I have written a parallel script file that after initializing the kernels it puts the result of some computation in a file. I provide some external parameters to the script. I would like to run the script several times with different parameters, however every time the script runs it inizialises again the kernels, wasting a lot of time.

The script structure is something like

param = ToExpression[ $ScriptCommandLine[[2]] ];


WriteString[s,param<>"  "<>ToString@MaxDat<>"\n"];

and I run in terminal through, for instance for param=2 and param=3

wolframscript -script prova.wls 2
wolframscript -script prova.wls 3

Every time I called the command the script launches the kernels. It is possible to inizializes the kernels only during the first run and keep them opened? I had a look at similar questions but I did not find the answer.

  • $\begingroup$ Why do you insist on invoking wolframscript many times with command line parameters? You could write a single program that runs once and does everything you need, for all parameters. Running "scripts" like this is not the most effective way of using Mathematica. If each run is so fast that the time to start parallel kernels matters, why are you even using the command line instead of the notebook interface? $\endgroup$ – Szabolcs Oct 2 '17 at 9:18
  • $\begingroup$ I agree with you, but I need to keep a ssh session alive from remote and I am trying to follow the suggestion in mathematica.stackexchange.com/questions/151981/…. The computation of every script is not slow compared with the initialization time of the kernels (it depends on the value of the parameter...the code I showed you it is just an example), however it is unnecessary, and I am trying to understand whether it is possible to avoid it. $\endgroup$ – Galuoises Oct 2 '17 at 10:43
  • $\begingroup$ That explains why you don't want to use notebooks, but I still do not see why you want a separate run for each parameter value. $\endgroup$ – Szabolcs Oct 2 '17 at 10:46
  • $\begingroup$ I need to analyse the data with some parameters before choosing whether or not generate further data...the choice of the parameter I put depends on the partial results (I cannot automate this stage, unfortunately). $\endgroup$ – Galuoises Oct 2 '17 at 10:51
  • $\begingroup$ I still don't understand why you can't just run everything in Mathematica instead of invoking multiple scripts from the shell. Mathematica runs interactively, so you can use it even for tasks that require human decision from time to time. The screen utility helps you run it on the server, disconnect, reconnect, and still find it where it was. $\endgroup$ – Szabolcs Oct 2 '17 at 10:53

Your Answer

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

Browse other questions tagged or ask your own question.