flag whether or not a program has been called by createTask

조회 수: 1 (최근 30일)
Leo Simon
Leo Simon 2015년 1월 11일
편집: Edric Ellis 2016년 1월 11일
I run certain jobs either as standalone jobs, or in parallel, for example called by createTask. Is there some way to distinguish between these cases? obviously I could use brute force, use dbstack and related tools and check if the calling line had the word createTask in it, but I'd much prefer to do something more general/elegant. Since one can interact with programs in the former case, but not the latter, there must be something matlab knows that I can tap into...
Thanks very much for any help!
Leo

채택된 답변

Edric Ellis
Edric Ellis 2015년 1월 12일
편집: Edric Ellis 2015년 1월 12일
One simple way is to check the return of getCurrentTask. This will always return empty in a desktop MATLAB session, and a parallel.Task object when running on a worker.
  댓글 수: 3
Leo Simon
Leo Simon 2016년 1월 11일
I accepted this answer but at the time I must have been running version R14b, with 15a it returns a warning
>> isempty(getCurrentTask)
Warning: Unexpected error trying to obtain the current task.
> In getCurrentTask (line 24)
Warning from getCurrentTask (line 24)
warning(message('parallel:cluster:GetCurrentTaskFailed'));
I can of course suppress the warning, but if this is the only/best way to check if I'm in parallel, then it's disappointing.
Edric Ellis
Edric Ellis 2016년 1월 11일
편집: Edric Ellis 2016년 1월 11일
Hm, I don't see the warning in R2015a. What are your precise reproduction steps to get that? Here's what I did, after opening a (local) parallel pool:
>> getCurrentTask
ans =
[]
>> spmd, getCurrentTask, end
Lab 1:
ans =
Task with properties:
ID: 1
State: running
Function: @distcomp.nop
Parent: Job 7
StartTime: Mon Jan 11 12:43:28 GMT 2016
Running Duration: 0 days 0h 0m 60s
ErrorIdentifier:
ErrorMessage:
>>

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by