How to replace matlapool by parpool in my code ?

2 ビュー (過去 30 日間)
Momo76800
Momo76800 2015 年 8 月 23 日
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 Center および File ExchangeParallel Computing Fundamentals についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by