Main Content

Use Parallel Computing Resources in Deployable Archives

To take advantage of resources from Parallel Computing Toolbox™, you can pass a cluster profile to a MATLAB® application that you deploy to MATLAB Production Server™.

Cluster profiles let you define parallel computing properties for your cluster, such as information about the cluster for your MATLAB code to use and the number of workers in a parallel pool. You apply these properties when you create a cluster, job, and task objects in your MATLAB application. For more information on specifying cluster profile preferences, see Specify Your Parallel Preferences (Parallel Computing Toolbox). To manage cluster profiles, see Discover Clusters and Use Cluster Profiles (Parallel Computing Toolbox).

You can also package MATLAB functions that use parallel language commands into a deployable archive and deploy the archive to MATLAB Production Server. For information on creating and sharing deployable archives, see Create Deployable Archive for MATLAB Production Server and Deploy Archive to MATLAB Production Server.

Deployed MATLAB functions are able to find the parallel cluster profile through the Cluster Profile Manager or an exported profile.

Use Profile Available in Cluster Profile Manager

When you package a MATLAB function into a deployable archive, all profiles available in the Cluster Profile Manager are available in the archive by default. This option is useful when you do not expect the profile to change after deployment.

Link to Exported Profile

If you expect the cluster profile to change, you can export the cluster profile first, then load the profile either programmatically in your MATLAB code or use the --user-data MATLAB Production Server configuration property. For exporting the cluster profile, see Import and Export Cluster Profiles (Parallel Computing Toolbox).

Load Profile Using MATLAB Code

To load the exported profile in your MATLAB function, use parallel.importProfile (Parallel Computing Toolbox). For example, the following sample code imports a profile and creates a cluster object using an exported profile.

clustername = parallel.importProfile('ServerIntegrationTest.settings');
cluster = parcluster(clustername);

Load Profile Using Server Configuration Property

To load the exported profile using the MATLAB Production Server configuration property, set the --user-data property to pass key-value parameters that represent the exported profile. Set the key to ParallelProfile and the value to the path to the exported cluster profile followed by the profile file name. For example, to load a profile called ServerIntegrationTest.settings, set the property as follows:

--user-data ParallelProfile /sandbox/server_integration/ServerIntegrationTest.settings

If you use the command line to manage the dashboard, edit the main_config server configuration file to specify the --user-data property. If you use the dashboard to manage MATLAB Production Server, use the Additional Data field in the Settings tab to specify the --user-data property.

The cluster profile that you provide to the --user-data property is automatically set as the default. Therefore, your MATLAB code does not have to explicitly load it and you can use the default cluster as follows:

cluster = parcluster();

Reuse Existing Parallel Pool in Deployable Archive

The following example uses gcp (Parallel Computing Toolbox) to check if a parallel pool of workers exists. If a pool does not exist, it creates a pool of 4 workers using parpool (Parallel Computing Toolbox).

pool = gcp('nocreate');
if isempty(pool)
    disp("Creating a myCluster")
    parpool('myCluster', 4);
    disp('myCluster pool already exists')


Deployable archives that use parallel computing cannot share parallel pools with other deployable archives.

See Also

(Parallel Computing Toolbox) | (Parallel Computing Toolbox) | (Parallel Computing Toolbox) | (Parallel Computing Toolbox)

Related Topics