Parallel Simulation
The parallel simulation kernel can provide significant speed improvements by executing radio transmission calculations concurrently. This section describes parallel processing in wireless simulations and how to safely program wireless models for parallel execution. For additional information about implementing parallel simulations, see “Parallel Simulation” on page 400.
Radio Pipeline Stages
A radio transmission involves only five stages of the Radio Transceiver Pipeline: transmission delay, closure, channel match, tx antenna gain, and propagation delay. The other pipeline stages are invoked for the reception of a packet by another node. In a sequential simulation (Figure 43), the Simulation Kernel fully processes one packet through these five stages, then moves on to another packet. There is one start of transmission event.
Figure 43: Sequential Execution of Radio Transceiver Pipeline (Stages 1–5)

As shown in Figure 44, the parallel simulation kernel performs most of these five stages in the radio receivers (as opposed to the transmitters). Within each transmission, the transmission delay stage is computed once (it is not part of the parallel portion of the transmission). After the transmission delay has been computed, a copy of the outbound packet is made for each potential recipient, a receiver transmission event is scheduled for each copy, and each copy is processed by the remaining four stages. Thus, for each radio transmission, an additional event is scheduled for each receiver in the transmitter’s receiver group.
Figure 44: Parallel Execution of Radio Transceiver Pipeline (Stages 1–5)

Riverbed Modeler uses the split_start_radio_transmission simulation preference to determine whether stages 2–5 of the Radio Transceiver Pipeline are calculated in parallel (which will generate more events) or sequentially. The default value of this simulation preference is TRUE for the parallel kernel and FALSE for the sequential kernel.
When split_start_radio_transmission is TRUE, the processing of packets is performed by several threads of computation, where each thread handles the processing of a subset of the transmitted packets. The number of threads of computation is specified by the parallel_sim.num_processors preference. Unless the pipeline stages involve intense I/O activity (such as searching through databases), you typically should not use more threads than physical CPUs available, as this can result in reduced performance.
As a debugging aid, you can set the split_start_radio_transmission preference to TRUE in the sequential kernel. This will ensure the same sequence of events for both parallel and sequential execution, allowing you to match the event counts in both cases more closely. A setting of TRUE provides better performance in the parallel kernel but, conversely, is slower in the sequential kernel.
Code Design for Multi-Threading-Safety
To ensure that the parallel transmission of packets is performed correctly and as quickly as possible, you must ensure that all pipeline stages involved are multi-threading safe. This means that the code is designed in such a way that one of the following situations is true:
- Several threads can execute it at the same time, in which case the code is considered reentrant.
- At most one thread executes the code using a serialization mechanism: the mutex (mutual exclusion) approach.
- A combination of the first two points is used, such that some parts are reentrant while others are serialized.
Safe code is code that uses only MT-safe KPs and that is self-contained, meaning it uses only elements that are accessible or visible to the thread. Such elements include the local variables declared inside a function (because each invocation of the function uses a different set of these variables) and the arguments of a function (provided that these arguments are either copies of global data or, in the case of pointers, it is known that no other threads will be modifying the values referenced by these pointers).
In the case of pipeline stages, the packet pointer provided by the Simulation Kernel references a copy of the packet being sent. This copy is used only by the thread processing it. Thus, a pipeline stage is reentrant if its computation involves only the packet and local variables.
However, if code accesses global variables, shared files, and other elements that might be used by multiple threads concurrently, you must be much more careful to ensure that the correct values are obtained. As a general rule, concurrent access is not problematic as long as only reading is involved. If any form of writing is required (such as increasing a counter or moving a file offset), then it is safer to assume that concurrent access should not be allowed. In this case, mutual exclusion locks (mutexes) can be used to ensure serialized access to information. See “Mutex Sub-Package” on page 5 for a description of the KPs that can be used to implement mutexes.