Multiple Models and Communication

Discussions involving programming in ExtendSim.
Post Reply
kimmamula
Posts:21
Joined:Thu Apr 07, 2016 5:09 am
First Name:Kim
Multiple Models and Communication

Post by kimmamula » Wed May 09, 2018 6:47 am

I am trying to set up an ExtendSim model that will initiate another ExtendSim model to open, run and communicate with it. I need items to pass from the 1st model to the second and back to the 1st to finish up. In the User Guide, it says models can run simultaneously and can communicate with each other. I do not see where it discusses how to communicate. I used the OpenExtendFile(path) in the 1st model to open the 2nd model, but I get an error "Cannot call RunSimulation function during a simulation". So, I started with having both models open. I am able to get the 1st model to run the 2nd by using ActivateWorksheet and ExecuteMenuCommand(6000). But, it pauses the 1st model and waits for that 2nd model to complete running before it goes back to the 1st to finish running it. I saw the FAQs regarding IPC and using the IPCServerAsync(True) function and tried adding that to the equation blocks where I call ExecuteMenuCommand(6000) in the 1st model. Didn't work either - it still waits for that 2nd model to stop running before it continues the 1st. I wonder if it is because I am not using a different application - both models are ExtendSim apps (IPC only good if using ExtendSim app plus a non-ExtendSim app?). I need them to run simultaneously, passing items and information from one to the other.

Also, I can not find how to make them communicate. I looked all over in documentation, developer references, website, and even youtube channel.

Can this (two communicating models running simultaneously) be done, or is this beyond ExtendSim's capabilities?

ceciledamiron
Posts:60
Joined:Wed Jul 02, 2008 12:10 pm
First Name:Cecile
Last Name:Damiron

Re: Multiple Models and Communication

Post by ceciledamiron » Thu May 10, 2018 8:54 am

Hello,

You can achieve what you want with ExtendSim but it will be a lot of work and it will not be very efficient in term of speed execution. You have to see if a solution with one single model would not be better at solving your problem.

-There is no built in mechanism to have an item going from one model to another so you will have to build a way of doing it. It maybe using databases, text files, excel or custom code blocks.
-You can look at the examples shipped with ExtendSim: C:\ExtendSim9\Examples\Developer Tips Mailslot Receive.mox and Mailslot Send.mox that might help you
-I'm going to ask if Peter can join the discussion as he has a lot of experience on remote launching models.

Cecile

kimmamula
Posts:21
Joined:Thu Apr 07, 2016 5:09 am
First Name:Kim

Re: Multiple Models and Communication

Post by kimmamula » Wed Jun 27, 2018 3:46 am

I looked into the Mailslot method, but after reading through it and looking at examples, I realized it is Windows only. I would need something supported by both Windows and Mac.

The model I have built is already 34MB, and I will be adding a lot more. So if I could have two separate models that can communicate and share data, that is ideal. All would start in first model which has resource pools and a lot of its own activity, but then that would initiate second model. Some items stay in first and others are passed to second for activities and then passed back to first. I do not see a way of doing this based on the documentation but want to make sure I am not missing something. I can get one model to call the other, but it just pauses that first model then. I need them to work simultaneously, modeling 2 simultaneous processes.

davek
Posts:75
Joined:Thu Apr 27, 2000 12:00 am
First Name:Dave
Last Name:Krahl

Re: Multiple Models and Communication

Post by davek » Wed Jun 27, 2018 1:29 pm

Kim,

I don't think that having two models communicate with each other will achieve what you want. For one thing, you can only have one instance of ExtendSim running on a computer at a time. Also, even if you were able to run two instances of ExtendSim on the same computer, the overhead for moving items from one to another and synchronizing the clock would be significant, much more than working within a single model. FYI there are a pair of blocks in the Custom Blocks library (in the libraries\example libraries folder) that will send an item from one model on one computer to a model on another computer.

You might want to consider organizing your model hierarchically with each process in a different hierarchical block. We work with models that are 20x the size of what you have developed so far. The practical limit seems to be around 800MB.

Are there other reasons why you would want to divide the model up other than performance and size?

Dave

kimmamula
Posts:21
Joined:Thu Apr 07, 2016 5:09 am
First Name:Kim

Re: Multiple Models and Communication

Post by kimmamula » Thu Jun 28, 2018 3:29 am

No - no other reason than performance and size. Building H-Blocks does not reduce size does it? I have a number of those in there now to keep things neat and organized. I thought that was their only purpose.

Sounds like I will keep it to one model. Thanks for the feedback!

davek
Posts:75
Joined:Thu Apr 27, 2000 12:00 am
First Name:Dave
Last Name:Krahl

Re: Multiple Models and Communication

Post by davek » Thu Jun 28, 2018 8:30 am

No, hierarchical blocks do not reduce the size of the model. If you are concerned about size there is a block called "Model Size" in the Utilities library that reports the size of every block in the model. You may be able to use this information to reduce the memory footprint. The RealTimer block (also in the Utilities library) reports how much time every block requires during the simulation. This can help identify performance issues.

Should size or performance really become a problem, we have had quite a bit of success improving these. In one case, I was able to speed up a model by a factor of 20.

Dave

Post Reply