Main Content

Set Environment Variables on Workers

Some computations use system environment variables, such as computations that require Amazon S3™ access. When you offload computations to workers using Parallel Computing Toolbox™, the client and workers can have different operating system environment variables. On the client, you can use setenv to set environment variables. You can then copy environment variables from the client to the workers so that the workers perform computations in the same way as the client.

Set Environment Variables for Cluster Profile

Every cluster profile that is not a local cluster has an EnvironmentVariables property. You can use this property to specify a list of environment variables to copy from the client to cluster workers. These environment variables are set on the workers for the duration of a job or parallel pool.

Screen shot of Cluster Profile Manager. The MyMJSProfile1 cluster profile is selected, and the Workers dialog is open.

Use the Cluster Profile Manager to manage cluster profiles. To set the EnvironmentVariables property for a cluster profile using the Cluster Profile Manager, use the following steps.

  1. Open the Cluster Profile Manager. To open the Cluster Profile Manager, on the Home tab in the Environment section, select Parallel > Create and Manage Clusters.

  2. In the Cluster Profile Manager, select your cluster in the Cluster Profile list. For this example, select the MyMJSProfile1 cluster.

  3. Go to the Workers section. Add the names of environment variables you want to copy from the client to cluster workers. Use one name per line, with no commas or other delimiters. Any listed variables that are not set are not copied to the workers.

  4. Click Done to save the profile settings.

For more information about the Cluster Profile Manager, see Customize Startup Parameters (MATLAB Parallel Server).

Set Environment Variables for a Job or Pool

You can also copy environment variables from the client to workers programmatically for the duration of a job or a parallel pool. The names are added to the EnvironmentVariables property specified in the parallel profile to form the complete list of environment variables. Any listed variables that are not set are not copied to the workers.

  • When you use createJob or batch to create a job, you can specify the names of environment variables by using the 'EnvironmentVariables' name-value pair argument. These environment variables are set on the workers when the job starts. When the job finishes, the environment variables are returned to their previous values.

  • When you use batch to create a parallel pool, you can specify the names of environment variables by using the 'EnvironmentVariables' name-value pair argument. These environment variables are set on the workers for the duration of the parallel pool.

See Also

| |

Related Topics