Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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[76]:= 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 *)
share|improve this question

1 Answer 1

up vote 7 down vote accepted

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.

share|improve this answer
2  
Yea I think that would work. As soon as you posted that I realized I could just do this: ParallelEvaluate[$RecursionLimit = 10^6] –  Jackson Walters 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
    
@sebhofer Oh dear. Thanks for pointing that. I wrote it without mma at hand, and did not catch the error. Apparently, the parallel kernels don't see the modified value. I'll try to fix it later or if not, I'll delete it. –  rm -rf Apr 2 '12 at 19:25
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.