# Setting $RecursionLimit across all parallel kernels I'm trying to optimize an elliptic curve factoring method by running it in parallel. There is a recursive step which required me to set the recursion limit higher than 256, however when I try and run it in parallel apparently the $RecursionLimit on each different kernel isn't changed.

Here's part of the output:

In:= ParallelECFactor[2418059292539721278076064468260051655561,1000,40]
(kernel 4) $RecursionLimit::reclim: Recursion depth of 256 exceeded. (kernel 3)$RecursionLimit::reclim: Recursion depth of 256 exceeded.
(kernel 2) $RecursionLimit::reclim: Recursion depth of 256 exceeded. (kernel 1)$RecursionLimit::reclim: Recursion depth of 256 exceeded.
(* and many more *)


As sebhofer pointed out, my previous solution didn't work — a fact that I missed because I wrote it without an mma to test. The users who voted for it also must've missed it, because on the surface it looks like a straightshot answer, but no. So, here's Jackson's solution that works — Use ParallelEvaluate as:
ParallelEvaluate[$RecursionLimit = 10^6]  Here's my previous solution that doesn't work, but I'm leaving it here so that others will not try something similar. Block[{$RecursionLimit = Infinity},
SetSharedVariable[$RecursionLimit] (* your parallel code *) ]  Using Block allows you to temporarily modify $RecursionLimit so that the global value is unaffected andSetSharedVariable declares that the variable's value is synchronized across all kernels.
• Yea I think that would work. As soon as you posted that I realized I could just do this: ParallelEvaluate[$RecursionLimit = 10^6] – Jackson Apr 1 '12 at 23:44 • R.M: Your code does not work for me (version 8.0.4)! ParallelEvaluate[$RecursionLimit = 10^6] does work though. – sebhofer Apr 2 '12 at 19:12
• I think it's worth noting that, at least on Windows or Mac, setting $RecursionLimit as high as$10^6$is liable to crash the kernel(s) due to stack overflow. On Linux it should be okay since there the stack can grow as large as necessary. – Oleksandr R. Apr 3 '12 at 12:47 • Yes, it's because setting a shared variable isn't the same as doing DistributeDefinitions. Shared variables are read from the master kernel whenever they're referenced in the subkernels using a callback. $RecursionLimit is treated specially by the kernel; its value can only be either an integer 20 or greater, or Infinity. This excludes setting its value to the expression that performs the callback. Using DistributeDefinitions would have worked, however. – Oleksandr R. Apr 3 '12 at 14:15