I am running Mathematica on a computer with multi CPU and every CPU has multicore. I am wondering if there exist a method to send different cell evaluation to different core? So if I already have a cell being evaluating for a long time, I can still add other cells into evaluation at the same time, while won't have to stop the current evaluation or wait until the current evaluation to be done.
Answer
You can use the Evaluator
option of Cell
for this. You should define several kernels through the Kernel Configuration Options...
dialog, then you can use a name of configured kernel as value for the Evaluator
option.
For example, create new local kernel with name "My"
. Then generate an Input Cell by the following code:
CellPrint@Cell[BoxData[MakeBoxes[Do[Print[n]; Pause[1], {n, 20}]]], "Input", Evaluator -> "My"]
In another Cell
just type Do[Print[n]; Pause[1], {n, 20}]
and evaluate both Cells
with Do
expressions simultaneously by selecting both of them and then pressing Shift+Enter. You will see that results of the evaluations are printed in parallel.
Note that the process of assigning of individual kernels to individual Cell
s can be automatized, you aren't have to do this by hand. One way is to make a Palette with Button
s which will attach individual kernels to the selected Cell
s in a Notebook.
Comments
Post a Comment