CasADi not available in parallel Matlab workers

268 views
Skip to first unread message

krishnakumar G

unread,
Oct 31, 2016, 3:55:10 AM10/31/16
to CasADi
Dear all,

When I try to run a CasADi code (code written in MATLAB) in parallel, using Mathworks parallel computing toolbox (PCT), I get an error message and MATLAB quits. The individual Matlab workers don't seem to be understanding CasADi syntax, even though it was imported using import casadi.* in the beginning of the main script which calls the worker processes. My basic serial code of the model works just fine. 

Is there a way to distribute the CasADi namespaces over to the parallel Matlab worker pool ? I am okay with using addAttachedFiles option, but don't wish to send over the entire contents of the CasADi install directory, since I suspect that there might be a more efficient solution. I did a quick search on StackExchange and google, before posting this question here. 

Any help is much appreciated.


Best Regards

Krishna 

Joel Andersson

unread,
Oct 31, 2016, 9:25:24 AM10/31/16
to CasADi
Hi Krishna,

Are we talking about parallelization with MPI on a distributed memory architecture? If so, you'd need to install CasADi on each computing core of course. An attractive alternative could be to generate the code once, generate a MEX-file and broadcast it to all of the cores. 

Related, I would not recommend using CasADi symbolic calculations in parallel on a shared memory architecture using e.g. OpenMP, if that's something you're considering.

Joel


krishnakumar G

unread,
Nov 1, 2016, 8:34:12 AM11/1/16
to CasADi
Hi Joel,

Hmm. I am just using MATLAB's default (a.k.a automatic parallelisation) on my 16-core machine. I don't know much about parallelism, but I think since I am using my local workstation, it must be shared memory parallelism. I have no clue what MATLAB's parallel computing toolbox uses as its underlying technology. 

Yes, the model contains symbolic variables. Has this never been done before? I am performing a computationally intensive task and would like to use all my 16-available cores. 

The script I am running repeatedly performs a numeric evaluation on a symbolic model created using casADi.  It seems highly inefficient to run this in serial mode, as I need around to run the model around 10000 times. My parallelisation works fine on all other models/scripts which don't contain any functions from the CasADi framework. 

I am using MATLAB's built-in 'parfor' as my sole parallelisation method . Any ideas on how this can be achieved ? 


Krishna 

Julian Golembiewski

unread,
Sep 21, 2021, 6:10:21 AM9/21/21
to CasADi
Hi Krishnak,

could you solve your problem in the meantime?
I am currently facing the exact same problem and struggle to find a viable solution.

Best
Julian

joaosa...@gmail.com

unread,
Sep 23, 2021, 6:30:04 AM9/23/21
to CasADi
As Joel said in previously you need to use a tool that allows "parallelism" with distributed memory.
E.g.  with threads, or openmp, or parfor you have "multiple cpu's" accessing same shunk of memory (shared memory), this is what happens in usual concurrency tools.
Since Casadi is not thread safe what you need is multiple cpu's where each one accesses their own memory (distributed memory). 
Just to simpliy, 3 cpus run on 1 memory (shared memory) , you need 3 cpu's running on 3 memory (distributed).
You can see the distributed case as having 3 computers with their own casadi instalation. 

That is why you need to use something like openMPI. Which allows distributed memory (even using your own computer) and then pass messages between the "fake computers "
I have played arround in c++ with openMPI.

An idea for you specific case would be:
1- generate c-code from your matlab code
Alternativelly there might be some MPI equivalent for Matlab (not sure)

grr

unread,
Sep 23, 2021, 9:50:45 AM9/23/21
to CasADi
Hi

Until quite recently, Matlab's parfor was entirely distributed memory, since the so-called "workers" were indeed processes, not threads; usually, only the latter share memory, while processes have distinct chunks. In the newer versions of Matlab, you have -- I believe -- a choice, but I haven't used the threading so far. Make sure you use the "classical" variant.

Best, Gregor.

Reply all
Reply to author
Forward
0 new messages