For each kernel, a unique symbol can be generated with Unique[]
. However, since it's basically defined by the growing $ModuleNumber
, parallel kernels can only generate unique symbols for themselves, but they are the same across kernels.
MWE:
ParallelEvaluate[Unique[i]]
So how can I generate unique symbols across all kernels? Of course I can set the $ModuleNumber
for each kernel during the initialization, but that's way too brute force.
EDIT
My use of this unique symbol, for example, is
expr1=q.k l.k;
expr2=expr1/.{q.k->Module[{i},q[i]k[i]],l.k->Module[{i},l[i]k[i]]};
expr3=expr2/.k[i_]k[j_]:>delta[i,j];
result=expr3/.q_[i_]l_[j_]delta[i_,j_]:>q.l
i
must be unique and can only appear twice. $\endgroup$q[i$1]k[i$2]kroneckerdelta[i$1,i$2]
and I want to contract those indices such that the result is $q^ik^j\delta^{ij}=q^ik^i$. And the contraction is the last step so before that, I'd have intermediate results with indices I'd like to keep. $\endgroup$Indexed
be of any help then? $\endgroup$