Topics Map > •Research Computing
CRC Compiling and Optimizing
Compiling and Optimizing
Several programming models are supported on this system. Programs that are sequential, parallel (within a node) or distributed can be run. Sequential programs require one processor to run. Parallel and distributed programs utilize multiple processors concurrently. Parallel programs are a subset of distributed programs. Generally speaking, distributed computing involve parametric sweeps, task farming, etc. Message passing, threaded applications generally fit under the scope of parallel computing. SPMD (single process, multiple data) is one of the most popular method of parallelism, where a single executable works on its own data.
The supported compilers on this system are Intel and GCC. The MPI implementations from OpenMPI and Intel are available for both compilers and can be loaded upon demand using the module command. The preferred compiler for this system is Intel.
Compiling Serial Code
To compile serial code you must first load the appropriate compiler environment module. To load the Intel compiler, execute this command:
module load iccifort
Once the environment is set, you can compile your program with one of the following (using Intel compiler as an example):
icc -o executablename sourcecode.c
icc -o executablename sourcecode.cc
ifort -o executablename sourcecode.f77
ifort -o executablename sourcecode.f90
When invoked as described above, the compiler will perform the preprocessing, compilation, assembly and linking stages in a single step. The output file (or executable) is specified by executablename and the source code file is specified by sourcecode.f77, for example. Omitting the -o executablename
option will result in the executable being named a.out by default. For additional instructions and advanced options please view the online manual pages for each compiler (i.e. execute the command man ifort
).
Compiling Parallel Code
To compile a parallel version of your code that has MPI library calls, use the appropriate MPI library. Again, use module command to load the appropriate compiler environment as follows (Intel versions highly recommended):
module command | Description |
---|---|
module load GCC OpenMPI |
For gcc compiled OpenMPI |
module load iccifort OpenMPI |
For Intel compiled OpenMPI |
module load GCC impi |
For gcc compiled Intel MPI |
module load iccifort impi |
For Intel compiled Intel MPI |
To compile your code you will have use the MPI compiler wrappers that are currently in your default path. The MPI wrappers are responsible for invoking the compiler, linking your program with the MPI library and setting the MPI include files.
Once the environment is set, you can compile your program with one of the following:
mpicc -o executablename mpi_sourcecode.c
mpicxx -o executablename mpi_sourcecode.cc
mpif77 -o executablename mpi_sourcecode.f77
mpif90 -o executablename mpi_sourcecode.f90
When invoked as described above, the compiler will perform the preprocessing, compilation, assembly and linking stages in a single step. The output file (or executable) is specified by executablename and the source code file is specified by mpi_sourcecode.f77, for example. Omitting the -o executablename
option will result in the executable being named a.out by default. For additional instructions and advanced options please view the online manual pages for each compiler (i.e. execute the command man mpif77
).
GNU Compiler
The GNU compiler is installed as part of the Red Hat Enterprise Linux distribution. Use man gcc
to view the online manual for the C and C++ compiler, and man gfortran
to view the online manual for the Fortran compiler.