0
$\begingroup$

I feel this question probably has been asked before, but I can't find a thread with a clear enough answer. Let me know if you can help locate anything useful.

As the title suggests, I want to run different calculations at the same time. Typically, we have program A running now, which will last for hours. In the meantime, I need to calculate B, maybe a different version of A or some completely different stuff. How to start B completely independently from A?

Firstly, a new notebook doesn't help. It only waits until A finishes. This is probably the main question.
Secondly, by 'independently', I mean if A and B happen to have certain same variable names or so, surely we want to avoid any possible side effects. And I usually start my programs with ClearAll["Global`*"];. But running B had better not clean anything in A. In this sense, maybe this command is no longer a good practice?
(Optional) Thirdly, with parallelization. If A uses 2 cores and B uses another 2 cores, is the above still possible?

I remember that one can open a new instance of MMA in Windows, but this doesn't seem available in Mac.

$\endgroup$
5
  • $\begingroup$ Regarding your variables you should have a look at Module. With this you can treat your variables inside Moduleas local and they won't be defined outside it. $\endgroup$
    – rowsi
    Feb 3, 2022 at 8:27
  • 2
    $\begingroup$ For your parallelization needs, you might find ParallelSubmit to do the trick. $\endgroup$
    – rowsi
    Feb 3, 2022 at 8:33
  • $\begingroup$ ClearAll["Global*"];` is indeed not a good practice in general. As rowsi suggests, get into the habit of localizing variables with Module, Block, or With in greater projects. $\endgroup$ Feb 3, 2022 at 8:44
  • 1
    $\begingroup$ If you have enough RAM, you may start Mathematica twice. $\endgroup$ Feb 3, 2022 at 9:36
  • $\begingroup$ In mathematica, you can see a command for configuring kernels in the Evaluation menu. Add a kernel there, and assign it to a new notebook. $\endgroup$
    – rnotlnglgq
    Mar 11, 2022 at 14:18

0

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.