function theanswer = psimulate(nruns, filedep, fxn, varargin) %PSIMULATE, parrallel simulate %The syntax is: %theanswer = psimulate(nruns, thefxn, varargin) %Where nruns is the number of times to run your simulation function. %fxn is a string containing the name of your function %The remaining arguments are then used as arguments to the function in thefxn. %This will return a cell array of outputs. varargintemp = varargin; a=findResource('jobmanager','LookUpURL','rescluster2.mgh.harvard.edu') try a=a(1); catch end b=createJob(a,'fileDependencies',filedep); for i = 1 : nruns createTask(b,fxn,1,varargintemp) end submit(b); while (~strcmp(get(b,'state'),'finished')) pause(3); end theanswer=getAllOutputArguments(b); temp = size(theanswer); temp = temp(2); if (temp==0) disp('An error has occured'); t=get(j,'tasks'); theanswer=get(t,'errormessage'); end destroy(j);