2
$\begingroup$

I want to run some function with different parameters, parallel on 4 cores (i5). When I run it without using Parallelize, processor has ~25% utilization. It's a little time consuming (a couple of minutes), so I tried run it 4x with different parameters on each core.

I tried: Parallelize[{f[a1,b1,c1],f[a2,b2,c2],f[a3,b3,c3],f[a4,b4,c4]}] (also with different methods like: "FinestGrained"/"CoarsestGrained"/"EvaluationsPerKernel" -> 1) and still, total utilization of cpu is 30% top).

  1. Each variant is processed within a few minutes, at least 4 minutes.
  2. In Parallel Kernel Status window all 4 kernels have status busy, after the start of the calculation. I used Parallelize earlier and it worked just fine (~100% utilization).

So, what is the reason?

My configuration: Mathematica 9.0.0/Win8 x64/i5 2500k, 4GB RAM

$\endgroup$
14
  • 1
    $\begingroup$ There could be several reasons. Can you check the CPU utilization of each subkernel process separately with a task monitor, as well as that of the main process, and tell us what you found? $\endgroup$
    – Szabolcs
    Feb 16, 2013 at 14:54
  • 1
    $\begingroup$ A few things will help: knowing your OS and version of Mathematica. Full specs on the machine (total cores, Mma V9 has native support for 6 cores in parallel). While it sounds like you've got all of this running on a single machine, let us know if you want to do this across a network. Check that you don't have other processes running to compete for usage of the 4 cores. $\endgroup$
    – Jagra
    Feb 16, 2013 at 15:12
  • 1
    $\begingroup$ Might help a lot if we knew how your function f was defined. $\endgroup$
    – m_goldberg
    Feb 16, 2013 at 15:21
  • 1
    $\begingroup$ It sounds like some function is unexpectedly being evaluated in the main kernel. The test Szabolcs mentioned will show you if this is the case; you can also put "Print[$KernelID]" in various places in your code to verify that functions are being executed in parallel. Use of SetSharedFunction (or possibly SetSharedVariable) will cause functions (or variables, respectively) to be evaluated in the main kernel. If your function uses a symbol which is not in the current context (e.g. from a package), and you forget to invoke DistributeDefinitions, $\endgroup$ Feb 16, 2013 at 15:44
  • 1
    $\begingroup$ If providing f is not feasible, you could reword the problem to ask for a list of the most common causes of utilization failure, in the hope of eliciting more answers. $\endgroup$ Feb 16, 2013 at 15:53

1 Answer 1

8
$\begingroup$

This is more of a big comment not answer to your quesetion!

Here is a function I want to Parallelize. I have four cores in my machine so I Launch four kernels and distribute the definition of my functions to the kernels.

fun[a_?NumericQ, b_?NumericQ, c_?NumericQ] := 
Plot3D[Evaluate[Im[a ArcSin[(b x + I y)^c]]], {x, -2, 2}, {y, -2, 2},
Mesh -> None,PlotStyle ->Directive[Yellow, Specularity[White, 20], Opacity[0.8]], 
ExclusionsStyle -> {None, Red}, PlotPoints -> 120,MaxRecursion -> 4];
LaunchKernels[4];
DistributeDefinitions[fun]

{fun}

Now do what you want to do

Parallelize[{fun[1, 1, 3], fun[1, 2, 4], fun[2, 1, 3], fun[3, 3, 3]}, 
Method -> "EvaluationsPerKernel" -> 1] // AbsoluteTiming

enter image description here

And the result is as expected! enter image description here

My PC Config:

Windows 7 64-bit (SP1) /Core i7 620M Quad Core /4 GB RAM

Tested:

Mathematica 8.0.4 /Mathematica 9.0.1

$\endgroup$
2
  • 1
    $\begingroup$ +1 because I think what you've posted will really help point us in a better direction to solve the problem. Could you post some of the same info I asked for in my comment on the original question. It might help establish the differences between why yours works and the OPs doesn't $\endgroup$
    – Jagra
    Feb 16, 2013 at 15:21
  • $\begingroup$ Thanks. Utilization now is about 30-68%, but it is not stable. Similarly with your code 60-70% (executed in 3.3s so maybe this is the reason). $\endgroup$
    – Bartek
    Feb 16, 2013 at 15:50

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.