Why is it so slow?

Dear, i am a beginner with dask and trying to efficiently parallelise some piece of codes…

Runnig this little code takes 18s. I’ve read many topics but cannot find out why is it so slow…

Have any idea (i offer a beer!). Best

def mafun(y,x,tab):
return [tab2,tab3]

def costly_simulation(y,x,tab):
result=
for iy in np.arange(np.size(y)):
result.append(mafun(y[iy],x[iy],tab[iy,:]))
return result

lazy_results =
client = Client()
st=time.time()
reflectances=np.random.normal(0,1,[2000,2000,3,3])
slices=slice_image(2000,2000,2000) # par ligne
for islice in slices:
lazy_result = dask.delayed(costly_simulation)(islice[0],islice[1],reflectances[islice[0],islice[1],:,:])
lazy_results.append(lazy_result)

results = dask.compute(*lazy_results,scheduler=‘processes’)
st2=time.time()
results2=np.reshape(np.asarray(results)[:,:,1,:,:],[2000,2000,3,3])
client.close()
print(st2-st)
gc.collect()

Hi @MichaelSaviniaul,

Could you just edit your post and put the code into a code block?

At first glance, I wonder what is the slice_image function doing?