clear
close
% if the matalbpool is open, close it
isOpen = matlabpool('size') > 0;
if (isOpen)
    matlabpool close
end
%find out how many workers the user wants
prompt={'Enter the number of workers:'};
name='Open a Matlab Worker Pool';
numlines=1;
defaultAnswer={'2'};
answer=inputdlg(prompt,name,numlines,defaultAnswer);
nWorkers = str2num(answer{1});
%open the pool
matlabpool ('open', nWorkers);
m = 1000000;
 tic;
 numcalcs =100;
parfor p=1:numcalcs
%for p = 1:numcalcs
   z = rand(m, 1) + i*rand(m, 1);
   c(p) = sum(abs(z) < 1);
end
%k = gplus(c);
k=sum(c);
format long
piapprox = 4*k/(m*numcalcs)
time1=toc
%close the matlab pool
isOpen = matlabpool('size') > 0
if (isOpen)
    matlabpool close
end