Hi S G. I appreciate your problem, but unfortunately I don't have that much time to spare and your code is simply quite difficult to read. The only way I could really assess the problem is by taking it apart completely and rewriting it, which is a lot of work.
However, I noticed one more thing in your code that almost certainly problematic: in the definition of XXXX
there is an assignment to the function Et[m]
. This function is used to define other functions elsewhere and I'm fairly certain that these assignments will get communicated back and forth between kernels. Assignments like these shouldn't be done inside of code that gets evaluated in a parallel fashion. Your code is has a slew of other side effects (meaning that non-local variables and functions are defined during the parallel evaluation) and all of them could be the culprit of poor performance.
I recommend you restructure your code to one function of phi
and theta
. To be on the safe side, this function should not depend on any other global variables, so every internal function should be localized with Module
. So you'd end up with code that looks roughly like this:
myFunction[phi_, theta_] := Module[{
var1, var2, ...,
fun1, fun2, ....
},
...
];
In the definition of myFunction
there shouldn't be any blue symbols left at the end; it should be entirely self-contained. After that, you can just call it with:
ParallelTable[{myFunction[phi, theta], phi, theta}, {phi, 0, Pi/4, Pi/12}, {theta, 0, ArcCot[Cos[phi]], ArcCot[Cos[phi]]/3}]