Create A Standalone Executable for MATLAB calling Fortran and C
MEX Standalone Folder
batch_standalone -- batch script for standalone
make.m -- m-file to compile this example completely
mexStandalone.zip -- zip file of this directory
mybash.txt -- append to your .bashrc file
mycsh.txt -- append to your .cshrc file
README.html -- this file
runx2.m -- main m-file (calls Fortran and C apps)
submitmjobs -- script to launch multiple batch jobs (optional)
times2.c -- Mathworks' C example (with gateway) to perform multiply
timestwo.F -- Mathworks' equiv. Fortran example (with gateway)
Procedures for generating and running standalone
If you do not have access to Boston University's Shared Computing Cluster (SCC), you may download the mexStandalone.zip file. Upon unzipping it, follow the steps starting from "cd mexStandalone"
If you have access to Boston University's Shared Computing Cluster (SCC), it is more convenient to
scc1% cp -r /project/scv/examples/matlab/misc/mexStandalone your-preferred-path
scc1% cd mexStandalone
Code compilations and running
function runx2(n)
%function runx2(n)
% Purpose: Simple demonstration of calling Fortran and C codes for
% multiplying an input, n, by 2. This program is used to
% demonstrate:
% 1) use of mex to compile C and Fortran codes
% 2) calling procedure of these C/Fortran mex files
% 3) use of mcc to generate standalone to run outside MATLAB
% Input:
% n -- this will be multiplied by 2
% Procedure:
% >> mex timestwo.F % compile fortran file with F suffix
% >> mex times2.c % compile C file
% Generate standalone with -m; non-m-files added to standalone with -a
% >> mcc -m runx2.m -a timestwo.mexa64 times2.mexa64
% Run executable runx2 outside of MATLAB
% scc1% runx2 5
% data passed with command syntax are strings; need conversion for double
if ~isdeployed, disp('Cannot run as m-file.'), return, end
n = str2double(n);
mf=timestwo(n); % run fortran mex file to compute mf = n x 2
disp(['n = ' num2str(n) ' ; mf = n x 2 = ' num2str(mf)])
mc=times2(n); % run C mex file to compute mc = n x 2
disp(['n = ' num2str(n) ' ; mc = n x 2 = ' num2str(mc)])
exit
Append mysch.txt and mybash.txt to .cshrc and .bashrc in your home directory
scc1$ source ~/.bashrc <== if you run the bash shell
scc1% source ~/.cshrc <== if you run the csh shell
Running in batch mode
For instructions on running batch jobs on the SCC, visit the
standaloneDemo folder.
Kadin Tseng, Research Computing Services, IS&T, Boston University
Created : November, 2013
Modified : July, 2014
Note: Research Computing Services (RCS) example programs are provided
"as is" without any warranty of any kind. The user assumes the entire risk of
quality, performance, and repair of any defects. You are encouraged to copy
and modify any of the given examples for your own use.