Use Parallel Computing Toolbox in Deployed Applications
An application that uses the Parallel Computing Toolbox™ can use cluster profiles that are in your MATLAB® preferences folder. To find this folder, use prefdir
.
For instance, when you create a standalone application, all of the profiles available in your Cluster Profile Manager will be available in the application.
Your application can also use a cluster profile given in an external file. To enable your application to use this file, you can either:
Link to the file within your code.
Pass the location of the file at run time.
Export Cluster Profile
To export a cluster profile to an external file:
In the Home tab, in the Environment section, select Parallel > Create and Manage Clusters.
In the Cluster Profile Manager dialog, select a profile, and in the Manage section, click Export.
Link to Parallel Computing Toolbox Profile Within Your Code
To enable your application to use a cluster profile given in an external file, you can link to the file from your code. In this example, you will use absolute paths, relative paths, and the MATLAB search path to link to cluster profiles. Note that since each link is specified before you compile, you must ensure that each link does not change.
To set the cluster profile for your application, you can use the setmcruserdata
function.
As your MATLAB preferences folder is bundled with your application, any relative links to
files within the folder will always work. In your application code, you can use the
myClusterProfile.mlsettings
file found within the
MATLAB preferences
folder.
mpSettingsPath = fullfile(prefdir, 'myClusterProfile.mlsettings'); setmcruserdata('ParallelProfile', mpSettingsPath);
fullfile
gives the absolute path for the external file.
The argument given by mpSettingsPath
must be an absolute path. If the
user of your application has a cluster profile located on their file system at an
absolute path that will not change, link to it
directly:mpSettingsPath = '/path/to/myClusterProfile.mlsettings'; setmcruserdata('ParallelProfile', mpSettingsPath);
mpSettingsPath = fullfile(pwd, '../rel/path/to/myClusterProfile.mlsettings'); setmcruserdata('ParallelProfile', mpSettingsPath);
which
to get the
absolute path to the cluster profile. Then, link to
it.mpSettingsPath = which('myClusterProfile.mlsettings'); setmcruserdata('ParallelProfile', mpSettingsPath);
mcc -a /path/to/myClusterProfile.mlsettings -m myApp.m;
/path/to/
to your MATLAB search path.Pass Parallel Computing Toolbox Profile at Run Time
If the user of your application myApp
has a cluster profile
that is selected at run time, you can specify this at the command line.
myApp -mcruserdata
ParallelProfile:/path/to/myClusterProfile.mlsettings |
Note that when you use the setmcruserdata
function in your
code, you override the use of the -mcruserdata
flag.
Switch Between Cluster Profiles in Deployed Applications
When you use the setmcruserdata
function, you remove
the ability to use any of the profiles available in your Cluster Profile Manager. To
re-enable the use of the profiles in Cluster Profile Manager, use
the parallel.mlSettings
file.
mpSettingsPath = '/path/to/myClusterProfile.mlsettings'; setmcruserdata('ParallelProfile', mpSettingsPath); % SOME APPLICATION CODE origSettingsPath = fullfile(prefdir, 'parallel.mlsettings'); setmcruserdata('ParallelProfile', origSettingsPath); % MORE APPLICATION CODE
Sample C Code to Load Cluster Profile
You can call the mcruserdata
function natively in C and C++
applications built with MATLAB
Compiler SDK™.
mxArray *key = mxCreateString("ParallelProfile"); mxArray *value = mxCreateString("/path/to/myClusterProfile.mlsettings"); if (!setmcruserdata(key, value)) { fprintf(stderr, "Could not set MCR user data: \n %s ", mclGetLastErrorMessage()); return -1; } |
See Also
setmcruserdata
| getmcruserdata