In a nutshell, how can I get this number:
I'm having trouble because $KernelID isn't a function and the FullForm is this crazy thing:
Motivation:
After you call CloseKernels[]
, the next time you LaunchKernels[]
the new kernels don't start from one again:
In my parallel code I'd like to have access to the index of the kernel from 1 to $KernelCount, but I'm not sure how to efficiently get that:
offset = ToExpression@(StringCases[ToString[Kernels[][[1]]], NumberString][[1]])
(*Out[]= 17*)
LaunchKernels
, and referenced the kernels by their index (1-4) in that variable? I am sure there are practical, low-level reasons why the kernels continue to increment. $\endgroup$1 + Mod[$KernelID - 1, $KernelCount]
do what you want? I.e.,ParallelEvaluate[1 + Mod[$KernelID - 1, $KernelCount]]
always gives, e.g., on a 4-core machine,{1,2,3,4}
? $\endgroup$