Quantcast
Channel: Latest Discussions - COMSOL Forums
Viewing all articles
Browse latest Browse all 26527

Parallel Computing with MATLAB Livelink and COMSOL

$
0
0
Hi everyone,
I am currently trying to use Matlab's Global Optimization tool (specifically using genetic algorithms) with my function. Every time my function evaluates, it loads a model file, modifies some parameters in it, does the calculation and sends it back to the Matlab program. In order to speed up this process, I intend to parallelize my code. The Matlab part of this is easy, as I simply have to start a pool of MATLAB workers and turn the parallelization option in the optimization tool. However, for the COMSOL part, I think that I need an independent COMSOL server for every worker/core. How does one go about doing this?

I have tried the solution outlined in this thread (www.comsol.com/community/forums/general/thread/33446/). Specifically what I tried to do was write the following code to initialize multiple COMSOL servers:

matlabpool open 3
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 )

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

Then after this I start the Matlab genetic algorithm, which calls upon my function.

Within my function, I add an mphstart(portno), with the portno depending on the MATLAB worker ID.

What happens when I run this code is that at first three COMSOL servers seem to come up (with three splash screens etc.). Initially each worker seems to be able to start accessing the model. However after a few seconds (while the workers are modifying the model) the COMSOL servers shut down and only one worker is left doing its job. What is the cause of this? Is it that COMSOL doesn't allow more than one server operating?

On the other hand, when I tried to make all workers simply connect to the same COMSOL server, a "java.lang.NullPointerException" occurs, which led me to believe that I need three independent servers.

If anyone has any pointers on how to execute this task (running a parallel operation on MATLAB livelink where each worker has access to a COMSOL server, or perhaps do this without needing multiple COMSOL servers), that would be great!

Thanks in advance for any help given.

Viewing all articles
Browse latest Browse all 26527

Trending Articles