At each host process, the simulation protocol is executed by the scheduler. Each thread, upon getting blocked, immediately calls the scheduler, which performs a number of actions, and then switches in the next runnable thread. The scheduler is different for the sequential (one host process only) and the parallel (more than one host processes) simulators.
The pseudocode for the scheduler in the parallel simulator is shown in Figure 5.1. The first step taken by the scheduler is to determine the current thread's simulation status, and match its request list with arrived messages. If it is in non-deterministic mode, only safe messages can be matched. The thread's execution status and simulation time are updated whenever message matching is performed. The scheduler then checks for arrived off-processor messages. Off-processor messages could be protocol messages, containing EOTs and ECOTs of threads on other processors, or data messages or acknowledgements. Acknowledgements are matched immediately with the request list of the thread they are sent to. If the thread they are sent to is in deterministic mode, data messages are immediately matched with the thread's request list. If not, the messages are queued up at their respective communicators, since their send timestamp must be greater than the message EIT on the communicator. Only when the arrived protocol messages are processed can the EIT at each communicator increase. Increasing EIT reveals new messages, which are immediately matched with the request list of the thread they are intended for.
The scheduler switches on the simulation protocol at its host process upon either receiving a protocol message from another process (which it determines in CollectAndProcessOffProcessorMessages), or if a local thread is blocked in non-deterministic mode. When the protocol gets switched on, the EOTs and ECOTs of all local LPs on all local communicators are calculated, and packaged into a single protocol message, and a copy of the protocol message sent to all other processors. If the simulation protocol is already switched on, and a complete round of protocol messages has already been received, the scheduler can make a decision whether to switch off the simulation protocol. It does this only if there are not any local threads in non-deterministic mode. Otherwise, it sends out another round of protocol messages. The scheduler then looks for another runnable thread. If none is found, and the simulation has not terminated or deadlocked, it repeats the loop shown in the figure. Otherwise, it swaps in the next thread.
Figure 5.1: Scheduler Pseudo Code for Parallel Simulator
The scheduler for the sequential simulator is similar but a little simpler, since it does not need to wait for off-processor messages. It is shown in Figure 5.2. Whenever there is a thread in non-deterministic mode, EOTs and ECOTs are calculated for all threads. Subsequently, the EIT on all communicators is computed and advanced, revealing new safe messages which are matched with the request list of the threads they are intended for.
Figure 5.2: Scheduler Pseudo Code for Sequential Simulator