How to replace matlapool by parpool in my code ?

10 vues (au cours des 30 derniers jours)
Momo76800
Momo76800 le 23 Août 2015
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.

Réponse acceptée

Matt J
Matt J le 23 Août 2015
Modifié(e) : Matt J le 24 Août 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 commentaire
Foteini Zagklavara
Foteini Zagklavara le 1 Mai 2019
The suggestion of Matt J worked for me, when trying some of the MATSuMoTo examples. Thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Parallel Computing Fundamentals dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by