Parallel computing MatLab Comsol

Thread index  |  Previous thread  |  Next thread  |  Start a new discussion

RSS FeedRSS feed   |   Email notificationsTurn on email notifications   |   7 Replies   Last post: March 13, 2014 6:56am UTC
Anders Gudmarsson

Anders Gudmarsson

December 6, 2012 8:24am UTC

Parallel computing MatLab Comsol

Hi,

I am using Comsol 4.3 with Livelink for Matlab. I run an optimization code in Matlab where i call Comsol to perform frequency response simulations. Now i would like to start two parallel frequency response simulations that are independent of each other from my Matlab code.
My approach so far has been to open another Matlab worker by using matlabpool and parfor. However, only one of the Matlab workers are then connected to Comsol. Is it possible to perform parallel computing in Comsol when using the Matlab livelink?

//Anders

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Hamsa Dhwani

Hamsa Dhwani

January 31, 2013 3:19pm UTC in response to Anders Gudmarsson

Re: Parallel computing MatLab Comsol

Hi Anders,

Were you able to solve this problem?

Hi,

I am trying to do the following

parfor k=1:20
model2 = mphload('micromodel');
end

This should initiate several parallel comsol instances in matlab. However, I get the following error

Error using parallel function
Undefined variable "ModelUtil" or "ModelUtil.load"

However if I do this in serial:

parfor k=1:20
model2 = mphload('micromodel');
end

it works fine.

Thanks,

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Anders Gudmarsson

Anders Gudmarsson

February 5, 2013 3:14pm UTC in response to Hamsa Dhwani

Re: Parallel computing MatLab Comsol

Hi Hamsa,

Yes I managed to find a solution to this problem.

To connect the matlab workers to comsol i use the system command below to start a server for each worker. Then i use the mphstart command to connect my parallel functions to the comsol servers by specifying the ports.

comsolPort = 2036;
system( ['comsol -np 1 server -silent -port ' num2str(comsolPort) ' &'] );

mphstart( comsolPort )
import com.comsol.model.*
import com.comsol.model.util.*

I hope this will help you.

Regards,
Anders

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Hamsa Dhwani

Hamsa Dhwani

February 5, 2013 5:03pm UTC in response to Anders Gudmarsson

Re: Parallel computing MatLab Comsol

Hi Anders,

Thanks for your reply. I am able to launch comsol on the workers, however, they are not able to finish off normally. Somhow they end up crashing.

Can you tell me if you use labBarriers, LabSend and LabReceive commands to communicate from the parent process to the worker processes?

Also, would I be right in making the parent do the writing to the files etc. and just get the data from the child processes?

Thanks,

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Julian Freed-Brown

Julian Freed-Brown

February 8, 2013 5:33pm UTC in response to Anders Gudmarsson

Re: Parallel computing MatLab Comsol

Hi Anders,

I'm having the same problem you started with, but I'm not quite following how you solved it.

Could you please upload some sample code that show how you fixed the problem? I'd really appreciate it.

Thanks,
-jfb

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Anders Gudmarsson

Anders Gudmarsson

February 13, 2013 9:50am UTC in response to Julian Freed-Brown

Re: Parallel computing MatLab Comsol

Hi,

Here is a sample code of my solution to this problem.
I use the system command to start comsol and then i call my comsol functions in the parfor loop.


matlabpool open 2
comsolPort = 2036;
system( ['comsol -np 1 server -silent -port ' num2str(comsolPort) ' &'] );
pause( 6 )

comsolPort = 2037;
system( ['comsol -np 1 server -silent -port ' num2str(comsolPort) ' &'] );
pause( 6 )

parfor i = 1:2
if i == 1
y_acc_amp_final{i}=Torsion(dataT,f_range);
else
x_acc_amp_final{i}=Long(dataT,f_range);
end
end

matlabpool close


In my comsol functions i use the mphstart command to connect the functions to the opened comsol ports.


cd('C:\Program Files\COMSOL43\mli')
mphstart(2036)


I hope this may be helpful.

Regards,
Anders

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Julian Freed-Brown

Julian Freed-Brown

February 13, 2013 6:00pm UTC in response to Anders Gudmarsson

Re: Parallel computing MatLab Comsol

Hi,

Thanks so much for your help! I got it working.

Thanks again,
-jfb

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Michael Mrejen

Michael Mrejen

March 13, 2014 6:56am UTC in response to Julian Freed-Brown

Re: Parallel computing MatLab Comsol

Hi,

I'm trying to implement the solution suggested here.
I'm able to get the different servers up and connect them to the workers but I'm now stuck when I try to use mphload (in order load my model).
Should I load my model in the parent process or should I load it for each worker?
if so how can I specify to which server mphload should load the model?
Your help is appreciated in advance!

Thanks

Michael

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse


Rules and guidelines