The documentation shows the following example to "Remove a distributed definition..."
Oh, course this doesn't work without redefining the function prior to re distributing the definition. The following does work:
ClearAll[f];
f[x_] := Labeled[Framed[x^2], $KernelID]
DistributeDefinitions[f];
ParallelMap[f, {1, 2, 3, 4}]
and will give the same output as the above screen clip. OK, but...
This seems a very cumbersome way to do this and just doesn't seem right at all.
It would seem clearer to me if one could call back the distribution of a function definition, something like UnDistributeDefinitions[]
, to withdrawal the function from remote kernels rather than needing to clear the function in the main kernel, redefine it, then redistribute it.
I came across this issue as I looked to move a DistributeDefinitions[] into a function that will run a bunch of other functions from a standalone cell in a notebook. To test whether it would work, I need to clear all the functions I wanted to distribute or restart the kernel.
Just seems a messy way to do things. So, does a way exist to clear definitions in remote kernels without clearing them in the main kernel?
g=f; ParallelDo[Clear[f],{<numberofkernels>}]; f=g;
$\endgroup$a = 1; ParallelEvaluate[a]
andOwnValues[a]
and nowParallelEvaluate[OwnValues[a]]
? Your example from the doc does not only show the undistribution, it clearsf
completely. If this would not be done, then the main-kernel would be called when you evalf
on the subkernels. Can you clear again for me, what your question is? $\endgroup$ParallelEvaluate[Clear[f]]
is not an option? $\endgroup$