# Using Parallelize on a For loop

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?

-
You can't auto-parallelize a For loop because it uses mutable state (the iteration variable). As a beginner it's best never to use For anyway---if you are using it, you are very likely doing things in a too complicated or an inefficient manner. Use either Do (for which you have ParallelDo but you still need to avoid changing global variables in the loop) or in your case, use Table, which has the counterpart ParallelTable. –  Szabolcs May 14 at 22:04
Nested For loops are about the worst way to go in Mathematica, you are much better off with a single Do or Table statement. I would try that before you worried about parallelizing it (which often has unexpected consequences). –  Guillochon May 14 at 22:14
You are asking for nearly 20 x 10^9 iterations. With the If and guessing at the time for f, 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. With f, 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