Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am experimenting with Parallelize and ParallelTable

This is the code I am using:

K[a_, b_, r_] = a*Exp[-r/b]/r;

T = D[K[10^5, 10^9, s], s]/299792^2 /. s -> 7.6

R = Range[0, 7, 0.01];
\[Theta] = Range[0, 2*Pi, 0.05];

RcG[d_, t_] = Sqrt[7.6^2 + d^2 - 2*7.6*d*Cos[t]];
f[a_?NumberQ, b_?NumberQ] := 
  1/299792^2*NIntegrate[K[10^5, 10^9, x], {x, 7.6 - a, b}];

tab = Parallelize[
      d*(K[10^5, 10^9, RcG[d, t]] - K[10^5, 10^9, 7.6] - d*T) + 
     f[d, RcG[d, t]], {d, R}, {t, \[Theta]}]];
p1 = ListPlot3D[tab, InterpolationOrder -> 4]

I want make a 3d plot using the complicated function defined in the table. When computing, Mathem. gives this error a lot of times:

NIntegrate::inumr: The integrand K[100000,1000000000,x] has evaluated to non-numerical values for all sampling points in the region with boundaries {{7.3,7.30039}}.

It doesn't happen without the Parallelize, so this means that I am using it wrongly, but I don't get where. I also used ParallelTable, with the same result.

share|improve this question
up vote 0 down vote accepted

1) K is a built-in symbol. Don't use this symbol.

2) Use DistributedContexts with ParallelTable

  tab = ParallelTable[1/299792^2*d*(K[10^5, 10^9, RcG[d, t]] - K[10^5, 10^9, 7.6] - d*T) + f[d, RcG[d, t]], {d, R}, {t, \[Theta]}, DistributedContexts -> All];
share|improve this answer
Thank you, it works now. Also I didn't know that K is built-in, thanks for that too. – mattiav27 May 22 '14 at 13:04
@mattiav27 DistributeContexts is in fact not necessary here and when set to All it can potentially cause problems ... the problem was (1), not (2). – Szabolcs May 22 '14 at 16:36

Your Answer


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.