Multistart: parallel task ID

It happens often that one has to run MultiStart together with fmincon to find the optima of some function. If there is a possibility to get the error (function behaves not so stable / other unexpected events) then one usually uses try/catch blocks.

However, if the computation takes a lot of time, we want to log the computation progress. There is pretty nice logger class log4m. But using MultiStart with ‘UseParallel‘ option the plain output to the log file will be a complete mess: information will come independently from workers and the log file becomes unreadable.

The way to overcome this mess is to annotate the events that happen while computation with worker/task ID. The following solution will work with CJS (common job scheduler) objects:

task = getCurrentTask;
if(~isempty(task))
  do_something_with_ID(task.ID);
end

The information about the fields of the structure can be obtained using

help parallel.task.CJSTask

If you want to know the ID of the process associated to each worker you can use the following

worker = getCurrentWorker;
if(~isempty(worker))
  do_something_with_ID(worker.ProcessId);
end

And the help on the fields of the structure can be obtained using

help parallel.cluster.CJSWorker