1

I want to achieve parallel computing by Python multiprocessing module, so I implement a simulated calculation to test whether I can use multiple CPU cores. I found a very strange thing that a single process can achieve 8 CPU usage of 100% on Windows Subsystem for Linux(WSL) on my desktop rather than only one CPU usage of 100% on Ubuntu on Lab's server. Like this:

enter image description here

And this is the contrast:

enter image description here

Furthermore, I found that using multiple processes does not reduce the time cost on WSL on my desktop, but which indeed largely reduce the time cost on Ubuntu on Lab's server. Like this:

enter image description here

(Here I run 6 processes and running a single process on Lab's server needs about 440s.)

And this is the contrast:

enter image description here

(Here I run 3 processes and running a single process on my desktop needs about 29s.)

Here is my Python source codes:

import numpy as np
import time
import os
import multiprocessing as mp

PROCESS_MAX = 1
LOOPS = 1
process_list = []

def simulated_calculation():
    x = np.random.rand(100, 100)
    y = np.random.rand(100, 100)
    z = np.outer(x, y)
    determinant = np.linalg.det(z)

def child_process(name):
    for i in range(LOOPS):
        print("The child process[%s] starts at %s and its PID is %s" % (str(name), time.ctime(), os.getpid()))
        simulated_calculation()
        print("The child process[%s] stops at %s and its PID is %s" %(str(name), time.ctime(), os.getpid()))

def main():
    print("All start at %s" % time.ctime())
    print("The parent process stars at %s and its PID is %s" % (time.ctime(), os.getpid()))
    start_wall_time = time.time()
    for i in range(PROCESS_MAX):
        p = mp.Process(target = child_process, args = (i + 1, ))
        process_list.append(p)
        p.daemon = True
        p.start()
    for i in process_list:
        i.join()
    stop_wall_time = time.time()
    print("All stop at %s" % time.ctime())
    print("The whole runtime is %ss" % str(stop_wall_time - start_wall_time))

if __name__ == "__main__":
    main()

I hope someone can help me. Thanks!

tk421
  • 5,775
  • 6
  • 23
  • 34
Victor Ma
  • 11
  • 3
  • Could you please add some paragraphs to your question for better readability? Also Remove these `enter image description here ` and enter an image discription, please. – Michael W. Czechowski Mar 13 '19 at 09:03
  • my **guess** is that `det` is built on top of BLAS and hence will be executed in parallel - which is at least true for `dot` : https://stackoverflow.com/a/16618268/351861 – specializt Mar 13 '19 at 09:12

1 Answers1

0

WSL1 has a virtual layer through which the Windows device drivers are being passed. WSL2 on the other hand, has more access due to a Linux kernel in place. However direct access to the hardware is inaccessible to WSL1 except USB. Hardware such as USB and GPU are currently not available to WSL2 but is being worked.

WSLUser
  • 601
  • 5
  • 10