Matlab Compile Runtime
Due to licensing issues Matlab can't be directly use in the FGI environment. However, many Matlab codes can be translated to C coded executables. This executable can be used in FGI when the Matlab Compiler Runtime (MCR) is available. When Matlab code is executed this way it does not require license and thus large amounts of C converted Matlab codes can be executed simultaneously.
MCR-R2013A Runtime Environment supports c-converted Matlab codes that have been created with the mcc command of Matlab version R2013A (other Matlab versions are not compatible with the Runtime Environment).This Matlab version is available in the taito.csc.fi server of CSC.
A simple Matlab code ( testjob.m) is converted to C exeutable with command: ( download the sample case from here):
mcc -mv testjob.m
The conversion command produces C executable (testjob) and a shell scrip ( run_testjob.sh) that can be used to launch the executable. These components, as well as any input files that the Matlab code uses, needs to be defined as input files in the grid job description file. In this sample case we don't have any input files so the job description file (matlab.xrsl) could look like following:
( "testjob" "testjob" )
( "run_testjob.sh" "run_testjob.sh" )
( "matlabresults.txt" "matlabresults.txt" )
In the command script ( matlabrun.sh) execution permissions must first be defined for the compiled command and execution script. After this the compiled Matlab code is launched using the execution script (run_testjob.sh). The location of the MCR library must be given as the first argument for execution script. When the MCR-R2013A Runtime Environment is used, this location is stored to environment variable: $MCRROOT. The possible arguments of the Matlab code are added to the execution command after this.
In cases where large amounts of Matlab jobs are submitted it is advices to run the actual matlab task in the local temporary directory ($TMPDIR) of the computing node. To do this, the execution script must have steps where the input data is coped to $TMPDIR and the process is moves to the $TMPDIR before the actual execution of the Matlab task. The results must also be copied back to the original job directory when the actual matlab task has finished.
In this example the command script could look like following. :
echo "Hello Matlab!"
#copy data to temporary directory
cp -r * $TMPDIR/
#set execution permissions for the matlab script and executable
chmod u+x run_testjob.sh
chmod u+x testjob
./run_testjob.sh $MCRROOT > matlabresults.txt
#Copy results from the temporary directory
#back to the home directory of the grid job
mv matlabresults.txt $jobdir/
echo "Bye Matlab!"
Set up grid environment and submit the job
Follow the progress of the job and retrieve the result when the job is finished,
In the commands above, job_id should be replaced with the job identifier given by the the arcsub command for example:
The runtime environment sets the following environment variables:
Download and install the MCR installation kits from:
Download runtime environment example for SLURM,
Modify the scripts as needed and save the main script in your ARC runtime directory as APPS/MATH/MRC-R2013A
As long as the interface requirements are satisfied, the implementation does not really matter. And some adaptation is needed anyway to accommodate differences in the cluster environment (batch queue systems, temporary directory location etc.)