How to replace matlapool by parpool in my code ?

조회 수: 11 (최근 30일)
Momo76800
Momo76800 2015년 8월 23일
댓글: Foteini Zagklavara 2019년 5월 1일
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.

채택된 답변

Matt J
Matt J 2015년 8월 23일
편집: Matt J 2015년 8월 24일
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
Foteini Zagklavara
Foteini Zagklavara 2019년 5월 1일
The suggestion of Matt J worked for me, when trying some of the MATSuMoTo examples. Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by