I have something that looks a lot like the following:

              f=Abs[t+w Exp[I a]s];

$h$ is simply the correlation of two matrices $d_1$ and $d_2$ of the same size, one of which is displaced by $r_n$ rows and $c_n$ columns, weighted by the overlap area (yes, I know of ListCorrelate; that's beside the point). $rows$ and $cols$ are the number of rows and columns in the matrices, respectively. $s$ and $t$ are matrices of size $rows\times cols$, so obviously $f$ is also a matrix of that size. $g$ is an $11\times11$ matrix. Finally, $total$ is the sum of all the elements of $g$.

The whole thing should result in an $4\times4$ matrix with all the values of $total$ for different values of $x$ and $y$ (or, equivalently, for different values of $w$ and $a$).

When I run this, I get the following message:

ParallelTable::subpar: Parallel computations cannot be nested; proceeding with sequential evaluation.

(The message appears a few times per processor core before a "further output of ParallelTable::subpar will be suppressed" message appears.) However, the thing runs in under 4 seconds. If I change the first ParallelTable to Table, the error doesn't appear anymore but the thing takes about 10 seconds.

As far as I understand, the error comes up because I have a ParallelTable nested inside of another ParallelTable and what Mathematica does is turn one of them into Table. If this is the case, though, why does it take longer to run when I manually change one of them into Table?

Edit: I read here that the error results in the second ParallelTable being turned into Table. I suppose the stuff outside the second ParallelTable takes longer to evaluate than the stuff inside it (and thus it's better for the stuff outside to be parallelised than for the stuff inside to be parallelised); that would explain the computation-time difference. However, I still have another question:

Why does it take really long (it's been going on for half an hour; who knows how long it's got left) when I do this $11\times11$ times instead of $4\times4$ times (i.e. when I let $x$ and $y$ run up to 10)? If $4\times4=16$ takes under 4 seconds, I'd imagine $11\times11=121$ to take $4\times121/16=30$ seconds at most.

Thanks for any insight into this.

  • 2
    $\begingroup$ The main issue is probably not the stuff outside the inner ParallelTable, but rather the overhead of starting a parallel computation… Regarding your other issue: I cannot reproduce the timing behavior you describe. Can you provide example data for gradhLr?? $\endgroup$
    – Lukas Lang
    May 10, 2018 at 14:32
  • $\begingroup$ @BrettChampion They are exact numbers. $\endgroup$
    – Rain
    May 10, 2018 at 14:32
  • $\begingroup$ @Mathe172 I'd already started parellel computation when I made these tests. As for gradhLr, that's a typo (f was initially called that); I'll edit my post to fix it. $\endgroup$
    – Rain
    May 10, 2018 at 14:33
  • 1
    $\begingroup$ @Rain There will still be some overhead - although a big part of that is indeed only done once for the first parallel computation $\endgroup$
    – Lukas Lang
    May 10, 2018 at 14:35
  • 1
    $\begingroup$ Can you provide s and t? $\endgroup$ May 10, 2018 at 14:44


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.