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

Because NIntegrate[] does not support parallel computation out of the box, I'm doing a simplified version by breaking the integration limit into pieces and using ParallelTable[]. The following code is just a minimum working example in which I used Sinc[] as the integrated function.

iser[x_] := NIntegrate[Sinc[t + x], {t, 0, 100}];

ipar[x_] := Total[ParallelTable[
             With[{xx = x}, NIntegrate[Sinc[t + xx], {t, ii*25, ii*25 + 25}]
             ], {ii, 0, 3}]
            ];

where iser[] is the usual serialize version, and ipar[] is the parallel version. Then I do DistributeDefinitions[ipar]. Passing a value to iser[] and ipar[] and both give the correct answer:

In[28]:= ipar[3]

Out[28]= -0.270322

But, when I try to run Plot[ipar[x], {x, 0, 10}] // Timing I get error messages that says

 NIntegrate::inumr: The integrand Sinc[t+x] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,25}}.

 NIntegrate::inumr: The integrand Sinc[t+x] has evaluated to non-numerical values for all sampling points in the region with boundaries {{50,75}}.

 NIntegrate::inumr: The integrand Sinc[t+x] has evaluated to non-numerical values for all sampling points in the region with boundaries {{75,100}}.

 NIntegrate::inumr: The integrand Sinc[t+x] has evaluated to non-numerical values for all sampling points in the region with boundaries {{25,50}}.

 NIntegrate::nlim: t = 25. ii is not a valid limit of integration.


 General::stop: Further output of NIntegrate::nlim will be suppressed during this calculation.

 $Aborted

I know I can just generate a table of values and use ListPlot[] instead, but it's not easy to do adaptive sampling as Plot[] does. How can this be fixed?

share|improve this question
ipar[x_?NumberQ] := ... – wxffles Nov 9 '12 at 2:23
@wxffles Thanks. That solves it. Bit strange that ipar[3] returns the correct value without the query ?NumberQ – david sedai Nov 9 '12 at 2:56
2  
Please read this for a full explanation: support.wolfram.com/kb/3820 – Searke Nov 9 '12 at 5:14
2  
@davidsedai please rename your post to Table not working with Plot as the problem has nothing to do with Parallel in practice. And change the tag? – chris Nov 9 '12 at 7:13
@Searke Thanks for the link – david sedai Nov 9 '12 at 7:22
show 2 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

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.