-1

I am new to cloud computing. I made a virtual machine in google cloud computing, machine type:

e2-highcpu-2 (2 vCPU's, 2 GB geheugen)

I run a script with running the command

python3 simulation1.py

When I look at the output control screen, I note that only 50% of the CPU power is used. So I just use one of my 2 CPU's. Is there a way to make full use of the computing power ?

Rens
  • 177
  • 9
  • Without more details, we are not able to know if your code takes advantage of both cores. Please add more details to your question. – Puteri Sep 24 '20 at 19:55

1 Answers1

1

Looks like your question can be resumed to "is Python capable of running on multiple cores?"

And you can find the answer to that question perfectly explained in this post.

Basically:

Python threads cannot take advantage of many cores. This is due to an internal implementation detail called the GIL (global interpreter lock) in the C implementation of python.

You can either use something like multiprocessing, celery or mpi4py to split the parallel work into another process;

Or you can use something like Jython or IronPython to use an alternative interpreter that doesn't have a GIL.

If you are already using any of the tools mentioned above. you could also add more details about your code.

Lalo P
  • 326
  • 1
  • 10