2

A friend said he was able to get multithreading in python (with Anaconda's default interpreter, probably cpython?) to utilise all cores on Google Cloud vCPUs. However, ordinarily, multithreading in python is limited to a single core on local machines.

Is this possible? Does this have something to do with the way vCPUs share memory? I assumed that a vCPU looks like a logical core to the OS and the same GIL restrictions would apply.

Raskell
  • 158
  • 3
  • 9
  • CPython has a GIL that limits threads so that only 1 runs at a time, although I'm not sure about them being limited to only 1 core. Maybe your friend was talking about multiprocessing? – Iain Shelvington Dec 28 '19 at 17:42
  • The GIL doesn't mean that Python is completely single-threaded; if it did, why would Python support threading at all? It's the Global *Interpreter* Lock; only one *Python* instruction can be run at a time, but system calls and (some) underlying C methods can execute in parallel. In other words, the answer totally depends on your code. – Jonathon Reinhart Dec 28 '19 at 17:44
  • @JonathonReinhart I am looking at the code, and it's multithreading that's being used, furthermore, majority of the calls are numpy calls. However, running on a different server, the code basically executes on one CPU. My friend reported that on GCP, he got 80% CPU utilisation on all 16 cores on htop. So that was strange. – Raskell Dec 28 '19 at 18:02

2 Answers2

0

On Compute Engine, each virtual CPU (vCPU) is implemented as a single hardware hyper-thread on one of the available CPU Platforms. On Intel Xeon processors, Intel Hyper-Threading Technology allows multiple application threads to run on each physical processor core. You configure your Compute Engine virtual machine instances with one or more of these hyper-threads as vCPUs. The machine type specifies the number of vCPUs that your instance has.

You can identify the specific CPU platform for your instance using one of the following options:

  • See what CPU platforms are available in each of the available regions and zones.

  • Use the compute.instances.get a method to obtain the CPU platform property for one of your existing instances.

  • On Linux instances, run cat /proc/cpuinfo.

If you want to change the CPU platform for your instance, you can specify a minimum CPU platform.

Rishit Dagli
  • 1,000
  • 8
  • 20
0

Yes. But it depends on the VM type. I think you will want general purpose, high memory, compute intensive, or A2 types.

From GCP Docs(2021-08-17) "By default, Compute Engine enables simultaneous multithreading (SMT) on all virtual machine (VM) instances. With SMT enabled, a single physical CPU core can run 2 virtual CPUs (vCPUs), each as separate threads."

Then when you are creating a new VM you can up the threads per a core:

gcloud beta compute instances create VM_NAME \
    --zone=ZONE \
    --machine-type=MACHINE_TYPE \
    --threads-per-core=THREADS_PER_CORE

"THREADS_PER_CORE: the number of threads per physical core. Current processors support 2 threads per core for SMT, which is enabled by default. To disable SMT, set to 1."

Brian C.
  • 6,455
  • 3
  • 32
  • 42