The documentation of ParallelTable indicates that if you want to parallelize the evaluation of a table of more than one dimension, such as

Table[f[i,j], {i, 5}, {j, 5}]

it is often not enough to simply use ParallelTable, as this will in general only parallelize over the outermost index.

Parallelization happens along the outermost (first) index:

ParallelTable[Labeled[Framed[f[i, j]], $KernelID], {i, 4}, {j, i}]

Using multiple iteration specifications is equivalent to nesting Table functions:

ParallelTable[i + j, {i, 3}, {j, i}]

ParallelTable[Table[i + j, {j, i}], {i, 3}]

In some use cases (such as a relatively long computation to be run for a limited number of instances, say this five by five array, with more cores than each dimension, say eight kernels) this can be a significant under-use of system resources.

This can be overcome by joining the two indices into one multi-index and parallelizing over that, in the form

  With[{i=index[[1]], j=index[[2]]},
{index, Flatten[Array[List, {5, 5}], 1] }]

but this feels like a bad hack.

Is there a cleaner way to make ParallelTable throw those bounds to the wind and simply hand out computation to any kernel that's free for it?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.