Question details:
I used the GaussianQuadratureWeights to calculate the Integration of a simple expression. But when I used the ParallelTable, it turned out to be errors about the GaussianQuadratureWeights and Transpose.
My Mathematica kernels are 2.
Here are the original code for this example.
In[1]:= << NumericalDifferentialEquationAnalysis`
In[2]:= GLQ1D[func_, {a_, b_}, {Xdegree_}] :=
Block[{Xnodes, x, Xweights, i},
x = GaussianQuadratureWeights[Xdegree, a, b];
Xnodes = Transpose[x][[1]]; Xweights = Transpose[x][[2]];
Total[Flatten[
Table[Xweights[[i]]*func[ Xnodes[[i]]], {i, 1, Xdegree}]]]];
In[3]:= f[x_] := x^2;
In[4]:= a = 1.;
In[5]:= b = 3.;
In[6]:= TrueValue = Integrate[x^2, {x, a, b}]
Out[6]= 8.66667
In[7]:= x1 = Table[i, {i, 1, 3 - 0.1, 0.1}];
In[8]:= x2 = Table[i, {i, 1 + 0.1, 3, 0.1}];
In[9]:= value1 =
Table[Total[
Flatten[Table[
GLQ1D[f, {x1[[i]], x2[[i]]}, {k}], {i, 1, Length[x1]}]]], {k, 1,
5}] // AbsoluteTiming
Out[9]= {0.009066, {8.665, 8.66667, 8.66667, 8.66667, 8.66667}}
In[10]:= ListLinePlot[Abs[value1[[2]] - TrueValue]]
It was OK with Table for GaussianQuadratureWeights, but when it came for ParallelTable, it had errors like this:
In[11]:= value2 =
Table[Total[
Flatten[ParallelTable[
GLQ1D[f, {x1[[i]], x2[[i]]}, {k}], {i, 1, Length[x1]}]]], {k, 1,
5}] // AbsoluteTiming
(kernel 2) Part::partw : Part 2 of Transpose[NumericalDifferentialEquationAnalysis`GaussianQuadratureWeights[1,1.,1.1]] does not exist.
Out[11]= {4.62609, {42., 989.6, 2105.52, 3945.13, 6745.78}}
In[12]:= value3 =
ParallelTable[
Total[Flatten[
Table[GLQ1D[f, {x1[[i]], x2[[i]]}, {k}], {i, 1,
Length[x1]}]]], {k, 1, 5}] // AbsoluteTiming
(kernel 2) General::stop : Further output of Part::partw will be suppressed during this calculation.
(kernel 1) General::stop : Further output of Part::partw will be suppressed during this calculation.
(kernel 2) Part::partw : Part 2 of Transpose[NumericalDifferentialEquationAnalysis`GaussianQuadratureWeights[4,1.,1.1]] does not exist.
(kernel 1) General::stop : Further output of Part::partw will be suppressed during this calculation.
Out[12]= {0.343389, {{{40.}, {2.}}, {{323.091, 327.709}, {169.4,
169.4}}, {{520.948, 527.919, 534.891}, {172.919, 175.919,
172.919}}, {{796.147, 804.485, 815.365, 823.703}, {173.923,
178.792, 178.792, 173.923}}, {{1148.52, 1157.71, 1171.18, 1184.64
,1193.83}, {173.903, 179.946, 182.202, 179.946, 173.903}}}}