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 am using Mathematica to perform trial divisions on large Mersenne numbers using specific prime numbers (e.g., primes of the form 8n+1 or 8n-1) and would like the program to abort once a factor is found. Here is an example of the code I have so far:

For[n = 1, n < 2^30, n++, 
 If[PrimeQ[8 n - 1], 
  If[Divisible[2^115770329- 1, 8 n - 1], Print["Factor at n = ", n]; 
   Abort[]]]]

This is fine for just testing one form of prime numbers, however, I would like to test both forms at the same time in parallel and have both abort if one finds a factor. I can open two notebooks and have two separate sets of code running at the same time, window / kernel 1 running for 8n-1 and window / kernel 2 running for 8n+1 however if kernel 1 finds a factor and aborts, kernel 2 will needlessly continue running until it also finds a factor or reaches "n max". I would like both to run at the same time and both to abort if one finds a factor and then print the "n" that caused both to abort.

Thank you for any help or advice!

share|improve this question
1  
Have you looked at ParallelTry? No need to have separate notebooks, etc. –  rasher Mar 2 at 22:53
    
@rasher Thanks! After Looking at ParallelTry in the Documentation Center it sounds like that is exactly what I am looking for. I will try to figure out how to use it in this situation. –  user3116891 Mar 3 at 19:39
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.