This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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.

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

Examples

Find the Host property of a worker that runs a task. The file identifyWorkerHost.m contains the following function code.

function localHost = identifyWorkerHost()
  thisworker = getCurrentWorker; % Worker object
  localHost = thisworker.Host;   % Host property
end

Create a job with a task to execute this function on a worker and return the worker’s host name. This example manually attaches the necessary code file.

c = parcluster();
j = createJob(c);
j.AttachedFiles = {'identifyWorkerHost.m'};
t = createTask(j,@identifyWorkerHost,1,{});
submit(j)
wait(j)
workerhost = fetchOutputs(j)

Introduced before R2006a