In the note RootSearch problem when called from within ParallelDo I described the problem with Ted Ersek's RootSearch package and came to the conclusion that it is caused by the fact that the derivative with respect to the parameter from the ParametricFunction, which is obtained as a solution to the differential equation using the ParametricNDSolve function, is incorrectly calculated inside the ParallelDo loop.
The following example illustrates the problem. First, we solve an ordinary differential equation and formulate the result of the solution in the form of a function ϕ1p, which depends on the z coordinate and the parameters β and Λ. We also define the ϕ1p1b function as the derivative of the ϕ1p function with respect to the β parameter. This function and its numerical value at β=0.4 will be compared with the ϕ1p derivative with respect to the β parameter, which we will calculate inside the Do and ParallelDo loops. This derivative within the cycles is denoted as LHS1b.
Inside the Do loop, the ϕ1p1b and LHS1b functions and their numerical values are the same. However, inside the ParallelDo loop, the resulting expression for the LHS1b function is gigantic, so the Short form is used to print it. Mathematica cannot calculate the numerical value of LHS1b at all.
It seems to me that the described problem is a bug in the Mathematica system, although I admit that I am doing something wrong. If so, where am I wrong?
Same error occurs when computing derivative over coordinate z.
Attachments: