function theanswer = pbootstrp(varargin)

%PBOOTSTRP, the parallel bootstrap function
%the syntax is: theanswer = pbootstrp(varargin)
%the call is identical to nonparallel bootstrap
%The function extracts the first argument and determines the number of tasks to create
%The remainder of the arguments are used as arguments to the function given to the bootstrap
%The function returns a cell array of outputs. 

variables=varargin;
a=findResource('jobmanager','LookUpURL','rescluster2.mgh.harvard.edu')
try
	a=a(1);
catch
end
b=createJob(a);
nruns=variables{1};
variables{1}=1;
for i = 1 : nruns
createTask(b,@bootstrp,2,variables)
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);
