# How to redistribute definitions to parallel kernels

I am trying to redistribute a definition after removing the definition on parallel kernels.
Sample code on version 10.4.0.0:

x=3;
DistributeDefinitions[x]  (* {x} *)
ParallelEvaluate[Print[x];];  (*  displayed as "3", "3", ... *)
ParallelEvaluate[Remove[x];];
DistributeDefinitions[x]  (* {} *)
ParallelEvaluate[Print[x];];  (* displayed as "x", "x", ... *)


The first behavior of parallel Print[x] is as expected, but the second is not. For unchanged x on the master kernel, is there a way to make DistribteDefinitions[x] work again ?

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Aug 1 '16 at 18:54

You can run

x = 3;
DistributeDefinitions[x];
ParallelEvaluate[Print[x]];
ParallelEvaluate[Remove[x];];
x++;
DistributeDefinitions[x];
x--;
ParallelEvaluate[Print[x]];


If that works for you.

I found another answer in Shared variable can not be distributed again after UnsetShared.
Using ParallelDeveloperClearDistributedDefinitions[],

SetOptions[{ParallelEvaluate}, DistributedContexts -> None]; (* for the avoidance of confusion in distributing definitions *)
x=3;
DistributeDefinitions[x]
(* {x} *)
ParallelEvaluate[Print[x];];
ParallelEvaluate[Remove[x];];
ParallelDeveloperClearDistributedDefinitions[];
DistributeDefinitions[x]
(* {x} *)
ParallelEvaluate[Print[x];];


I was able to observe the redistribution of x to parallel kernels.