Message Boards Message Boards

GROUPS:

Can you parallelize a numerically solved Integral?

Posted 2 months ago
663 Views
|
3 Replies
|
3 Total Likes
|

Hello, I have recently made use of a numerical integration method (Gaussian Quadrature) to solve very complex integrals for research. While the results have been good, and are much faster than any other numerical integration method I have used so far, it can still take hours to solve certain complicated integrals. However, I know my laptop is far faster when utilizing its multi-core processor. It is possible to modify this integration scheme to solve in parallel? The notebook uses a simple example of solving for an integral of cosine but this can be scaled up for more complicated examples.

3 Replies

It is possible that Sum will do symbolic processing under the hood. You might forestall that by using NSum or perhaps a different construct such as Total[Table[...]]. Only if these fail to deliver adequate speed would I look into coarse-grained parallelizing of the computation.

If functions are listable like Cos, using Range together with Total usually gets met the fastest results.

In[1]:= f[x_] := Cos[x]; (*function*)
n = 75;

I2[f_, a_, b_, n_] := (h = (b - a)/n; 
  Sum[f[a + (i - 1/2)*h]*h, {i, 1, n}])

I2R[f_, a_, b_, n_] := With[{h = (b - a)/n},
  Total[f[a + Range[0.5, n - 0.5, 1.] h] h]
  ]

{t1, v1} = RepeatedTiming@I2[f, -1.0, 1, n];
{t2, v2} = RepeatedTiming@I2R[f, -1.0, 1, n];
{t1/t2, v1 === v2}

Out[6]= {16.0959, True}
Posted 1 month ago

Hello,

This method ended up being a bit slower. Perhaps, Cos[x] was not the best choice of function for describing my situation. It more closely resembles Cos[x*t] where the end result of the integration will not be a singular number but, rather, a function of t. This integration method is being used to create another function that I can plot as a function of t.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract