Background
I have a function I would like to execute inside a ParallelTable. One of the arguments of this function is another function. So it looks something like this:
myfunction[function_,param1_,someotherparameter_]:=(x=function[param1];
(*some evaluation using x and someotherparameter*))
(*I have several functions that I use as argument, but the one that causes the error is:*)
Needs["NumericalDifferentialEquationAnalysis`"]
gaussiangridandweights[np_] := (gaw = GaussianQuadratureWeights[np, 0, 10];
{gaw[[All, 1]], gaw[[All, 2]]})
Table[myfunction[gaussiangridandweights,n,otherparameter],{otherparameter,0,1}]
(*no error here*)
ParallelTable[myfunction[gaussiangridandweights,n,otherparameter],{otherparameter,0,1}]
(*error and different result*)
I have had no errors when using a Table, but now that I'm using ParallelTable, I get "Part specification is longer than depth of object." and I'm a bit baffled what causes this. The results are also different between using Table and using ParallelTable.
Drilled-down Problem
So I tried to nail down the problem and found that just evaluating the offending function gaussiangridandweights
inside a Paralleltable also gives the same error (but interestingly does not change the result)
Table[gaussiangridandweights[2], {i, 0, 2}]
(*no error*)
ParallelTable[gaussiangridandweights[2], {i, 0, 2}]
(*same error as before, but same result as with Table*)
Just doing
Table[GaussianQuadratureWeights[2, 0, 10], {i, 0, 2}]
ParallelTable[GaussianQuadratureWeights[2, 0, 10], {i, 0, 2}]
does not cause errors, so there must be something wrong with the {gaw[[All, 1]], gaw[[All, 2]]}
, but I have no idea what to do to fix this.
The exact error messages are
Part::partd : Part specification NumericalDifferentialEquationAnalysis`GaussianQuadratureWeights[2,0,10][[All,1]] is longer than depth of object.
Part::partd : Part specification NumericalDifferentialEquationAnalysis`GaussianQuadratureWeights[2,0,10][[All,2]] is longer than depth of object.
I searched for other people with the same error message "Part specification is longer than depth of object.", but their problems did not seem to apply to my case.
Questions
What causes the error message and why do I only get it in ParallelTable?
Any ideas why I get different results for myfunction in ParallelTable, even though gaussiangridandweights still seems to return the correct results (together with the error message)? (I do realise that this question might vanish as soon as question 1 is answered, but then again it might not. This part of the question is more out of theoretical interest)