How to replace matlapool by parpool in my code ?

8 views (last 30 days)
Hello everyone !
I worked with a code in matlab 2012 , and it worked very well at first.. But then, i used matlab 2015 and my function matlabpool disapeared , replaced by parpool. The problem is that i didn't succeed in replacing my piece of code using matlabpool.
arete_connex3D = NaN(neighborhood_size*neighborhood_size*neighborhood_size-1,numel(ROI_struct));
indexNonNaN = find(~isnan(ROI_struct));
if ~isempty(indexNonNaN)
isOpen = matlabpool('size') > 0;
if ~isOpen
matlabpool('open','local',3);
end
for n = 1:numel(indexNonNaN)
index_in_matrix = indexNonNaN(n);
pos = ind2sub_new(sz,index_in_matrix,'mat');
x = pos(1); y = pos(2); z = pos(3);
ind2 = 1;
for i = (x-floor(neighborhood_size/2)):(x+floor(neighborhood_size/2))
for j = (y-floor(neighborhood_size/2)):(y+floor(neighborhood_size/2))
for k = (z-floor(neighborhood_size/2)):(z+floor(neighborhood_size/2))
if i>=1 && i<=sz(1) && j>=1 &&j<=sz(2) && k>=1 && k<=sz(3) ...
&& ~isequal([x,y,z],[i,j,k])
arete_connex3D(ind2,index_in_matrix) = sub2ind_3D(sz,[i,j,k]);
ind2 = ind2 + 1;
end
end
end
end
end
isOpen = matlabpool('size') > 0;
if isOpen
matlabpool close
end
end
I tried some things but it didn't work, i really don't know how to do that. Thank you in advance for your help.

Accepted Answer

Matt J
Matt J on 23 Aug 2015
Edited: Matt J on 24 Aug 2015
Something like this perhaps,
function varargout = matlabpool(varargin)
varargout={};
arg1=varargin{1};
switch arg1
case 'open'
parpool(varargin{2:end});
case 'close'
delete(gcp('nocreate'));
case 'size'
p = gcp('nocreate'); % If no pool, do not create new one.
if isempty(p)
poolsize = 0;
else
poolsize = p.NumWorkers;
end
varargout={poolsize};
otherwise %number of workers
if ~isnumeric(arg1)
arg1=num2str(arg1);
end
parpool(arg1);
end
  1 Comment
Foteini Zagklavara
Foteini Zagklavara on 1 May 2019
The suggestion of Matt J worked for me, when trying some of the MATSuMoTo examples. Thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Parallel Computing Fundamentals in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!