Copyright 1998-2001, University of Notre Dame.
Authors: Jeffrey M. Squyres and Arun Rodrigues with Brian Barrett,
         Kinis L. Meyer, M. D. McNally, and Andrew Lumsdaine

This file is part of the Notre Dame LAM implementation of MPI.

You should have received a copy of the License Agreement for the Notre
Dame LAM implementation of MPI along with the software; see the file
LICENSE.  If not, contact Office of Research, University of Notre
Dame, Notre Dame, IN 46556.

Permission to modify the code and to distribute modified code is
granted, provided the text of this NOTICE is retained, a notice that
the code was modified is included with the above COPYRIGHT NOTICE and
with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE
file is distributed with the modified code.

LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
By way of example, but not limitation, Licensor MAKES NO
REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
OR OTHER RIGHTS.

Additional copyrights may follow.


The ring program is a canonical example of MPI usage.  It sends a
simple message around in a ring pattern:

       Rank 0 sends to rank 1
       Rank 1 sends to rank 2
       Rank 2 sends to rank 3
       ...
       Rank N-1 sends to rank N
       Rank N sends to rank 0
       Rank 0 sends to rank 1
       etc.

The message that is sent around the ring is a single integer.  If the
integer is zero, each rank quits after it has passed the message on.
Rank zero is special -- it will receive the message and decrement the
integer before it passes the message on.  This scheme guarantees that
the application completes in an orderly fashion in finite time.

Rank zero is also special in that it both starts and finishes the
ring.  Rank 0 sends the initial message (which is hardwired to "5" in
this example) to rank 1 to start the whole process.  Rank 0 then also
has to consume the final "0" message from rank N so as not to leave a
message "hanging" out on the network when all the ranks quit.

Use "make" to compile this example.  Make will use mpicc to compile
the program:

        mpicc -o ring ring.c 

This program can be run with any number of MPI ranks, including 1.
