Compiling and Linking¶
Before compiling in the RC environment, begin a compile job by using the
acompile command. Next, load the modules corresponding to the compiler, MPI version (if needed), and any third-party libraries required by your application. The load order should always be compiler first, MPI second, and third-party libraries last.
For example, suppose your application requires MPI and the HDF5
library. To compile using the Intel compiler and Intel MPI, the
module commands would be:
module purge module load intel module load impi module load hdf5
Supporting library-modules will be loaded as needed, and your
environment will be updated so that the appropriate library
directories are prepended to your
$LD_LIBRARY_PATH. The standard compiler variables
CXX are set as appropriate for your compiler/MPI combination. These environment variables reference to the Fortran, C, and C++ compilers respectively
In addition, several environment variables are set that may be useful during the compilation process. These variables are prefixed by
CURC and may easily be found by searching your environment for
env | grep CURC. This will yield output similar to:
[johndoe@@c3cpu-a5-u17-2 ~]$ env | grep CURC CURC_INTEL_BIN=/curc/sw/intel/17.4/bin CURC_INTEL_INC=/curc/sw/intel/17.4/include CURC_INTEL_ROOT=/curc/sw/intel/17.4 CURC_INTEL_LIB=/curc/sw/intel/17.4/lib CURC_HDF5_ROOT=/curc/sw/hdf5/1.10.1/impi/17.3/intel/17.4 CURC_HDF5_INC=/curc/sw/hdf5/1.10.1/impi/17.3/intel/17.4/include CURC_HDF5_BIN=/curc/sw/hdf5/1.10.1/impi/17.3/intel/17.4/bin CURC_HDF5_LIB=/curc/sw/hdf5/1.10.1/impi/17.3/intel/17.4/lib [...]
Once the relevant modules are loaded, you are ready to compile. For our HDF5 example, a compilation command that uses the environment variables set by the module system may look like:
$FC my_program.f90 -I$CURC_HDF5_INC -L$CURC_HDF5_LIB -lhdf5_fortran -o my_program
Note: Your run-time environment should reflect your compilation environment. Be sure to include the same sequence of
modulecommands in your job script as that used at compile time.
Compiler and Optimization Recommendations¶
The Alpine cluster runs on AMD-designed hardware, whereas the Blanca cluster runs on Intel-designed hardware. As such, we strongly recommend using the appropriate compiler and MPI library when compiling software. For production, we
suggest compiling with the
-O3 optimization flags along with the vectorization flags appropriate for the node you plan to run on. More compiler options and flags can be found in AMD’s reference guide.
Linking to the Math Kernel Library (MKL)¶
The Intel Math Kernel Library (MKL) provides optimized routines for a number of common mathematical operations. Notably, it provides interfaces to the LAPack and BLAS linear algebra libraries as well as the FFTW Fourier transform package.
If you wish to link MKL to your Intel-compiled application, use the
$CXX -O3 -xCORE-AVX2 my_program.cpp -o my_program.out -mkl
If your application uses FFTW, you will also need to include MKL’s FFTW directory in your compilation command:
$CXX -O3 -xCORE-AVX2 -I$CURC_MKL_INC/fftw my_program.cpp -o my_program.out -mkl
For the GNU and PGI compilers, the link syntax becomes more complex. The Intel Link Advisor can be used to generate the appropriate linking syntax based on your application’s needs.
For the GNU compiler, linking against sequential MKL libraries, the appropriate Fortran linking syntax is:
$FC my_program.f90 -m64 -I$CURC_MKL_INC -o my_program.out -L$CURC_MKL_LIB -Wl,--no-as-needed -lmkl_gf_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl
The comparable c/c++ syntax would be:
$FC my_program.cpp -m64 -I$CURC_MKL_INC -o my_program.out -L$CURC_MKL_LIB -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl
Note that if your application uses FFTW, you will must use the FFTW include flag just as with the Intel compiler. See the link advisor or contact firstname.lastname@example.org if you have additional questions about how to link MKL to your application.
Couldn’t find what you need? Provide feedback on these docs!