Say I have a For
loops the following,
Monitor[For[y = 6, y < 380, y++
For[v = 5, v < y, v++,
For[z = 4, z < v, z++,
For[x = 3, x < z, x++,
If[x + z + v - 3 >= 2*y - 2 &&
Exponent[r[x, z, v, y], A] < (x + z + v - 2)/2,
Print[{x, z, v, y}, f[x, z, v, y]]]]]]], y]
It'll take lots of time. Is it possible to use the command Parallelize
? Or how can I reduce the time?
For
loop because it uses mutable state (the iteration variable). As a beginner it's best never to useFor
anyway---if you are using it, you are very likely doing things in a too complicated or an inefficient manner. Use eitherDo
(for which you haveParallelDo
but you still need to avoid changing global variables in the loop) or in your case, useTable
, which has the counterpartParallelTable
. – Szabolcs May 14 at 22:04For
loops are about the worst way to go in Mathematica, you are much better off with a singleDo
orTable
statement. I would try that before you worried about parallelizing it (which often has unexpected consequences). – Guillochon May 14 at 22:14If
and guessing at the time forf
, that's about 10^-7 sec. or more. per iteration on my machine, or for the whole loop something like from a 1/2 hour or more. Withf
, it will be longer; if the time per iteration is 10^-5 sec., then the whole loop will take more than 2 days! – Michael E2 May 14 at 23:22