sgeParallelSubmitFcn.m
function sgeParallelSubmitFcn( scheduler, job, props, varargin )
%sgeParallelSubmitFcn - parallel submission for SGE
% Copyright 2006 The MathWorks, Inc.
% $Revision: 1.1.6.2 $ $Date: 2006/12/27 20:40:57 $
% Set up the environment for the decode function - the wrapper shell script
% will ensure that all these are forwarded to the MATLAB workers.
setenv('MATLAB_ENV_SETTING', '/exports/work/is_iti_ug/ywan/my_matlab_env.sh');
system(' if [ -r ${MATLAB_ENV_SETTING} ]; then rm -f ${MATLAB_ENV_SETTING}; fi ');
system(' touch ${MATLAB_ENV_SETTING}; chmod +x ${MATLAB_ENV_SETTING}');
setenv( 'MDCE_DECODE_FUNCTION', 'sgeParallelDecode' );
system('echo "export MDCE_DECODE_FUNCTION=${MDCE_DECODE_FUNCTION}" >> ${MATLAB_ENV_SETTING}');
setenv( 'MDCE_STORAGE_LOCATION', props.StorageLocation );
system('echo "export MDCE_STORAGE_LOCATION=${MDCE_STORAGE_LOCATION}" >> ${MATLAB_ENV_SETTING}');
setenv( 'MDCE_STORAGE_CONSTRUCTOR',props.StorageConstructor );
system('echo "export MDCE_STORAGE_CONSTRUCTOR=${MDCE_STORAGE_CONSTRUCTOR}" >> ${MATLAB_ENV_SETTING}');
setenv( 'MDCE_JOB_LOCATION', props.JobLocation );
system('echo "export MDCE_JOB_LOCATION=${MDCE_JOB_LOCATION}" >> ${MATLAB_ENV_SETTING}');
% Ask the workers to print debug messages by default:
setenv('MDCE_DEBUG', 'true');
system('echo "export MDCE_DEBUG=${MDCE_DEBUG}" >> ${MATLAB_ENV_SETTING}');
% Set this so that the script knows where to find MATLAB, MW_SMPD and MW_MPIEXEC
% on the cluster. This might be empty - the wrapper script will deal with that
% eventuality.
setenv( 'MDCE_CMR', scheduler.ClusterMatlabRoot );
system('echo "export MDCE_CMR=${MDCE_CMR}" >> ${MATLAB_ENV_SETTING}');
% Set this so that the script knows where to find MATLAB, SMPD and MPIEXEC on
% the cluster. This might be empty - the wrapper script must deal with that.
setenv( 'MDCE_MATLAB_EXE', props.MatlabExecutable );
system('echo "export MDCE_MATLAB_EXE=${MDCE_MATLAB_EXE}" >> ${MATLAB_ENV_SETTING}');
%setenv( 'MDCE_MATLAB_ARGS', props.MatlabArguments );
setenv( 'MDCE_MATLAB_ARGS', '-parallel' );
system('echo "export MDCE_MATLAB_ARGS=${MDCE_MATLAB_ARGS}" >> ${MATLAB_ENV_SETTING}');
% The wrapper script is in the same directory as this M-file
[dirpart] = fileparts( mfilename( 'fullpath' ) );
% scriptName = fullfile( dirpart, 'sgeParallelWrapper.sh' );
scriptName = '/exports/work/is_iti_ug/ywan/sgeParallelWrapper.sh'
% Forward the total number of tasks we're expecting to launch
setenv( 'MDCE_TOTAL_TASKS', num2str( props.NumberOfTasks ) );
system('echo "export MDCE_TOTAL_TASKS=${MDCE_TOTAL_TASKS}" >> ${MATLAB_ENV_SETTING}');
% Choose a file for the output. Please note that currently, DataLocation refers
% to a directory on disk, but this may change in the future.
logFile = fullfile( scheduler.DataLocation, ...
sprintf( 'Job%d.mpiexec.out', job.ID ) );
% Choose a number of processors per node to use (you will need to customise
% this section to match your cluster).
nodesArg = sprintf( '-pe matlab %d', props.NumberOfTasks );
% Finally, submit to SGE. note the following:
% "-N Job#" - specifies the job name
% "-j yes" joins together output and error streams
% "-o ..." specifies where standard output goes to
% add "-cwd" and display the comdline
cmdLine = sprintf( '. /exports/work/is_iti_ug/ywan/my_matlab_env.sh; qsub -cwd -N Job%d -j yes -o "%s" %s "%s"', job.ID, logFile, nodesArg, scriptName );
full_cmd = sprintf('ssh eddie.ecdf.ed.ac.uk "%s"', cmdLine);
% disp(cmdLine);
disp(full_cmd);
%[s, w] = system( cmdLine );
[s, w] = system( full_cmd );
% Report an error if the script did not execute correctly.
if s
warning( 'distcompexamples:generic:SGE', ...
'Submit failed with the following message:\n%s', w);
else
% The output of successful submissions shows the SGE job identifier%
fprintf( 1, 'Job output will be written to: %s\nQSUB output: %s\n', logFile, w );
end
Note:
1. This m file could be placed in any matlab path. I suggest $matlab-root-dir/work/
2. You need replace all /exports/work/is_iti_ug/ywan/ by your shared directory in this function file