Index of /examples/matlab/misc/mexStandalone

Icon  Name                    Last modified      Size  Description
[DIR] Parent Directory - [   ] batch_standalone 24-Jul-2014 10:10 2.2K [   ] dd 25-Jul-2014 16:10 75 [   ] make.m 24-Jul-2014 08:55 146 [   ] mccExcludedFiles.log 25-Jul-2014 16:09 458K [   ] mexStandalone.zip 24-Jul-2014 10:13 7.4K [TXT] mybash.txt 23-Jul-2014 16:12 709 [TXT] mycsh.txt 23-Jul-2014 16:12 731 [TXT] readme.txt 25-Jul-2014 16:09 3.6K [   ] run_runx2.sh 25-Jul-2014 16:09 1.1K [   ] runx2 25-Jul-2014 16:09 91K [   ] runx2.m 25-Jul-2014 16:11 1.1K [   ] submitmjobs 24-Jul-2014 09:00 1.5K [   ] times2.c 23-Jul-2014 15:34 1.3K [   ] times2.mexa64 25-Jul-2014 16:08 7.2K [   ] timestwo.F 23-Jul-2014 15:34 2.5K [   ] timestwo.mexa64 25-Jul-2014 16:08 7.5K [DIR] tmp/ 07-Aug-2014 14:03 -

Create A Standalone Executable for MATLAB calling Fortran and C

MEX Standalone Folder

  1. batch_standalone -- batch script for standalone
  2. make.m -- m-file to compile this example completely
  3. mexStandalone.zip -- zip file of this directory
  4. mybash.txt -- append to your .bashrc file
  5. mycsh.txt -- append to your .cshrc file
  6. README.html -- this file
  7. runx2.m -- main m-file (calls Fortran and C apps)
  8. submitmjobs -- script to launch multiple batch jobs (optional)
  9. times2.c -- Mathworks' C example (with gateway) to perform multiply
  10. timestwo.F -- Mathworks' equiv. Fortran example (with gateway)

Procedures for generating and running standalone

  1. 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"
  2. 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
  3. 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
    
  4. Append mysch.txt and mybash.txt to .cshrc and .bashrc in your home directory
    scc1% cat mycsh.txt >> ~/.cshrc
    scc1% cat mybash.txt >> ~/.bashrc
  5. To make the changes effective immediately
    scc1$ source ~/.bashrc     <== if you run the bash shell
    scc1% source ~/.cshrc      <== if you run the csh shell
  6. 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.