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, by default 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.
To export a cluster profile to an external file:
In the Home tab, in the Environment section, select Parallel > Manage Cluster Profiles.
In the Cluster Profile Manager dialog, select a profile, and in the Manage section, click Export.
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 as 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 you application code, you can use the myClusterProfile.mlsettings
file found within the MATLAB preferences folder as follows:
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 as follows:mpSettingsPath = '/path/to/myClusterProfile.mlsettings'; setmcruserdata('ParallelProfile', mpSettingsPath);
mpSettingsPath = fullfile(pwd, '../rel/path/to/myClusterProfile.mlsettings'); setmcruserdata('ParallelProfile', mpSettingsPath);
-a
flag when compiling with mcc
is added to the MATLAB search path. Therefore, you can also bundle a cluster profile with your application that is held externally. First, use 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.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.
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
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; } |