0
$\begingroup$

I have to use MATLINK to connect to MATLAB to run some programs. Variables can be get using MGet and assigned to a variable using MSet. However, I want to use ParallelMap (and other parallel functions) to set and get the variables from MATLINK. One way suggested here installs the mathlink into all parallel kernels. I tried to do the same with MATLINK and installed mengine into all parallel kernels using ParallelEvaluate[Install["mengine"]]. It created link objects. Now when I try to run ParallelMap, it is not working. The output is Not connected to the MATLAB engine.

How can I use MATLINK in parallel kernels?

$\endgroup$
  • $\begingroup$ MATLink is not MathLink. Don't try to mess with the internals of MATLink by using Install directly. You simply need to load the package on all parallel kernels (ParallelNeeds) and start a MATLAB session from each (ParallelEvaluate[OpenMATLAB[]]). These will be distinct MATLAB sessions that do not share any variables. $\endgroup$ – Szabolcs May 5 '18 at 9:14
  • $\begingroup$ @Szabolcs Is there any way to share the variables to parallel kernels? $\endgroup$ – no-one May 7 '18 at 16:18
  • $\begingroup$ What are you trying to do exactly? Why do you think you need parallelization? If all parallel kernels could connect to the same MATLAB instance (which they cannot) then the code that runs in MATLAB would not run in parallel. Maybe you want to parallelize MATLAB code purely in MATLAB. I don't really understand what you are trying to do. $\endgroup$ – Szabolcs May 7 '18 at 17:38
  • $\begingroup$ There is a MATLAB code (MATPOWER load flow) I am trying to run using Mathematica. I have to send some variables from Mathematica and run the Matlab code and get processed data from Matlab to Mathematica. I have to run code in matlab then get the data and again do some computations in mathematica. I have to do the above process thousads of times. That is why I am exploring parallel computing options $\endgroup$ – no-one May 7 '18 at 18:04
  • $\begingroup$ OK, but that does not explain why you want to share the MATLAB workspace between parallel instances. $\endgroup$ – Szabolcs May 7 '18 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.