1
$\begingroup$

I'm not familiar at using parallel computing in Mathematica. I have a combination of an NIntegrate and Sum to evaluate a function which takes about 1 hour to run.

Is there any way that I can break it down using parallel computing in Mathematica such that each part will run in a different processor to make it faster?

Or, is there a way I can run 4 different Mathematica files that will run simultaneously on 4 different cores and then compile the results?

Thanks in advance!

$\endgroup$
4
  • $\begingroup$ Have you seen ParallelSum? $\endgroup$ Oct 2, 2016 at 10:44
  • $\begingroup$ yes I've tried it and it made my code run twice as fast :D however, is there a way that i can run 4 different mathematica files that will run simultaneously on 4 different cores and then compile the results? $\endgroup$
    – anonymous
    Oct 2, 2016 at 10:49
  • $\begingroup$ Depends on what Mathematica licence you have. Different licences allow different number of concurrent processes. $\endgroup$ Oct 2, 2016 at 10:50
  • $\begingroup$ ok. so assuming I have that licence, how can I do it? $\endgroup$
    – anonymous
    Oct 2, 2016 at 10:52

1 Answer 1

1
$\begingroup$

In general, the simplest way to evaluate multiple expressions in parallel is Parallelize.

Example:

Parallelize[{$KernelID, $KernelID}]
(* {4, 3} *)

However, I would be cautious with NIntegrate because it is already parallelized internally. Test this by watching your CPU usage while it is running. Parallelizing manually is likely to reduce performance in this case, not increase it. The one exception is when parallelizing across several computers (not several CPUs).

$\endgroup$
1
  • $\begingroup$ thanks! my code runs almost three times faster now :D $\endgroup$
    – anonymous
    Oct 2, 2016 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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