Use Parallel Computing Toolbox in Deployed Applications - MATLAB & Simulink (original) (raw)
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 > .
- In the Cluster Profile Manager dialog, select a profile, and in the Manage section, clickExport.
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);
The function 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);
This is a good practice if the cluster profile is centrally managed for your application. If the user of your application has a cluster profile that is held locally, you can expand a relative path to it from the current working directory:
mpSettingsPath = fullfile(pwd, '../rel/path/to/myClusterProfile.mlsettings'); setmcruserdata('ParallelProfile', mpSettingsPath);
This is a good practice if the user of your standalone application should supply their own cluster profile. Any files that you add to your application at compilation are added to the MATLAB search path. Therefore, you can also bundle a cluster profile that is held externally with your application. First, use which
to get the absolute path to the cluster profile. Then, link to it.
mpSettingsPath = which('myClusterProfile.mlsettings'); setmcruserdata('ParallelProfile', mpSettingsPath);
Finally, compile at the command line and add the cluster profile.
mcc -a /path/to/myClusterProfile.mlsettings -m myApp.m;
Note that to run your application before you compile, you must manually add/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
Topics
- Using MATLAB Runtime User Data Interface
- Specify Parallel Computing Toolbox Profile in .NET Application (MATLAB Compiler SDK)
- Specify Parallel Computing Toolbox Profile in Java Application (MATLAB Compiler SDK)