Compiling thecode
Command To Compile
thecode is compiled using a makefile. The file "makefile" is contained in the folder with all of the .c and .h files of thecode. Compiling on linux is accomplished by simply typing: $ make
To remove the results of a previous compile, type: $ make clean
Note: All computer programs including thecode need to be recompiled on each computer system you run on (e.g. watt vs. fsl). Executables compiled on one computer and then copied or moved to another computer will not function.
makefile
Within the makefile, you must specify multiple things as described below.
- Executable Name (EXEC)
- Compiler (CC)
- Compiler Options (CFLAGS)
- Code Options (DFLAGS)
- Location of .h files to include (INCL)
- Location of libraries for linking (LIBS)
1. Executable Name (EXEC)
You can specify any name for the executable. This is done in the makefile with EXEC = executable-name
2. Compiler (CC)
Multiple compilers are available on both watt and fsl.
Compiler | Description |
---|---|
CC = gcc | Gnu C Compiler |
CC = icc | Intel C Compiler |
CC = mpicc | Message Passing Interface C Compiler |
icc will generally make faster code than gcc; however, gcc is widely available on almost all computers. icc is not available for our lab computers.
mpicc is used when you want to compile the code to run in parallel (for replica exchange purposes). mpicc can be a variety of different compilers and mpi implementations. For example, OpenMPI, MPICH, and IMPI are all implementation of MPI. To specify which MPI and compiler you want to use with mpicc is different on watt and FSL. For both, you should almost always use OpenMPI, but you can change the compiler.
Using mpicc on Watt
Watt uses mpi-selector
to specify the MPI distribution and compiler to use for mpicc. Type the following to see the available options. $ mpi-selector --list
Usually, you will use one of the following
openmpi-1.4-gcc-i386 | OpenMPI version 1.4 and 32-bit gcc |
openmpi-1.4-gcc-x86_64 | OpenMPI version 1.4 and 64-bit gcc |
openmpi-1.4.5-icc-x86_64 | OpenMPI version 1.4.5 and 64-bit icc |
openmpi-1.4.5-icc-x86_64 should give the fastest code.
To select the desired option, type: $ mpi-selector --set openmpi-1.4.5-icc-x86_64
Log out of watt and log back in before compiling the code.
Using mpicc on FSL
FSL uses module
to specify the MPI distribution and compiler to use for mpicc. Type the following to see the available options: $ module avail mpi
You will see many options for intel, Gnu, Portland Group Compiler, IMPI, OpenMPI, and MPICH. Typically you will want to use the latest version of OpenMPI with the latest Intel or Gnu compiler.
By default, mpi/openmpi_1.6.3_gnu-4.4
is loaded. If you want to select a different option, you will need to first unload this module and load the desired one. For most situations this is unneeded.
To load a different mpi module use the following commands: $ module unload mpi/openmpi_1.6.3_gnu-4.4
$ module load mpi/openmpi-1.8.4_intel-15.0.0
3. Compiler Options (CFLAGS)
Compilers may be directed to compile codes different ways. For example, you can direct the compiler to add debugging information to the code or you can tell it to make the code as fast as possible. A full list of options for different compilers can be found on their respective man
pages.
In the makefile, the compiler options are set using the variable CFLAGS Below are some common combinations.
||border = 1
Compiler | Options | Description |
---|---|---|
gcc | -O3 -std=c99 -Wall | GNU Optimized for Speed |
gcc | -std=c99 -Wall -g | GNU Debugging |
icc | -O3 -ipo -no-prec-div -w -xW -axW -std=c99 | Intel Compiler Optimized for Speed |
4. Code Options (DFLAGS)
thecode is a very versatile program. Many of the options are specified at compile time as DFLAGS
. For example, to output a movie file you define the TRR
option using DFLAGS = -DTRR
Notice the -D
in front of the option TRR
. (.trr is the type of file many movie programs read, this includes the VMD movie program we use.)
More information on define options is found here.
5. Location of Header Files to Include (INCL)
Many libraries are available in the C programming language. To use these in the code, you need include the header (.h) files. The location of these files is found somewhere on each computer system. The default location is usually enough, but sometimes you need to specify additional locations. This is done by defining the INCL
variable in the makefile.
For both watt and fsl, the following line should be found in the makefile: INCL = -I${MKLROOT}/include
For watt, you also have to include the following line before the line found just above: MKLROOT = /opt/intel/composerxe-2011.2.137/mkl/
Note that MKLROOT
is automatically specified on fsl so it doesn't have to be specified. Also, you really don't need to include this library unless you are using MKL
. To make your life easier, it is always included by default in the makefile.
6. Location of Libraries for Linking (LIBS)
In addition to specifying the location of the include files (just described), the compiler will need to link to the libraries needed by the program. For the code, you specify the linking library with: LIBS = ${LIBSMKL} -lm
-lm
is the standard math library. LIBSMKL
is the location of the @MKL libraries. Strictly speaking,
LIBSMKL isn't needed if you aren't using
MKL. However, keeping it in the definition of
LIBS@@ doesn't affect the makefile, so it is kept in for simplicity.
Note, the variable: LIBSMKL = -Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_ilp64.a ${MKLROOT}/lib/intel64/libmkl_core.a ${MKLROOT}/lib/intel64/libmkl_sequential.a -Wl,--end-group -lpthread
should always be present in the makefile on both watt and fsl. On watt, you also need to specify: #MKLROOT = /opt/intel/composerxe-2011.2.137/mkl/