Approx. 20 minutes
If so, then continue to the next step. If not, then login as you did previously for Exercise 1.
Assuming you were able to create a successful “hello world” MPI program in Exercise 1, copy your source file to a new file and call it something like
helloBsend.f. If you were not successful, you can use the provided
mpi_hello.f. as your starting point.
Edit your new
helloBsend source file and modify it to do the following - after the master task has printed the number of tasks, but before MPI_Finalize:
Have each task determine a unique partner task to send/receive with. One easy way to do this:
if (taskid < numtasks/2) then partner = numtasks/2 + taskid else if (taskid >= numtasks/2) then partner = taskid - numtasks/2
if (taskid .lt. numtasks/2) then partner = numtasks/2 + taskid else if (taskid .ge. numtasks/2) then partner = taskid - numtasks/2
Each task sends its partner a single integer message: its
Each task receives from its partner a single integer message: the partner’s
For confirmation, after the send/receive, each task prints something like “Task ## is partner with ##” where ## is the taskid of the task and its partner.
Using your choice of compiler as in Exercise 1, compile your
helloBsend program until you get a clean compile.
srun command as in Exercise 1 to run your executable. For example:
srun -N2 -n8 -ppReserved helloBsend
Did your job run successfully? Based on the output, did it behave as expected? If not, figure out any problems and fix them before proceeding.
Run your program a few more times, but vary the number of nodes and total tasks. Observe the task output statements to confirm.
If time permits, copy your helloBsend source file to a new helloNBsend source file. Then convert the blocking routines to non-blocking routines. See the provided or source files if you need assistance.