I am trying to have each compute kernel in a Mathematica session evaluate a notebook with NotebookEvaluate. Here is a sketch of my code:


computeNotebooks = Map[ FileNameJoin[{NotebookDirectory[],#}]&,
   {"ComputeNotebook1.nb","ComputeNotebook2.nb","ComputeNotebook3.nb"} ]

ParallelMap[ UsingFrontEnd[NotebookEvaluate[#,InsertResults->True]]&, computeNotebooks ]

The notebooks are located in the same directory as the driver notebook which contains the commands above.

With both Mathematica 10.4 and 11 the compute kernels seem to launch a front end but the ParallelMap command then never completes. Aborting the evaluation does not work either.

Also note that running the evaluation on the controller kernel works without problems:

Map[ UsingFrontEnd [NotebookEvaluate[#,InsertResults->True]]&, computeNotebooks ]

Both UsingFrontEnd and ParallelMap are using the same mechanism for tracking the parent process, so they conflict with each other. This is a known issue. In the meantime, there is a workaround: a separate evaluator for each notebook. For instance, here is a set up I used recently,

(* Set up the known evaluators *)
$processorCount = 4;
 EvaluatorNames -> Join[{"Local" -> {"AutoStartOnLaunch" -> True}}, 
  Table["Kernel" <> ToString[i] -> {"AutoStartOnLaunch" -> False}, 
   {i, $processorCount}]]]

 Function[{file, k},
   nb = NotebookOpen[file];
     Evaluator -> "Kernel" <> ToString[Mod[First[k], $processorCount, 1]]
   FrontEndTokenExecute[nb, "SelectAll"];
   FrontEndTokenExecute[nb, "SelectionOpenAllGroups"];
   FrontEndTokenExecute[nb, "EvaluateCells"];

The disadvantage of this method is that you cannot queue up the notebooks, if you have a lot of them, which would allow the load to be better balanced between the kernels.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.