Home → Developer Docs → Master-Slave |
---|
Master/Slave synchronization is an optional class when running simulations.
Master/Slave synchronization synchronizes a master simulation to one or more slave simulations. While synchronized, the master controls the overall simulation mode as well as the current simulation time for all simulations. The set of simulations may change mode if one of the simulations in the set freezes or exits unexpectedly.
Master/Slave syncrhonization uses the Trick::MSConnect class for communications. The MSConnect class is an abstract base class that defines functions for connecting the simulations together and passing the simulation mode and simulation time between simulations. The Trick::MSSocket class derives from the Trick::MSConnect class, and uses sockets as the transport medium for master/slave communications.
The master simulation starts slave simulations during initialization. At the end of each software frame during Run mode and at the end of each freeze frame during Freeze mode the master reads the mode of all connected slave simulations. The master will determine the mode of the simulations for the next frame according to the slave modes and the master mode. The new mode and the current simulation time is sent to the slaves.
Master/Slave synchronization is divided into code based on the mode of the simulation. The modes are Initialization, Run, Freeze, and Shutdown.
Master/Slave functions are designed to be called from the S_define file.
Listed below are the various modes of operation and the Master responsibilities within each.
During Initialization slave connections are allocated and defined. Default values to start each slave using ssh are set when a slave connection is allocated. At the mimimum a slave must define a remote machine, the path to the simulation executive, and a Trick::MSConnect class to use for communications with the slave. Users may also define the remote shell to use, a simulation executable name, a remote run directory, and additional user arguments to pass to the slave. The allocation and definition of the slave connections are typically done through Trick's input processor, but may also be done in default_data or initialization jobs.
At the end of the scheduler initialization phase the master starts the slaves. For each slave the master creates a slave startup command and executes the slave startup command. This is how the slave startup command is created:
The master sends its software frame to each slave.
During Run mode the master reads the simulation mode of each slave. The master determines the new simulation mode and sends the new mode and the current simulation time to the slaves.
After gathering the simulation command from all of the slaves, send the command to all of the slaves.
Upon entering freeze mode the master turns off sync_time_limit because while in freeze, master/slave communications may not be regular and periodic.
At the end of each freeze frame call Trick::Master::end_of_frame() to perform the same synchronization as in run mode.
When exiting freeze mode the master sets sync_time_limit back to the user set value ready for running again.
The master tells the slaves that it is shutting down.
At the end of each software frame during Run mode and at the end of each freeze frame during Freeze mode slave simulations send the master the current mode of the slave. The slaves wait for the new mode and simulation time from the master.
The Trick::Slave class is enabled by calling the MSConnect::process_sim_args() routine. If the MSConnect::process_sim_args() finds command line arguments specifying this simulation is a slave, then the Trick::Slave is enabled.
At the end of the scheduler initialization phase the slave connects to the master.
In Run mode the slave writes its next executive command to the master. The master will return the overall next simulation mode to the slave. The slave will also read the current simulation time from the master.
Upon entering freeze mode the slave turns off sync_time_limit because while in freeze, master/slave communications may not be regular and periodic.
At the end of each freeze frame call Trick::Slave::end_of_frame() to perform the same synchronization as in run mode.
When exiting freeze mode the slave sets sync_time_limit back to the user set value ready for running again.
If a slave is shutting down, inform the master that it is exiting. [@anchor d_slave_shutdown_0 d_slave_shutdown_0]