Hi,
I want to speed up my computations using the parfor loop in MATLAB (from Parallel Computing Toolbox). I run this on a Linux machine. My code so far:
system('killall -9 comsollauncher java'); % kill previous running Comsol server instances to prevent port assignment problems
pool = parpool('local',2); % open local pool with two Workers
parfor i=1:5 % set this to 2 iterations (=number of workers in pool) and it will work
comsolPort = 2036+i; % set unique port
system( ['comsol -np 1 server -port ',num2str(comsolPort), ' &'] ); % start a Comsol server
pause( 6 ) % give Comsol server time to start up
testfun(comsolPort) % function connects to the given Comsol server using mphstart(comsolPort), does some Comsol stuff and later disconnects
end
delete(pool); %close pool
Using 2 workers the code works if parfor makes only 2 iterations. But if there are more iterations mphstart() cannot connect to the given Comsol server throwing:
"Error using mphstart (line 152) A connection to Comsol could not be established. Please check that a Comsol Server is started prior to calling mphstart"
although a new server is definitely running on the given port. This might be related to how the MATLAB job scheduler works. But I have no idea why and how to fix this. Having only as many parfor iterations as workers in the pool is not optimal, because I have to run far more cases than there are CPUs/workers on my machine. Do you have any suggestions how to make this work?
Thank you and best regards,
Chris
I want to speed up my computations using the parfor loop in MATLAB (from Parallel Computing Toolbox). I run this on a Linux machine. My code so far:
system('killall -9 comsollauncher java'); % kill previous running Comsol server instances to prevent port assignment problems
pool = parpool('local',2); % open local pool with two Workers
parfor i=1:5 % set this to 2 iterations (=number of workers in pool) and it will work
comsolPort = 2036+i; % set unique port
system( ['comsol -np 1 server -port ',num2str(comsolPort), ' &'] ); % start a Comsol server
pause( 6 ) % give Comsol server time to start up
testfun(comsolPort) % function connects to the given Comsol server using mphstart(comsolPort), does some Comsol stuff and later disconnects
end
delete(pool); %close pool
Using 2 workers the code works if parfor makes only 2 iterations. But if there are more iterations mphstart() cannot connect to the given Comsol server throwing:
"Error using mphstart (line 152) A connection to Comsol could not be established. Please check that a Comsol Server is started prior to calling mphstart"
although a new server is definitely running on the given port. This might be related to how the MATLAB job scheduler works. But I have no idea why and how to fix this. Having only as many parfor iterations as workers in the pool is not optimal, because I have to run far more cases than there are CPUs/workers on my machine. Do you have any suggestions how to make this work?
Thank you and best regards,
Chris