UCL-RITS / pi_examples

A lot of ways to run the same way of calculating pi. Some of them are dumb.
Creative Commons Zero v1.0 Universal
29 stars 8 forks source link

Dask example #14

Closed adrianjhpc closed 2 years ago

adrianjhpc commented 2 years ago

I humbly constribute an example using Dask as the parallelisation method from python3

giordano commented 2 years ago
[cceamgi@login13 python3_dask_pi_dir]$ ./run.sh 
Calculating PI using:
  10000000 slices
  1 workers
Dask setup time: 0.5512979030609131 seconds
Obtained value of PI: 3.141592653589731
Time taken: 3.319666862487793 seconds
[cceamgi@login13 python3_dask_pi_dir]$ ./run.sh 10000000 10
Calculating PI using:
  10000000 slices
  10 workers
Dask setup time: 0.4764735698699951 seconds
Obtained value of PI: 3.1415926535897905
Time taken: 3.394249200820923 seconds

Am I using it right? This is on Myriad

giordano commented 2 years ago

Looking at htop while I run the example I'm not even sure this is using multiple processes at all, otherwise the performance scaling would be very underwhelming. But probably I'm doing something wrong.

adrianjhpc commented 2 years ago

My bad, I've left thread based parallelism enabled, but that's blocked by the GIL. I'll update and it should work

adrianjhpc commented 2 years ago

Can you try again now

giordano commented 2 years ago
[cceamgi@login13 python3_dask_pi_dir]$ ./run.sh 20000000 1
Calculating PI using:
  20000000 slices
  1 workers
Dask setup time: 1.565711259841919 seconds
Obtained value of PI: 3.141592653589961
Time taken: 6.514402389526367 seconds
[cceamgi@login13 python3_dask_pi_dir]$ ./run.sh 20000000 10
Calculating PI using:
  20000000 slices
  10 workers
Dask setup time: 1.8686230182647705 seconds
Obtained value of PI: 3.1415926535897567
Time taken: 0.8722851276397705 seconds
[cceamgi@login13 python3_dask_pi_dir]$ ./run.sh 20000000 18
Calculating PI using:
  20000000 slices
  18 workers
Dask setup time: 2.286681890487671 seconds
Obtained value of PI: 3.1415926535897887
Time taken: 0.6200428009033203 seconds

Looks better now, thanks!