Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.
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.
Parallel computing MatLab Comsol
Posted 2012年12月6日 GMT-5 03:24 Interfacing, Structural Mechanics Version 4.3, Version 4.3a, Version 4.3b 12 Replies
Please login with a confirmed email address before reporting spam
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
Hello Anders Gudmarsson
Your Discussion has gone 30 days without a reply. If you still need help with COMSOL and have an on-subscription license, please visit our Support Center for help.
If you do not hold an on-subscription license, you may find an answer in another Discussion or in the Knowledge Base.
Please login with a confirmed email address before reporting spam
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,
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
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,
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
Thanks so much for your help! I got it working.
Thanks again,
-jfb
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
I had problems inside MATLAB's parfor loop.
parfor idx = 1:2
import com.comsol.model.*
import com.comsol.model.util.*
model = ModelUtil.create('Model');
end
Error: MATLAB cannot determine whether "ModelUtil" refers to a function or variable.
See Parallel for Loops in MATLAB, "Unambiguous Variable Names".
Could you please kindly advise how you solved this?
Best regards, and thanks in advance!
Alvin
Please login with a confirmed email address before reporting spam
Did you solve the problem? I have exactly the same problem.
Error: MATLAB cannot determine whether "ModelUtil" refers to a function or variable.
See Parallel for Loops in MATLAB, "Unambiguous Variable Names".
Could you please kindly help?? Really desperate.
Thanks a lot
Alvin
Please login with a confirmed email address before reporting spam
I'm trying to use Comsol with the optimization tool from Matlab to estimate some parameters of my Comsol model using genetic algorithms. Could you please, give me some tips how to do it? I'm not trying to do parallel processing, it's just the first part of your text, which I think you are dealing well with that, right?
Could you please help me with that?
Thank you.
Marco
Please login with a confirmed email address before reporting spam
Is your problem solved? I am in exactly the same situation as you.
Regards
Jia
Please login with a confirmed email address before reporting spam
Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.