8
$\begingroup$

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.

$\endgroup$

1 Answer 1

8
$\begingroup$

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 Cells can be automatized, you aren't have to do this by hand. One way is to make a Palette with Buttons which will attach individual kernels to the selected Cells in a Notebook.

$\endgroup$
9
  • 1
    $\begingroup$ Hi, thank you for your reply. But I'm afraid that Evaluator doesn't related to my problem. I know the Kernel Configuration. But this option configure remote kernels. What I am talking about is multicore in one kernel. $\endgroup$
    – matheorem
    Aug 27, 2013 at 6:26
  • $\begingroup$ @matheorem Multithreading is implemented in Mathematica through launching several kernels. It is not possible to force one kernel to perform several computations in parallel. And the Kernel Configuration Options... dialog allows to set up several local kernels, not only remote kernels. $\endgroup$ Aug 27, 2013 at 7:28
  • $\begingroup$ What does several local kernel mean? I only have one local kernel $\endgroup$
    – matheorem
    Aug 27, 2013 at 7:29
  • $\begingroup$ Local kernels are available on your local machine to perform computations. You can assign different kernels to different Noteboks and/or different Cells in one Notebook. You can also configure when these kernels should be launched: when Mathematica starts or only when you need them. See options in the Kernel Configuration Options... dialog (press the Add button). $\endgroup$ Aug 27, 2013 at 7:33
  • $\begingroup$ I tried. But add a local kernel with a different name, doesn't work at all. UseExpressionCell[expr, "Input", Evaluator -> "Local"], two cell with different local evaluator still run in sequence. $\endgroup$
    – matheorem
    Aug 27, 2013 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.