| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB Builder JA |
| Contents | Index |
| Learn more about MATLAB Builder JA |
This feature provides a lightweight interface for easily accessing MCR data. It allows data to be shared between an MCR instance, the M-code running on that MCR, and the wrapper code that created the MCR. Through calls to the MCR User Data interface API, you access MCR data through creation of a per-MCR-instance associative array of mxArrays, consisting of a mapping from string keys to mxArray values. Reasons for doing this include, but are not limited to:
You need to supply run–time configuration information to a client running an application created with the Parallel Computing Toolbox. Configuration information may be supplied (and change) on a per-execution basis. For example, two instances of the same application may run simultaneously with different configuration files.
You want to initialize the MCR with constant values that can be accessed by all your M applications
You want to set up a global workspace — a global variable or variables that MATLAB and your client can access
You want to store the state of any variable or group of variables
MATLAB Builder JA software supports per-MCR instance state access through an object-oriented API. Unlike MATLAB Compilersoftware, access to a per-MCR instance state is optional, rather than on by default. You can access this state by adding setmcruserdata.m and getmcruserdata.m to your deployment project or by specifying them on the command line.
For more information, see Improving Data Access Using the MCR User Data Interface in the MATLAB Compiler User's Guide.
Following is a complete example of how you can use the MCR User Data Interface as a mechanism to specify a configuration .mat file for Parallel Computing Toolbox applications.
Supply configuration information by setting the MCR User Data key ParallelConfigurationFile in your application. The specified configuration will be set as the default parallel configuration and used by Parallel Computing Toolbox functions such as matlabpool.
function ranks = parmagic
cfg = defaultParallelConfig();
fprintf('Using parallel configuration: %s\n',cfg);
n = 10;
matlabpool('open');
parfor ind=1:n
ranks(ind) = rank(magic(ind));
end
matlabpool('close');Use MATLAB Compiler to build the deployable component Parmagic from parmagic.m:
>> mkdir out
>> mcc -d out -W
'java:com.mathworks.parmagicComponent,Parmagic'
parmagic.m setmcruserdata.m pctRunDeployedCleanup.m
The Java™ application udata.java relays the configuration information passed via command line to the Parmagic component via the MCR User Data Interface.
public class udata
{
public static void main(String[] args)
{
/* First argument is the parallel configuration file */
MWCharArray configFile = new MWCharArray(args[0]);
Object[] result = null;
Parmagic m = null;
try
{
m = new Parmagic();
String key = "ParallelConfigurationFile";
m.setmcruserdata(key, configFile);
int nargout = 1;
result = m.parmagic(nargout);
MWClassID classID = ((MWArray)result[0]).classID();
if (classID.equals(MWClassID.DOUBLE))
{
double[][] resultarray =
(double[][])((MWArray)result[0]).toArray();
double[] ranks = resultarray[0];
for (int i=0; i<ranks.length; i++)
{
System.out.println(
"rank(magic(" + (i+1) + ")) =
" + ranks[i]);
}
}
}
catch (Exception e)
{
System.out.println("Exception: " + e.toString());
}
finally
{
MWArray.disposeArray(configFile);
if (result!=null)
{
MWArray.disposeArray(result[0]);
}
if (m!=null)
{
try
{
m.pctRunDeployedCleanup();
}
catch (Exception e)
{
System.out.println("Exception: " +
e.toString());
}
m.dispose();
}
}
}
}Use javac to compile program udata.java:
javac -d out -g -classpath \
.:"$MWE_INSTALL/toolbox/javabuilder/jar/javabuilder.jar"\
:./out/parmagicComponent.jar udata.javaRun the Java application. myconfig.mat is a parallel configuration file exported from MATLAB that specifies the configuration when the application is run.
java -classpath \
.:"$MWE_INSTALL/toolbox/javabuilder/jar/javabuilder.jar"\
:./parmagicComponent.jar udata myconfig.mat
![]() | Managing Native Resources | Dynamically Specifying Run-Time Options to the MCR | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |