34
$\begingroup$

When one evaluation is running, if I want do another evaluation, Mathematica will put the second one in the queue and run it after the first evaluation finish. However, the first evaluation may take very long time and the second one may just a easy calculation. It is possible that running the second evaluation without giving up or waiting the first evaluation?

BTW, I am using Mathematica 9 in Windows 8(64 bit), but I am also happy to use Ubuntu.

Any suggestions are welcome.

$\endgroup$
  • 1
    $\begingroup$ May be you can try reference.wolfram.com/mathematica/ref/ParallelEvaluate.html $\endgroup$ – Nasser May 24 '14 at 11:52
  • 1
    $\begingroup$ You should find the answer to your question here $\endgroup$ – Sektor May 24 '14 at 12:20
  • 2
    $\begingroup$ Possibly also reference.wolfram.com/mathematica/tutorial/Dialogs.html $\endgroup$ – mfvonh May 24 '14 at 14:38
  • 6
    $\begingroup$ You can either go to Evaluation -> Kernel Configuration Options and configure a second kernel, open a new notebook, set the second kernel as the new notebooks's kernel and work there; or interrupt using Alt-, to enter a dialog as mfvonh said above. The first option won't let you use the definitions you already made in the session as it starts a completely new kernel. The second option is not 100% reliable. $\endgroup$ – Szabolcs May 24 '14 at 14:44
  • 1
    $\begingroup$ This issue usually arises, precisely as the OP notes, when one is evaluating something and it takes a long time, and you don't want to stop it ... but also want to quickly perform some other calculations. For various reasons (including testing), I keep multiple versions of mma on my computer (e.g. 9.0 and 9.01) ... so, if 9.01 is busy doing some calculation, I just open up 9.0 and start doing something new in that. $\endgroup$ – wolfies May 24 '14 at 15:04
21
$\begingroup$

You have a few options depending on your precise needs:

  • many kinds of expressions can be evaluated in parallel;
  • long evaluations can often be paused and you can enter a Dialog where you can examine current values and evaluate other expressions (exit with Return[])
  • the same FrontEnd can control multiple kernels, so for example you can have 2+ notebooks being handled by 2+ different kernels; these are completely separate instances so definitions won't be shared unless you've done something to make that happen (look toward the bottom of the Evaluation menu)
  • you can also run multiple instances of the FrontEnd; usually I find one FE with multiple kernels easier, but in some instances this option makes sense
$\endgroup$
  • $\begingroup$ How does one start a notebook with a new Kernel? $\endgroup$ – jvriesem Mar 9 '15 at 19:35
  • 2
    $\begingroup$ If you are using the FrontEnd and you have set up a second kernel, focus that notebook and navigate to Evaluation > Notebook's Kernel to change it. $\endgroup$ – mfvonh Mar 9 '15 at 20:00
  • 1
    $\begingroup$ Is the normal way of pausing a long evaluation Alt-, mentioned in Szabolcs' comment? $\endgroup$ – Bruno Le Floch Oct 18 '16 at 3:46
  • 2
    $\begingroup$ @Casimir Yes. You can use ParallelSubmit to pass tasks to subkernels, but there is no callback mechanism so retrieving the result may end up blocking the main kernel. You can also use the Evaluator option at the cell level (I use this with style sheets to have different versions of the Input style). If you have MMA v11 you can use LocalSubmit, which is more convenient because it has a callback option to the main kernel. $\endgroup$ – mfvonh Nov 8 '17 at 0:09
  • 1
    $\begingroup$ Suppose you want to share x on kernel1 to kernel2. K1: link = LinkCreate["sharing"] then K2: link = LinkConnect["sharing"] then K1: LinkWrite[link, x] then K2: x = LinkRead[link] $\endgroup$ – mfvonh Feb 22 '18 at 19:44
7
$\begingroup$

Evaluation -> Kernel Configuration Options -> Add "kernel2"->

make new notebook -> Evaluation -> Start Kernel-> "kernel2"

note: in Ubuntu you can just open a second instance of mathematica. Hit the window key to open the launcher and type mathematica and hit enter. It opens a second mathematica instance on my Ubuntu machine.

Also I have found that there doesn't seem to be a limit on how many wolfram scripts you can run simultaneously.

#!/home/conor/mathematica/WolframScript -script
Print["hello world from a wolfram script"]

Maybe they are all executed on the same kernel? But they seem to run fast and at the same time.

enter image description here

$\endgroup$
6
$\begingroup$

If it is just something very short, you can just press F7 (Evaluate in Subsession) instead of Shift+Enter, which will evaluate the expression as a dialog.

This can also be used to launch new parallel kernels during the evaluation of a long parallel table for instance.

$\endgroup$
  • $\begingroup$ note this does "suspend" the running kernel to eval the subsession cell, so it depends on the kernel being in a responsive state. $\endgroup$ – george2079 Jan 11 '18 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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