7
$\begingroup$

after updating to version 11, I came across a problem with the execution of package files via bash.

The WolframScript program runs the entire code, but frequently it does not exit properly and as a result it does not release the terminal. To the best of my knowledge, this only happens when the package contains parallelized functions.

Below follows a short code which illustrates the problem. It works perfectly in v10.3, but frequently fails to exit in v11.0.

Print[ "Hello" ];
data = Table[ { i, i^2 }, { i, 1, 16 } ];

Print[ "Serial calculation complete." ];

Print[ "Launching Kernels" ];
LaunchKernels[4];

data2 = ParallelTable[ { i, i^2 }, { i, 1, 16 } ];
Print[ "Parallel calculation complete." ];

CloseKernels[];  (* workaround instructions *)
Pause[5];         (* workaround instructions *)

test = TrueQ[ data2 == data ];
Print[ "Is data consistent:\t", test ];


Quit[];

The code is run in a bash terminal as

$ WolframScript -script test.m
$ WolframScript10 -script test.m

where

$ ls -la /usr/local/bin/WolframScript*
lrwxrwxrwx 1 root root 90 Aug 24 17:53 /usr/local/bin/WolframScript -> /usr/local/Wolfram/Mathematica/11.0/SystemFiles/Kernel/Binaries/Linux-x86-64/wolframscript
lrwxrwxrwx 1 root root 94 Aug 24 18:02 /usr/local/bin/WolframScript10 -> /usr/local/Wolfram/Mathematica/10.3/SystemFiles/Kernel/Binaries/Linux-x86-64/MathematicaScript

This has been reported to the Wolfram Support team, it appears to be a problem with the management of kernels (particularly, closing them).

In the meanwhile, we can workaround it with a combination of the CloseKernels[], Pause[5] instructions and running the script via math, instead of WolframScript. The first ensures that the parallel kernels are closed and the second gives additional time to close parallel kernels before proceeding to the next instruction line. Last, the support team recommended to use math, rather than WolframScript. Even without the above-mentioned changes, the issue becomes less frequent than when running with WolframScript.

$ math -script test.m
$\endgroup$
  • $\begingroup$ at the first glimps I thought it is 'never exists', a great shock! ;) $\endgroup$ – Wjx Aug 24 '16 at 11:55
  • $\begingroup$ Perhaps file a report with Support, this is likely something they'd like to investigate $\endgroup$ – user6014 Aug 24 '16 at 13:21
  • $\begingroup$ The support team recommend a workaround using the CloseKernels[] and Wait[] instructions, details in the revised version of the post. $\endgroup$ – fabio.hipolito Aug 29 '16 at 5:51
  • $\begingroup$ The previous comment should read Pause[] instead of Wait[] $\endgroup$ – fabio.hipolito Aug 30 '16 at 12:36
  • $\begingroup$ Updating to v11.0.1 improved the issues with WolframScript, making it work as well as math. Yet, the core issue remains and the workaround with CloseKernels[] and Pause[5] remains necessary and robust. $\endgroup$ – fabio.hipolito Oct 7 '16 at 4:27

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.