How to replace matlapool by parpool in my code ?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Momo76800
am 23 Aug. 2015
Kommentiert: Foteini Zagklavara
am 1 Mai 2019
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.
0 Kommentare
Akzeptierte Antwort
Matt J
am 23 Aug. 2015
Bearbeitet: Matt J
am 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 Kommentar
Foteini Zagklavara
am 1 Mai 2019
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Parallel Computing Fundamentals finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!