Compiling Parallel Programs
Calls to the Message Passing Interface (MPI) are a typical part of a parallel application that is meant to run on a distributed memory resource such as Horizon. As the name suggests, MPI describes a standard interface together with a set of expected message-passing actions. When the code runs, the expected actions are performed by a system-specific MPI implementation, which usually comes in the form of a library.
Two major MPI implementations ("stacks") are supported on Horizon:
- Open MPI
- mvapich-plus (Ohio State University)
Either of these implementations may be selected through the module system. A default MPI module is generally already loaded when you log in, which is openmpi/5.0.11 (November, 2026). To see all the available versions, run:
Regardless of which MPI implementation you choose, the commands you use to compile and link your code are always the same:
| Command | Language | Filename Extension(s) | Example |
|---|---|---|---|
| mpicc | C | .c | mpicc prog.c |
| mpicxx | C++ | .C, .cc, .cpp, .cxx | mpicxx prog.cpp mpic++ prog.cpp |
| mpif77 | Fortran 77 | .f, .for, .ftn | mpif77 prog.f |
| mpif90 | Fortran 90 | .f90, .fpp | mpif90 prog.f90 |
The mpiXXX commands are "wrapper" scripts that call the underlying C/C++/Fortran compiler for you, including any compiler options that are needed for properly linking your selected MPI library to your code. For Open MPI (only), if you execute mpiXXX -show, you can see the full compile line that is generated by that wrapper. Open MPI also provides a third name for its C++ wrapper, mpiCC.
Performance Options
As we saw with serial programs, it is a good idea to supply architecture-specific optimization options to the compiler to ensure you get the best per-core performance for your code. For the NVIDIA compilers, the same -fast and -tp flags apply:
The -fast option does not do interprocedural optimization or inlining. To enable those, add -Mipa=fast,inline to the above.
For GCC on ARM platforms, -mcpu is preferred over -march: the -march flag selects only the instruction set architecture, while -mcpu additionally enables CPU-specific scheduling and tuning for the target core. Use -mcpu=neoverse-v2 for Grace nodes and -mcpu=olympus for Vera nodes; note that -mcpu=olympus requires GCC 16.1 or later. See the NVIDIA performance tuning guides for Grace (Neoverse V2) and Vera (Olympus), as well as the GCC AArch64 Options documentation, for details.
The -O3 option does interprocedural optimizations within a source file, but not across files. To enable cross-file optimizations at link time, you can add -flto to the above (at the cost of increased build time).
As an alternative, you may use the environment variable $TACC_VEC_FLAGS to set the compiler flags appropriately for the compiler that you have selected through one of TACC's modules. To view the expanded set of options that $TACC_VEC_FLAGS brings in for the NVIDIA compiler, check the Building for Performance section of the Horizon User Guide. Again, specifying the right -tp option along with these will ensure that the code is built optimally for the target CPU. For GCC, consider adding -flto for cross-file optimizations at link time.
CVW material development is supported by NSF OAC awards 1854828, 2321040, 2323116 (UT Austin) and 2005506 (Indiana University)