Ordering events in Sparta is one of the key features Sparta has over other simulation frameworks. Being able to indicate that a modeler requires one event to be scheduled/fired before another is not only handy, but critical to a deterministic model. Sparta enables ordering through precedence operations, documented here.
Sparta main precedence operator is the C++ operator>>
and are documented in namespace sparta. An example of setting precedence between two events:
event1 >> event2;
Event is a simple class for scheduling random events on the Scheduler.
This code will guarantee that event1
will always be scheduled and fired before event2
in simulation, not matter which event is scheduled first. However, if event2
attempts to schedule event1
on the same cycle, the framework will throw an exception:
void MyUnit::event2Handler()
{
event1.schedule(sparta::Clock::Cycle(0));
}
void MyUnit::event1Handler()
{
event2.schedule(sparta::Clock::Cycle(0));
}
This, however, is ok to do:
void MyUnit::event2Handler()
{
event1.schedule(sparta::Clock::Cycle(1));
}
Some combinations:
concrete_event >> concrete_event;
event_pointer >> concrete_event;
concrete_event >> event_pointer;
event_pointer >> event_pointer;
std::unique_ptr<eventT> >> std::unique_ptr<eventT>;
std::unique_ptr<eventT> >> concrete_event;
std::unique_ptr<eventT> >> event_pointer;
concrete_event >> std::unique_ptr<eventT>;
event_pointer >> std::unique_ptr<eventT>;
gop >> concrete_event;
gop >> event_pointer;
gop >> std::unique_ptr<eventT>;
concrete_event >> gop;
event_pointer >> gop;
std::unique_ptr<eventT> >> gop;
Used to set precedence between Scheduleable types across simulation.