Ping-Pong Example

In this example, we use the Channel frontend to exchange tokens between exactly two processes, both collectively creating two fixed-size SPSC Channels (see Channels: Fixed-Size SPSC). The ping channel of a consumer pings a message to a consumer, who echoes the message back to the producer via a pong channel.

Three arguments are required for the example:

  • The channel capacity

  • The number of repetitions of a ping-pong between the producer and consumer

  • The size (in bytes) of a single token being ping-ponged

For example:

  • mpirun -n 2 ./mpi 5 10 256 launches the examples to create 2 channels of capacity 5 tokens each, each token being 256 bytes large. The ping-pong is repeated 10 times.

The output shows the benchmarked execution time of the ping-pong itself at the producer:

Time: 0.012845 seconds

This example is implemented with two backends:

  • include/producer.hpp contains the semantics for the producer(s)

  • include/consumer.hpp contains the semantics for the consumer

  • source/ contains variants of the main program implemented under different backends

    • lpf.cpp corresponds to the LPF backend implementation

    • mpi.cpp corresponds to the MPI backend implementation