Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.
MATLAB parfor and Comsol server
Posted Jun 29, 2014, 8:37 a.m. EDT Interfacing, LiveLink for MATLAB Version 4.4, Version 5.1 7 Replies
Please login with a confirmed email address before reporting spam
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
7 Replies Last Post Aug 1, 2017, 5:03 a.m. EDT