compiling basics for hpc - national institute for ......user can link application dynamically by...
TRANSCRIPT
![Page 1: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/1.jpg)
Compiling basics for HPC
Dr. Shiquan Su NICS
![Page 2: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/2.jpg)
from source code to executable
• edit source code: hello_world.cpp • compile object file: hello_world.o • link to executable: hello_world (a.out)
![Page 3: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/3.jpg)
edit source code
• main program (driver) *.cpp • header files ( required at compile time) *.h • function / subroutine files (libraries) (required
at link time) *.cpp *.h
![Page 4: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/4.jpg)
compile object file
• main program driver.cpp à driver.o • header files ( required at compile time) *.h • function / subroutine files (required at link
time) *.cpp à *.o à lib.a
![Page 5: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/5.jpg)
link to executable
• driver, libraries: driver.o , lib.a à executable (a.out) driver.cpp à driver.o
![Page 6: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/6.jpg)
simple example: using command line shiquan1@darter2:~/testcompiler> g++ hw.cpp shiquan1@darter2:~/testcompiler> ./a.out Hello World! CPP program. shiquan1@darter2:~/testcompiler> cat hw.cpp #include <iostream> using namespace std; int main (){ cout << "Hello World! CPP program.\n"; return 0; }
![Page 7: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/7.jpg)
MPI Compiler
• mpicxx • check the mpi package for: mpi header file: mpi.h mpi library: libmpi.a mpi compiler: mpicxx mpi launcher: mpirun (see the openmpi library on Keeneland as example)
![Page 8: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/8.jpg)
compiler wrapper (Cray) Cray provides a convenient set of compiler wrapper commands that should be used for compiling and linking programs to be run on the compute nodes. The wrapper invokes the corresponding back-end compiler in the currently loaded programming environment. Invoking the wrappers will automatically: • Import the path for key header files like 'mpi.h' and other
libraries • Link in the MPI and other fundamental header files and libraries
needed to run on Cray system • Automatically include and link in header files and libraries
loaded via module • Specify the correct target processor arguments • Provides a common interface to all compilers • mpi launcher: aprun.
![Page 9: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/9.jpg)
compiler wrapper Cray GNU Intel PGI C cc craycc gcc icc pgcc C++ CC crayCC g++ icpc pgCC Fortran ftn crayftn gfortran ifort pgfortran
9
The following table lists the compiler wrappers and the corresponding back-end compilers available on the system
![Page 10: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/10.jpg)
example: Darter
Compilers on Darter • The default compiler is the Cray compiler
(CCE) • The available compilers on Darter are : Cray
(default), GNU and Intel. • The PGI and Pathscale compilers are no
longer available
![Page 11: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/11.jpg)
11
PGI Cray Intel GNU Description -fast optimized
by default -fast –no-ipo -O3 –ffast-math standard optimization
-mp -homp -openmp -fopenmp enable OpenMP support
-Mfixed -Mfree
-ffixed -ffree
-fixed -free
-ffixed-form -ffree-form
process Fortran source as fixed or free format
Common Compiler Options
![Page 12: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/12.jpg)
Using Dynamic Linking on Darter
Some application requires the use of dynamic linking and shared libraries on the compute nodes. Example of these include software from third-party vendor and popular applications such as Python and OpenFoam. Darter fully supports the use shared libraries and dynamic linking on the compute nodes. All Cray's provided software on Darter were also built with shared libraries support and can be used by dynamically linked application.
![Page 13: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/13.jpg)
User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic flag during linking. The following show some examples on building dynamically linked application and shared libraries. Building Hello World program with dynamic linking: export CRAYPE_LINK_TYPE=dynamic cc -o hello hello.c Same example as above, but using linker flag: cc -dynamic -o hello hello.c The same procedures apply to ftn and CC to build Fortran and C++ code with dynamic linking, respectively.
13
Using Dynamic Linking on Darter Example
![Page 14: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/14.jpg)
You may find more info for Darter machine here: https://www.nics.tennessee.edu/computing-resources/darter/compiling
![Page 15: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/15.jpg)
Use Makefile to manage dependence
target [target ...]: [component ...] Tab ↹[command 1] . . . Tab ↹[command n]
![Page 16: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/16.jpg)
Use flags make.inc FC = mpif90 CC = mpicc NOOPT = -O0 FCFLAGS = -O3 CCFLAGS = -O3 FCLOADER = $(FC) CCLOADER = $(CC) FCLOADFLAGS = $(FCFLAGS) CCLOADFLAGS = $(CCFLAGS) BLASLIB = -L$MKL_DIR -mkl -lpthread -lm LAPACKLIB = LIBS = $(LAPACKLIB) $(BLASLIB)
![Page 17: Compiling basics for HPC - National Institute for ......User can link application dynamically by either setting the environment variable CRAYPE_LINK_TYPE to dynamic or by adding -dynamic](https://reader033.vdocuments.us/reader033/viewer/2022050123/5f52fb849fefb0147f78e86f/html5/thumbnails/17.jpg)
realistic example: compiling Scalapack and test driver using makefile
• edit driver • the reference for the library can be found at: http://www.netlib.org/scalapack/explore-html/ • edit make.inc • Scalapack depends on blas and lapack
libraries