1
$\begingroup$

I've encountered a problem I can't make sense of:

I'm combining the ListPlot of a HPLC chromatogram (called bgcorrected in this case) with a Table of Plots of Gaussian fits (the function fit with peaks being the gaussians expected value) . With Manipulate I added a SetterBar to change the scaling of the Plots with ScalingFunctions. This works perfectly fine with Table, however I get the error message

Plot::sclfn : The scaling function FE`scaling$$128 cannot be used to scale coordinates.

when using ParallelTable for performance reasons.

The working code with Table:

Clear[scaling];
Manipulate[
 Show[{ListPlot[bgcorrected, ScalingFunctions -> scaling, 
    PlotRange -> All, PlotStyle -> {Red, Thick}], 
   Table[
    Plot[fit[[m]][x], {x, 
      Normal[peaks][[m]][[1]] - 5*\[Sigma] /. 
       fit[[m]]["BestFitParameters"], 
      Normal[peaks][[m]][[1]] + 5*\[Sigma] /. 
       fit[[m]]["BestFitParameters"]}, 
     ScalingFunctions -> scaling], {m, Dimensions[Normal[peaks]][[1]]}
    ]}], {{scaling, {Sqrt, InverseFunction[Sqrt]}, 
   "plot scaling"}, {None -> 
    "linear", {Sqrt, InverseFunction[Sqrt]} -> "sqrt", 
   "Log10" -> "log"}, ControlType -> SetterBar, Appearance -> "Row"}]

Interestingly, ParallelTable works fine when I input the value for ScalingFunctions by hand, e.g. "Log10" or {Sqrt,InverseFunction[Sqrt]}.

Does anyone have an idea why Table is working in this case, but ParallelTable is not?

$\endgroup$
1
$\begingroup$

The problem is that the subkernels do not know about the definition of scaling, since it is only defined in the main kernel. You can set scaling to be a shared variable, meaning that once the value is changed in the main kernel, it will be automatically synchronized across all subkernels. Since scaling is in your case a local variable, this has to be done inside Manipulate, for example via the Initialization option:

Manipulate[
    ParallelTable[
        Plot[Exp[-(x - m)^2], {x, -1, 8}, ScalingFunctions -> scaling],
    {m, 1, 4}],
    {{scaling, {Sqrt, InverseFunction[Sqrt]}, "plot scaling"}, 
    {None ->  "linear", {Sqrt, InverseFunction[Sqrt]} -> "sqrt", "Log10" -> "log"}, 
    ControlType -> SetterBar, Appearance -> "Row"}, 
    Initialization :> SetSharedVariable[scaling]
]
$\endgroup$
1
  • $\begingroup$ Thank you very much, sir. This works like a charm and is educational for future uses of parallel computation. $\endgroup$ – rowsi Jan 22 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.