4
$\begingroup$

I have NIntegrate[] inside a ParallelDo[] loop. Outside the loop I set some options for the integration using SetOptions[].

To give an example:

SetOptions[NIntegrate, MaxRecursion -> 20];
ParallelDo[NIntegrate[Cos[20000 x]/Sqrt[x], {x, 0, 1}], {i, 1, 4}]

results in the error output

NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in x near {x} = {0.}. NIntegrate obtained 0.005799163549191785` and 0.014875547652988553` for the integral and error estimates.

Thus, not every kernel seems to know about the set options. How to distribute this setting over every kernel?

$\endgroup$

1 Answer 1

2
$\begingroup$

Use ParallelEvaluate to make sure that SetOptions is evaluated by each kernel:

ParallelEvaluate[SetOptions[NIntegrate, MaxRecursion -> 20]];
ParallelDo[NIntegrate[Cos[20000 x]/Sqrt[x], {x, 0, 1}], {i, 1, 4}]
(* no messages *)
$\endgroup$

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.