Running six instances of Matlab, 3 pairs of two instances. Need to Share Data between pairs.

12 views (last 30 days)
I have six instances of Matlab running on my PC, instance A to F.
Matlab A needs to pass data to Matlab B. Matlab C to D. Matlab E to F.
I have been using shared folders and fileatrib to determine when safe to read data, but Matlab on the read side runs into load errors every so often.
I have Data in Matlab A been calulated and passed to a GUI in Matlab B. May be a better solution then saving and reading file in shared folder.
Looked at TCP/IP, but with 3 sets of Matlab, communications don't seem feasible.
Open to suggestions and a point in the right direction !
Joe

Answers (2)

Walter Roberson
Walter Roberson on 7 Jan 2017
TCP should be fine; you just have to configure appropriate ports. IP address would be 127.0.0.1 and you would need one of the pair to be Server and the other to be Client.
You could also consider shared matrix or you could memmapfile
Synchronization on shared files is often a challenge: how does the other instance know when the data is ready?
You can use a scheme such as this:
Reserve the first shared location as either 32 bit or 64 bit integer. Initialize to 0. After that, allocate two blocks of memory of the same size in the file, each the maximum size of data to share.
Now, the sending system should prepare the first batch of data to be shared, writing it into the first of the two blocks. After it is completely finished, it should increment the shared counter in the fixed location. And then it should start writing data into the second of the two blocks. When it finally finishes, it should increment the counter again, and switch back to writing into the first block. Keep repeating.
On the receiving side, periodically check the counter. If it has changed since you last checked, then new data is ready. If the counter is odd, then read the data out of the first of the two blocks; if it is even, read the data out of the second of the two blocks.
This procedure will work as long as the receiving system can finish reading the data before the sending system can finish writing the next block. If that is not the case, then the way of dealing with it depends upon whether that is an occasional short problem (e.g., maybe a write that normally works gets delayed because of virus checking) or whether it is a persistent risk, and depends on whether the receive absolutely needs to process every output block or only needs to process the most recent information.

Joseph
Joseph on 7 Jan 2017
Thank you for the suggestions. I will look at these definetly !
I have the timing part sorted. So that should not be a problem. There is a big delay between reads.
Thanks for the help !

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!