Benchmarking evaluating pi using dask

Working on a hand exercises of evaluating pi in a monte-carlo approach i.e. Estimating the value of Pi using Monte Carlo - GeeksforGeeks

Have some starter code here: faster_pi_evaluator · GitHub

Curious how dask users would approach this. My take was to apply the numpy function for each cpu. Curious if there is a faster approach.

Cheers,
Ray

Hi @raybellwaves,

The code I use when teaching or demoing Dask is the following:

import dask.array as da

sample = 10_000_000_000  # <- this is huge!
xxyy = da.random.uniform(-1, 1, size=(2, sample))
norm = da.linalg.norm(xxyy, axis=0)
summ = da.sum(norm <= 1)
insiders = summ.compute()
pi = 4 * insiders / sample
print("pi ~= {}".format(pi))

I took it from Parallelized vectorization with Dask - a Monte-Carlo example - DEV Community.

1 Like