Quantcast

Documentation Center

  • Trial Software
  • Product Updates

getCurrentWorker

Worker object currently running this session

Syntax

worker = getCurrentWorker

Arguments

worker

The worker object that is currently evaluating the task that contains this function.

Description

worker = getCurrentWorker returns the Parallel.Worker object representing the MATLAB worker session that is currently evaluating the task function that contains this call.

Examples

Create a job with one task, and have the task return the worker that evaluates it. Then view the Host property of the worker:

c = parcluster();
j = createJob(c);
t = createTask(j, @getCurrentWorker, 1, {});
submit(j)
wait(j)
w = t.OutputArguments{1};
h = w.Host

The task t executes getCurrentWorker to get an object representing the worker that is evaluating the task. The result is placed in the OutputArguments property of the task.

Create a task to return only the Host property value of its worker:

c = parcluster();
j = createJob(c);
t = createTask(j, @() get(getCurrentWorker,'Host'), 1, {});
submit(j)
wait(j)
h = t.OutputArguments{1}

This code defines a task to run an anonymous function, which uses get to view the Host property of the worker object returned by getCurrentWorker. So only the Host property value is available in the OutputArguments property.

More About

expand all

Tips

If the function runs in a MATLAB® session that is not a worker, it returns an empty result.

See Also

| | |

Was this topic helpful?