40

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.

  • 1
    May be you can try http://reference.wolfram.com/mathematica/ref/ParallelEvaluate.html – Nasser May 24 '14 at 11:52
  • 1
    You should find the answer to your question here – Sektor May 24 '14 at 12:20
  • 2
    Possibly also http://reference.wolfram.com/mathematica/tutorial/Dialogs.html – mfvonh May 24 '14 at 14:38
  • 6
    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. – Szabolcs May 24 '14 at 14:44
  • 1
    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. – wolfies May 24 '14 at 15:04

3 Answers3

23

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
mfvonh
  • 8,460
  • 27
  • 42
  • How does one start a notebook with a new Kernel? – jvriesem Mar 09 '15 at 19:35
  • 2
    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. – mfvonh Mar 09 '15 at 20:00
  • 1
    Is the normal way of pausing a long evaluation Alt-, mentioned in Szabolcs' comment? – Bruno Le Floch Oct 18 '16 at 03:46
  • @mfvonh Is there a way to work with multiple (sub-)kernels on the same notebook so that I can continue to work in it while some long evaluation is active? – Janosh Oct 30 '17 at 14:24
  • 2
    @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. – mfvonh Nov 08 '17 at 00:09
  • @mfvonh how can I share definitions between a newly opened kernel and the default kernel in the same FE? – user19218 Feb 22 '18 at 12:20
  • 1
    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] – mfvonh Feb 22 '18 at 19:44
  • I feel like LocalSubmit might be closest to what the OP (and many others who find this question) are looking for. Do I understand correctly that it will be able to send a computation to a parallel kernel which shares all definitions with the main one while keeping the main kernel responsive? A full answer on how to use this function would be very much appreciated. (I would ask a new question but I think it is more appropriate if the information was included here since the new question would be almost identical.) – Kvothe Aug 10 '21 at 17:41
14

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

Conor
  • 7,449
  • 1
  • 22
  • 46
6

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.

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