This simple example shows code that is the basis for some of the most powerful and complex message passing programs. The master/slave example is particularly appropriate for irregular task decomposition, load balancing tasks that take an unpredictable amount of time, and for handling irregular data structures.

In the solution here, the server allows any process to send an ordered output message. An alternative approach is to allow only slave 0 to send a request to perform ordered output. Then the master can send a message to either slave 0 or to each slave, informing them that they can send the ordered output message.

You can implement this alternate approach by using the ring communication within the slaves to indicate which slave can send an ordered message next.