LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running Matlab Scripts in Parallel

I have several MATLAB scripts running in my LabVIEW VI via MATLAB script nodes, and one of them in particular slows by program down considerably.  It dawned on me that I could just take the slowest commands in the script, place them in a script node running a separate VI, and run the two VIs in parallel.  It seems it doesn't work that way, though - my main program runs a little faster than it did before, but I only get a major speed increase when I stop the second VI.

I realized a long time ago that two VIs running in parallel share the same MATLAB environment and can even address the same variables, but it never occurred to me that I couldn't actually run two MATLAB scripts at the same time - and that seems to be the case.

What would be the best way around this limitation?  Is there some way I can force the two VIs to use separate MATLAB environments?  (There's plenty of resouces available on the computer, so I'm not particularly worried about inefficiency.)  Would compiling the VIs or compiling the scripts somehow help?
0 Kudos
Message 1 of 6
(5,041 Views)
kehander,

To my knowledge, there is not a way to select a specific MATLAB environment to run a MATLAB Script Node on.  One way you could get around this is to create DLL's from the MATLAB scripts you have and then call them in LabVIEW.  This does not require the MATLAB environment to be open when they are called.  Hope this helps!

Brian T
Applications Engineer
0 Kudos
Message 2 of 6
(5,014 Views)
I see...

Perhaps I should start another thread for this, but is there perhaps a way to write a C wrapper for the Java functions I am calling with this script, which I could then access with a CLN?  That would work too.
0 Kudos
Message 3 of 6
(5,003 Views)
There should be, but it's not at all trivial to integrate Java code in a C runtime environment. You might Google Java Native Interface for more info.
Jarrod S.
National Instruments
0 Kudos
Message 4 of 6
(4,997 Views)
What is your LabVIEW version. How complicated is the matlab code? Would it be easy to rewrite it in plain LabVIEW?
 
Have you tried to see if it runs in mathscript instead?
( I am not sure about performance comparisons and I also don't know if mathscript can run in parallel.).
 
How many CPU cores do you have?
0 Kudos
Message 5 of 6
(4,993 Views)
Yes, it does occur to me that I could run part of the code via a Mathscript node instead of a MATLB script node.  I'm going to have to come up with a better way of exchaging the relevant data between the two, though.

This is indeed a Core 2 system with two CPU cores
0 Kudos
Message 6 of 6
(4,989 Views)