2
$\begingroup$

Suppose I have the following functions:

f1:=(a=RandomInteger[{1,24}]; b=RandomInteger[{1,24}]; Return[a+b]) f2:=If[f1==2,Print["snake eyes"]; Return[true], Print["nada"]; Return[false]] 
  1. How can I parallelize these functions so that each kernel continuously executes f1 until any one kernel obtains "snake eyes" (at which point the process should terminate)?
  2. Relating to the first question, once parallelized is there a more efficient way of writing or executing this resulting code?
$\endgroup$
1
  • $\begingroup$ For a discussion of interkernel communication, the primitives, and the issues that arise, I think this question is quite informative (the question AND the answer, both). $\endgroup$ Commented Sep 22, 2014 at 0:17

1 Answer 1

1
$\begingroup$

All function you need it's DistributeDefinitions and ParallelTry

f1 := RandomInteger[{1, 24}] + RandomInteger[{1, 24}]; func[x_] := While[True, If[f1 === 2, Print["snake eyes"]; Return[True] ,(*else*) Print["nada"] ] ]; ParallelTry[func, Range[$KernelCount]] 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.