how to increase the number of workers to 32 for parfor loop

37 次查看(过去 30 天)
I am trying to increase the number of workers (cores) for parfor loop in Matalb, but after running the code the number of cores was limited to 12
parfor (i=1:size(data,2),32)
filename=[surfacename,num2str(sub),var,num2str(file_no(i)),'.raw'];
fullname=fullfile(Dir,filename);
fid = fopen(fullname,'rb'); % rb = read binary
NN=N*10;
data2 = fread(fid,NN,'single');
fclose(fid);
start=8;
data2=data2(start:length(data2));
len=length(data2)/no_variables;
if opt==1 ||opt==6;
data(:,i)=data2(1:len);
elseif opt==2;
data(:,i)=data2(len+1:2*len);
elseif opt==3;
data(:,i)=data2(2*len+1:3*len);
elseif opt==4;
data(:,i)=data2(3*len+1:4*len);
elseif opt==5;
data(:,i)=data2(4*len+1:5*len);
elseif opt==7;
F = scatteredInterpolant(x,y,z,data2(1:len),'linear','linear');
data_int=F(xq,yq,zq);
data_int_2= reshape(data_int,[],1);
data(:,i)=data_int_2;
elseif opt==8;
F = scatteredInterpolant(x,y,z,data2(len+1:2*len),'linear','linear');
data_int=F(xq,yq,zq);
data_int_2= reshape(data_int,[],1);
data(:,i)=data_int_2;
elseif opt==9;
F = scatteredInterpolant(x,y,z,data2(2*len+1:3*len),'linear','linear');
data_int=F(xq,yq,zq);
data_int_2= reshape(data_int,[],1);
data(:,i)=data_int_2;
elseif opt==10;
F = scatteredInterpolant(x,y,z,data2(3*len+1:4*len),'linear','linear');
data_int=F(xq,yq,zq);
data_int_2= reshape(data_int,[],1);
data(:,i)=data_int_2;
elseif opt==11;
F = scatteredInterpolant(x,y,z,data2(4*len+1:5*len),'linear','linear');
data_int=F(xq,yq,zq);
data_int_2= reshape(data_int,[],1);
data(:,i)=data_int_2;
end
if mod(i,500) == 0
fprintf('flie read %d...\n',i);
tt=toc/60
end
name=[name,i];
end
The output showed that the number of workers are only 12.Is there any method to increase them?

回答(1 个)

Raymond Norris
Raymond Norris 2022-4-10
Are you explicitly calling parpool?
parpool(32);
Alternatively, you can change the default by going to the Parallel preferences and changing Preferred number of workers in a parallel pool

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by