Full Example
The purpose of this exercise is to ensure that you're actually able to compile and run an MPI code. In order to do this, we'll use the basic "Hello World" code from an earlier topic. Copy the code in your preferred language (C or Fortran) into your clipboard, then paste it into your favorite editor on Frontera or Vista. Compile it using your compiler of choice, e.g.:
or
Move the binary into your home directory, and use a text editor to create a batch script for executing the app. If you're using the Slurm batch manager, you can just copy the script below (which also appears on the previous page): it defines a job that runs 16 MPI tasks on a single development node. You can change the queue name if necessary. Be sure to edit the allocation account number on the line that starts with #SBATCH -A
; if you have only one account, you can remove that line from the script entirely.
Go ahead and submit the job, and verify that the contents of the stdout (myMPI.oJobID) look something like this:
The output simply shows all of the workers giving their id and repeating the message from the manager saying hello.
Though this is a simple MPI program with no real purpose, getting MPI to work with a scheduler is a good first step. However, at this point, it is still highly recommended to get a better understanding of—and practice with—the fundamental two-way communication mechanisms present in MPI, as well as some of the problems that can arise. This is all covered in the CVW MPI Point-to-Point roadmap.
CVW material development is supported by NSF OAC awards 1854828, 2321040, 2323116 (UT Austin) and 2005506 (Indiana University)