In this example, you will begin to build an Input/Output master/slave system. This will allow you to relatively easily arrange for different kinds of input and output from your program, including
For the first exercise, divide the processors into two communicators, with one processor the master and the others the slave. The master should accept messages from the slaves (of type MPI_CHAR) and print them in rank order (that is, first from slave 0, then from slave 1, etc.). The slaves should each send 2 messages to the master. For simplicity, Have the slaves send the messages
Hello from slave 3
Goodbye from slave 3
(with appropriate values for each slave). You may assume a maximum length
message of 256 characters.
For this first exercise, keep the code simple. Do not use intercommunicators. Also, you'll find that you use the new communicator for the slaves only to get the rank of the slave in its communicator. Note that if the slaves were also computing, they would use that new communicator instead of MPI_COMM_WORLD.
You may want to use these MPI routines in your solution:
MPI_Comm_split
MPI_Send
MPI_Recv