I have an 8 core CPU and want to parallel evaluate the following nested Table
Table[Table[expr[i,j], {i,1,10}], {j,1,4}]
But there is a problem, the time cost of evaluating expr[i,j]
increases with the value of variable i
. If expr[1,j]
takes 5min, expr[2,j]
will take 10min and expr[10,j]
will take 3hours. Now you see, no matter where I will put Parallel
, in the outer Table
or in the inner Table
, the efficiency will not change.
The best way would be to first evaluate the most time consuming terms expr[10,1]
, expr[10,2]
, expr[10,3]
, expr[10,4]
and other expressions with less time cost just throw onto the remaining core one by one. I naively tried several parallel order, for example
ParallelTable[expr[i,j], {i,10,1,-1}, {j,1,4}]
but this will not use 4 cores out of my 8 cores. The question is what is the best way to parallelize this nested table evaluation?
f[parameter1,i,parameter2,j]
? $\endgroup$f[parameter1, #, parameter2, #2]& @@ # &
or perhaps better in that case:f[parameter1, #[[1]], parameter2, #[[2]] ]&
$\endgroup$