How can I save a large file asynchronously?
10 views (last 30 days)
Show older comments
I'm working with a MATLAB GUI that streams in, displays, and records data from a number of different sources. Because of how many different data sources I'm working with, the main MATLAB thread is up to 80% occupied with streaming in and displaying the data. Thus, when I go to save a recording, the save() operation blocks the MATLAB thread and bogs down the data streaming.
Is there a way to write a file to disk asynchronously? I thought I could do this with the parallel computing toolbox by offloading the job to another worker. However, it appears that PCT transfers the data other workers by saving the input variables to disk. I've searched for several hours to find another solution, but have not been able to find anything promising.
Suggestions anyone?
Below I've listed my failed attempts:
I thought I might be able to open a MATLAB session to run in the background for whenever I need to save a recording, using the MATLAB engine API for Java. Unfortunately, java throws an error saying "Initializing MATLAB Engine API from MATLAB is not supported."
I could have another MATLAB session open and use TCP/IP to pass the data in (after first serializing it using getByteStreamFromArray, and then deserializing it on the other end). I've proved that data can in fact be passed from one MATLAB session to another this way, and fwrite for the tcpip class can be asynchronous, so this seems like it would be faster than saving to disk. However, I don't want this other session of MATLAB to be visible to the user. Anyone know how to launch a session of MATLAB in the background, keep it open indefinitely, and then close it on command?
I even considered passing my data from one MATLAB session to the other using setenv and getenv (also using serializing and deserializing). I think this approach failed because many of the serialized uint8 values convert to illegal characters using char, or possibly because environment variables have a size limit I'm not aware of.
_____________________________________________
UPDATE:
I have proved that I can open a second session of MATLAB, open a TCP/IP connection between the two sessions, and pass commands and data from one to the other, then notify the when the command is complete. I have even proved that this method can be faster, provided the file is sufficiently large.
However, I cannot find a way to make the other session of MATLAB operate completely invisible to the user. The flag '-nodesktop' still launches a stripped-down command window (I'm working with Windows 10). '-nodisplay' seems to either have no effect or be explicitly rejected as an option depending on what other options I try to use.
Anyone know how to get a completely invisible MATLAB session on Windows?
1 Comment
Walter Roberson
on 26 Sep 2018
I think PCT serializes in memory and transmits using MPI (Message Passing Interface), but the situation might be different for MS Windows.
Answers (1)
Noah Jaxon
on 26 Sep 2018
I'm sure you've solved this by now, but the flag you're looking for is "-minimize".
2 Comments
Walter Roberson
on 26 Sep 2018
It sounds as if you are using MS Windows. I wonder if it would help to use the Windows "start" command?
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!