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 was doing the first exercise in the paper Lattice QCD for Novices. This is the expected result:

enter image description here

With the default "GlobalAdaptive" method for NIntegrate it threw errors saying that the error had increased more than 2000 times, so I switched to "LocalAdaptive". The result had some jitters, but was recognizable.

enter image description here

I decided to go back to "GlobalAdaptive" despite the warnings and slower time, and it actually looks really good despite the warnings.

enter image description here

However, the documentation says global adaptive is generally faster for multidimensional integrals. I'm looking for insight for why it is not true in this case, and in general, any settings that would give a better and faster result. I'm just getting into the options for the Monte Carlo methods. Here's the code:

stepSize = 1/2; stepCount = 8; potential[x_] := x^2/2; mass = 1;

action[x_List] := 
 Sum[mass/(2 stepSize) (x[[j + 1]] - x[[j]])^2 + 
   stepSize potential[x[[j]]], {j, stepCount}]

  NIntegrate @@ 
   Join[{E^-action[Join[{b}, Table[x[i], {i, stepCount - 1}], {b}]]}, 
    Table[{x[i], -5, 5}, {i, stepCount - 1}], {Method -> 
      "LocalAdaptive"}], {b, 0, 2, .2}]

  Quiet[NIntegrate @@ 
    Join[{E^-action[Join[{b}, Table[x[i], {i, stepCount - 1}], {b}]]},
      Table[{x[i], -5, 5}, {i, stepCount - 1}]]], {b, 0, 2, .2}]
share|improve this question
Just wanted to note that NIntegrate typically manages to use all cores of the CPU, so ParallelTable doesn't usually help with speeding things up (in fact it slows them down). I don't know what NIntegrate does in parallel internally, this is just an observation. – Szabolcs Feb 5 '14 at 20:26
@Szabolcs The problem asks for 11 separate NIntegrate calls (each with a separate start and end boundary for the propagator), so I'm just using ParallelTable to get a quick boost on those. – Michael Hale Feb 5 '14 at 22:13
@Szabolcs I mean, I understand your point, but in this case I go from 31 seconds to 12 seconds with ParallelTable for the local adaptive one. If anyone has insight into why this is a case where parallel does help NIntegrate I'm interested in that too. – Michael Hale Feb 5 '14 at 22:57
In that case it's clearly worth doing the parallelization! Maybe it's the global adaptive method that has some built-in parallelization. – Szabolcs Feb 5 '14 at 23:22
This section of NIntegrate's advanced documentation is a good start "GlobalAdaptive versus LocalAdaptive". It has comparison tables of computations of different types of integrals. – Anton Antonov Jun 6 at 14:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.