Compiling Serial Programs
Here are some simple examples to show how to use the available compilers to build an executable from source code. These examples apply either to a serial code, or to a code that is multithreaded with OpenMP so it can use multiple cores on a single compute node.
NVIDIA Compilers
GNU Compilers
Performance Options
Additional compiler flags can be selected to optimize the performance of the code. For the NVIDIA compilers on Horizon, TACC recommends using the flag -fast, which creates a generally optimal set of flags during compilation. Additionally, it tells the compiler to optimize performance for the CPUs and GPUs that happen to be on the machine where the compiler is running. This approach is valid as long as the machine on which the code is compiled (e.g., a login node) has the same CPU as the target machine (e.g., a "Grace Blackwell" compute node). To make extra sure that your code is correctly optimized for Grace processors, you can add the flag -tp neoverse-v2; for GPU code, -gpu=cc100 could be added for Blackwell. For Vera, the appropriate flag is -tp olympus. The full command lines for a CPU-only code therefore look like this:
The -fast option does not do interprocedural optimization or inlining. To enable those, add -Mipa=fast,inline to the above.
With GCC, the -O3 flag tells the compiler to be aggressive in making code transformations for greater speed. However, by default, GCC compilers generate code that works on a wide range of processors of a given family. To produce code that is optimized for the CPUs on the specific machine where the code is intended to run, additional flags are typically needed. 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.
On Horizon, 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. Thus, with GCC, the command lines for a CPU-only code on Horizon look like this:
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)