function runBatchJob()
% function runBatchJob()
% Purpose: 
% By default, a Parallel Computing Toolbox (PCT) job generates
% support folders and files on the user's ~/.matlab on the login
% node. Because SCC batch job is executed on a compute node, it
% is more efficient to create these support folders/files on the 
% compute node to avoid non-local I/O communications.
% Function myFCT.m computes s = 1+2+3+...+n with nslots cores
% qsub -t 100-300:200 run_matlab_pct_job  (n=100, 200, 300)
% qsub run_matlab_pct_job  (n=100)
% Kadin Tseng, RCS, IS&T, Boston University, February, 2015

[nslots, task] = getbev;  % RCS util to get batch-generated env vars

if task == 'undefined'
  n = 100;   % default if Array Job (qsub -t) not used
else
  n = task;  % for Array Jobs, each job has its only n
end

myCluster = parcluster('local')  % treat compute node as "local"
if isBatch    % if this job submitted by qsub, then
  myCluster.JobStorageLocation = getenv('TMPDIR')  % for batch job
end

% starts pool on myCluster with nslots cores
parpool(myCluster, nslots) 
[txt, s, x] = myFCT(n, 4)  % compute s=1+2+...+n with parfor
delete(gcp)

end
