Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I find out the current worker in my parfor loop?

247 views
Skip to first unread message

R

unread,
Jan 13, 2011, 11:46:08 AM1/13/11
to
I have an 8 core machine and I am trying to set up parfor looping for Parallel computing.

1). How can I find out the worker name/number that is currently running??
I tried getCurrentTask, getCurrentWorker, but I only get [ ].

2). Also, in getCurrentTask doc it says:
"If the function is executed in a MATLAB session that is not a worker, you get an empty result". How can I find out if it's executing in a worker or not?

Note:
I have 8 workers running and I am simply running my code within parfor loop(of course accounting for all the 'Limitations' in 'Programming Considerations' and other basic setup stuff.)

Any help shall be appreciated. Thanks!

R

unread,
Jan 13, 2011, 5:14:06 PM1/13/11
to
"R " <ritikag...@gmail.com> wrote in message <igna8g$ghl$1...@fred.mathworks.com>...

Any ideas/suggestions??

Edric M Ellis

unread,
Jan 14, 2011, 2:56:35 AM1/14/11
to
"R " <ritikag...@gmail.com> writes:

> I have an 8 core machine and I am trying to set up parfor looping for
> Parallel computing.
>
> 1). How can I find out the worker name/number that is currently running?? I
> tried getCurrentTask, getCurrentWorker, but I only get [ ].

Did you try something like this:

matlabpool local 8
parfor ii = 1:8
t = getCurrentTask();
id(ii) = t.ID;
end

> 2). Also, in getCurrentTask doc it says: "If the function is executed
> in a MATLAB session that is not a worker, you get an empty
> result". How can I find out if it's executing in a worker or not?

You could simply use the fact that the return of getCurrentTask is empty
to indicate whether you're on a worker

isOnWorker = ~isempty( getCurrentTask() ) % returns false
parfor ii = 1:8
isOnWorker(ii) = ~isempty( getCurrentTask() ) % all true
end

Cheers,

Edric.

R

unread,
Jan 15, 2011, 1:01:06 PM1/15/11
to
Edric M Ellis <eel...@mathworks.com> wrote in message <ytwtyhb...@uk-eellis-deb5-64.dhcp.mathworks.com>...

It worked!! Thanks Edric..

Alexander Andreychenko

unread,
Apr 4, 2016, 7:58:09 AM4/4/16
to
If you additionally want to know the process ID that your worker is attached to, you can use;

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

It shall hold when you use CJS (common job scheduler) workers.
0 new messages