I'm using ParrallelDo
to parallel run another program (windows executable) in 8 subkernels. Sometimes a SubKernel freezes. What I see in the task-manager is that one or two of the MathKernels don't finish executing but build up page faults. The task of the external program has already finished by then. I then terminate the MathKernel with the task-manager by hand and ParallelDo
redistributes the tasks - sometimes successful.
The external program is not written by me - so you can view it as a black box. I call it about 300-2000 times for one simulation which in total can take up to 8 hours - so I want to automatize this process. I want to terminate a subkernel after a specific time (i.e. four times the average time of the last program calls) in order to give ParallelTable
a chance to redistribute the tasks.
Is this possible? And is this a good approach?
I tried TimeConstrained[]
after I saw Pillsys answer but it didn't work for me.
Here are the relevant code snippets:
ParallelDo[
...
PutAppend[...first comment...];
TimeConstained[RunB["program.exe"<>item],600];
PutAppend[...second comment...];
...
,{item,items}]
with
RunB[cmd_String]:= Module[{shell},
shell=NETLink'CreateCOMObject["WScript.shell"];
shell@run[cmd,0,True]
];
After a while I see this in the taskmanager ("Seitenfehler" means page faults):
but the program.exe does not appear in the list so it should have finished. However, Mathematica doesn't reach the second comment so it must still be within the TimeConstrained[] command.
Any thoughts/ideas to how I can kill the task?
RunB
a typo? 2. Have you tried usingRunProcess
? $\endgroup$ReadString
has its ownTimeConstraint
option. $\endgroup$