2011年11月19日

Create the Makefile for fortran program by mkmf

The fortran program need the Makefile to build under linx. There are several Makefile generate on the web. The mkmf is the one used to build the SPH code.

1. Download the mkmf from the website: http://www.gfdl.noaa.gov/~vb/mkmf.html

2. Create a template for mkmf, which define the compiler, pre-processor (CPP,FPP), include path and library path and so on. The sample template is sown below, file name “mkmf_template” :

# template for the Intel fortran compiler version with mpich2
# typical use with mkmf:
#-------------------------------------------------------
# perl mkmf -t mkmf_template ../src_prec_source
#------------------------------------------------------
# compiler to compile the source code.
FC = mpif90 -fpp
# compiler to link the source doe.
LD = mpif90 -fpp
CPPDEFS    =
CPPFLAGS   =
FPPFLAGS   =
#define the include files.
#FFLAGS     =  -g  -heap-arrays -O3  -axSSE4.2 -I/home/tmsxh/Desktop/hostshare/PPM_library_Linux/libppm-1.2.1/include/ppm
FFLAGS     =   -g  -heap-arrays -I/home/tmsxh/Desktop/hostshare/PPM_library_Linux/libppm-1.2.1/include/ppm
OTHERFLAGS =
LDFLAGS    =
# add your libraries after LIBS= , e.g. -lblas
#LIBS = c:/mingw/lib
MKLLIB = -L/opt/intel/mkl/lib/intel64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5
#MKLLIB = /opt/intel/mkl/lib/intel64/libmkl_intel_lp64.a  /opt/intel/mkl/lib/intel64/libmkl_intel_thread.a /opt/intel/mkl/lib/#intel64/libmkl_core.a -liomp5
#LIBS = -L/home/tmsxh/ppm/ppm-1.0.1/lib -L/usr/lib/gcc/x86_64-redhat-linux/3.4.6 -lppm -lmetis -lvizing  ${MKLLIB}
LIBS = -L/home/tmsxh/Desktop/hostshare/PPM_library_Linux/libppm-1.2.1/lib -lppm -lmetis ${MKLLIB}
LDFLAGS    = $(LIBS)

3. generate the make file by : perl mkmf -t mkmf_template ../src_prec_source

3.1 “-t mfmk_template” : specify the template file;
3.2 “../src_prec_source ” : specify the folder the fortran code located.

4. make ; to generate the code.

Compile the PPM library version 1.0.1 and 1.2.1 on Linux

COMPILE PPM 1.0
    1. compile vizing:
        1.1 vizing is written by older c++ standard, hence the latest version of g++ can't work,
                2.1 the g++ version 34 "g++34" is employed to compile the code.
    2. compile the metis library.
        2.1 the metis include the the ppm-1.0.1 has problem to compile, the error is related to __log2. The error message is "/usr/include/bits/mathcalls.h:145: note: previous declaration of ‘__log2’ was here". Hence, use the metis library download from the PPM, address: http://www.ppm-library.org/index.php/download
        2.2 replace the metis by metis4 and copy the library to "libmetis.a"
    3. install fftw3
        3.1 download fftw3 from : http://www.fftw.org/download.html
        3.2 unpack the fftw3 by: tar xvzf fftw-3*.tar.gz
        3.3 configure the fftw3 : ./configure
                3.4 make the fftw3  : make
                3.4 install the fftw3: sudo make install
                3.5 the detail procedure can see INSTALL
    3. compile the PPM library.
        3.1 set the file in Make.userprefs: change FC as the setting mpif90
                     e.g : FC:=/usr/bin/mpif90
        3.2 set the FFTWDIR ( check where the FFTW installed by the following command :
                         rpm -ql fftw )
             e.g : FC:=/home/tmsxh/fftw-3.3
        3.3 change the compiler flag in ppm_define.h
                3.4 in order to get the preporcessed source file of PPM libaray comment the following line                 in file "Makefile.static", the program will not remove the preporcessed fortran file.
                   #    @rm $(OBJ_DIR)/__$*.f
                the preprocessed fortran code are stored in folder
COMPLIE PPM 1.2
    1. install the metis libaray.
    2. configure the library before compile by: ./configure --enable-mpi=mpich2 FC=/usr/bin/mpif90 --enable-linux LDFLAGS=-L./metis4/lib
        2.1 –enable-mpi= mpich2 : specify the mpich2 is employed as mpi library;
        2.2 FC = /usr/bin/mpif90  : specify the fortran MPI compiler; the mpif90 need to configured, before compile the PPM library;
        2.3 LDFLAGS=                : specify the location of metis library and other library.
    3. compile the PPM library by : make
    4. install the PPm library by  : sudo make install   
        the install will copy the “include” library to: /usr/local/include/ppm 
                                           and “library” to : /usr/local/lib