Hi, I have difficulty in outputting information to matlab command window when multi-task are running. Specifically I am using a independent multi-task parallel mode. Below is the way I created my multi-task within one job
parallel.defaultClusterProfile('local');
cluster = parcluster();
job = createJob(cluster);
createTask(job, funcHandles, numArray, args,'CaptureDiary',true);
submit(job);
wait(job);
results = fetchOutputs(job);
Within each funcHandle, I want to output some text during the execution. It is said that after matlab 2012b, this functionality is enabled through parallel.Task.Diary property. However, I can neither get nor set such property during the running of the task.There is completely no examples or explanation on how to access this property at all.
I know that I can output the info into a log file. But I still prefer to display something in the command window.
Can anyone help me? Thank you.

 채택된 답변

Edric Ellis
Edric Ellis 2014년 6월 2일

1 개 추천

The task "diary" property is updated automatically when your task function would emit text to the command window. For example:
c = parcluster('local');
j = createJob(c);
t = createTask(j, @disp, 0, {magic(4)}, 'CaptureDiary', true);
submit(j);
wait(j);
t.Diary

댓글 수: 5

Xinyi Shen
Xinyi Shen 2014년 6월 2일
Yes. But is there a way to output the text to the command window during the execution of the task rather than displaying all after the task is finished?
Thank you.
Edric Ellis
Edric Ellis 2014년 6월 2일
Yes, simply invoke "t.Diary" while the task is executing. (This is mentioned in the release notes for R2012b).
Xinyi Shen
Xinyi Shen 2014년 6월 2일
Thank you.
But in your code, t.Diary appears after wait(j), which means the diary will be output to the command window after the task is done. However, I need the command window output during the execution of the task.Is there a way?
You can execute "t.Diary" at any time - including before "wait(j)". So, you might do:
...
submit(j);
while ~strcmp(j.State, 'finished')
disp(t.Diary);
pause(5);
end
Of course, that will display the entire diary each time around the "while" loop. You might want to do something more sophisticated like checking the diary to display only the new lines.
Xinyi Shen
Xinyi Shen 2014년 6월 8일
편집: Xinyi Shen 2014년 6월 8일
That works. Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

2014년 5월 25일

편집:

2014년 6월 8일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by