# Information about how to set the various options here.
# Ideally you can use a file already created for your platform in this directory.
# Otherwise, you can work from the one most similar that is here.

# Select the Fortran compiler you are using.
# if you have a different one than these, modifications in Common/compiler.h
# and Common/common-rules.mk will be necessary.
COMPFLAG  = -D{INTEL, PGI, GNU, PATH, XLF, G95, ABSOFT, NAG, OPEN64, SUN, CRAY}

# Use -DMPI to compile Fortran in parallel with MPI. Otherwise is serial.
# Add -DOMP to compile with OpenMP support. Also add appropriate compiler-dependent flag to F90free:
# ifort, sunf90, absoft, pathscale, Open64: -openmp. PGI: -mp=nonuma. gfortran: -fopenmp. XLF: -qsmp=omp.
# crayftn: on by default (to turn off use -h noomp). g95 and NAG do not support OpenMP.
PARAFLAG  = -DMPI
# -DUSESCALAPACK enables usage of ScaLAPACK (required in parallel for BSE).
# -DUSEESSL uses ESSL instead of LAPACK in some parts of the code.
# -DUNPACKED uses unpacked rather than packed representation of the Hamiltonian
# in EPM. Packed LAPACK operations give bad results eventually in Si-EPM kernel 'max x'
# test for ACML, Cray LibSci, and MKL sometimes.
# -DUSEFFTW3 uses fftw3 instead of fftw2, which is recommended for better performance, and enables threading.
# -DHDF5 enables usage of HDF5 for writing epsmat and bsemat files. The produced files will be
# eps0mat.h5, epsmat.h5 and bsemat.h5 and are used in place of eps0mat, epsmat, bsedmat, bsexmat 
# (the latter two are combined in one .h5 file). 
# Using -DHDF5 gives you substantially better IO performance in many cases by taking advantage
# of HDF5's parallel IO options and other options. However, you must have the HDF5 libraries
# installed on your system and define HDF5LIB and HDF5INCLUDE below.
MATHFLAG  = -DUSESCALAPACK -DUSEESSL -DUNPACKED -DHDF5
# For Fortran and C++. -DDEBUG enables extra checking. -DVERBOSE is an internal
# flag, and is equivalent to running all codes with the maximum verbosity level.
# Don't use the -DVERBOSE option, unless a developer told you to. The -DDEBUG
# option makes extra memory checks, and slows down the code by up to ~20%.
# Only use these flags if you need to develop or debug BerkeleyGW.
# The output will be much more verbose, and the code will slow down by ~20%.
DEBUGFLAG = -DDEBUG -DVERBOSE
# Same, but for C and C++.
C_DEBUGFLAG = -DDEBUG -DVERBOSE

# Command for the preprocessor. -C (and not -ansi) should generally be used.
# add -P if the Fortran compiler will not accept indication of line numbers.
# Use gcc's (often in /lib/cpp) or a C compiler (even mpicc) with "-E". Some need "-x c" as well.
FCPP    = cpp -C
# Fortran compiler and its flags for F90 and f90 files (free source form)
# see above at PARAFLAG regarding flags for OpenMP.
# With -DOMP and openmp flags here, you will get threaded BerkeleyGW.
# Without -DOMP, but with openmp flags here, is appropriate for just using threaded libraries.
# Sometimes, flags such as -fno-second-underscore or -assume 2underscores may be necessary
# to make linking succeed against C libraries such as FFTW, depending on what compiler built them.
F90free = {mpif90, mpiifort, ftn, ifort, pgf90, gfortran, ...}
# Fortran compiler and any flag(s) required for linking
LINK    = {mpif90, mpiifort, ftn, ifort, pgf90, gfortran, ...}
# Fortran optimization flags. The levels below will generally work.
FOPTS   = {-fast, -O3}
# Fortran optimization flags for epsilon_main and sigma_main which can have
# trouble in high optimization due to their long length. If below does not
# work, try -O2.
FNOOPTS = $(FOPTS)
# Fortran compiler flag to specify location where module should be created.
# different for each compiler, refer to examples.
MOD_OPT =
# Fortran compiler flag to specify where to look for modules.
INCFLAG = -I

# Use this to compile C++ in parallel with MPI. Leave blank for serial.
# MPICH, MVAPICH, Intel MPI require also -DMPICH_IGNORE_CXX_SEEK, or an error may occur such as:
# "SEEK_SET is #defined but must not be for the C++ binding of MPI. Include mpi.h before stdio.h"
C_PARAFLAG  = -DPARA
# C++ compiling command and any needed flags
CC_COMP = {mpiCC, mpicxx, mpiicpc, CC, icpc, pgCC, g++, ...}
# C compiling command and any needed flags
C_COMP  = {mpicc, mpiicc, cc, icc, pgcc, gcc, ...}
# C/C++ link command and any needed flags
C_LINK  = {mpiCC, mpicxx, mpiicpc, CC, icpc, pgCC, g++, ...}
# C/C++ optimization flags
# Note: for Intel compilers, it is equivalent to use icc or icpc on C++ files.
C_OPTS  = -fast

# command to remove, for make clean
REMOVE  = /bin/rm -f
# command for making archives (.a). Default is /usr/bin/ar.
# Usually that is fine and AR does not need to be specified, but
# to do interprocedural optimizations (IPO) with ifort, you need xiar instead.
#AR = /usr/bin/env xiar

# Math Libraries
# path for FFTW library, used in lines below
FFTWPATH     = 
# link line for FFTW2 library. Sometimes needs to be -ldfftw
FFTWLIB      = -L$(FFTWPATH)/lib -lfftw
# link line for FFTW3 library, if -DUSEFFTW3 is used. Including fftw_omp allows threaded run.
# Note: To use FFTW3 from MKL, do not link the fftw3xf interfaces.
FFTWLIB      = -L$(FFTWPATH)/lib {-lfftw3_omp} -lfftw3
# FFTW2 requires include file fftw_f77.i;
# Sometimes supercomputer installations will not have it.
# If not, find it online and copy it: e.g. http://www.fifi.org/doc/fftw-dev/fortran/fftw_f77.i
# FFTW3 requires include file fftw3.f03 instead.
FFTWINCLUDE  = $(FFTWPATH)/include

# Different styles will apply depending on the package used.
# Must provide BLAS as well as LAPACK: some packages will do this in one library file,
# others will not. See examples in this directory for how to link with MKL, ACML,
# ATLAS, Ubuntu packages, etc. For MKL, if you will use ScaLAPACK, it is most
# convenient to include BLACS here too. For further info on linking with MKL, see
# the link-line advisor at http://software.intel.com/sites/products/mkl/
LAPACKLIB    = 

# Specify below if you have -DUSESCALAPACK in MATHFLAG.
# BLACS must be provided here too, if it is not provided in LAPACKLIB above. See
# examples in this directory for different packages, as with LAPACKLIB. Note that
# you may have problems if ScaLAPACK was not built with the same LAPACK used above.
SCALAPACKLIB =

# Specify below if you have -DHDF5 in MATHFLAG.
# If compiling in parallel, you must have HDF5 compiled with parallel support or linking will fail.
# Path as below should generally work. Sometimes -lsz too, or static linkage, might be required.
# Note that "-lz" is not from HDF5, but its dependency zlib.
# libdl may be required on your system even when linking static HDF5 due to plugin support in 1.8.11 and higher
HDF5PATH     =
HDF5INCLUDE  = $(HDF5PATH)/include
HDF5LIB      = -L$(HDF5PATH)/lib -lhdf5hl_fortran -lhdf5_hl -lhdf5_fortran -lhdf5 -lz

# Flags for performance profiling with an external tool such as IPM on NERSC
PERFORMANCE  = 

# Command to submit testsuite job script from testsuite directory.
# qsub is for PBS. If no scheduler, put make check-parallel here.
# In serial, delete this line.
TESTSCRIPT = qsub {architecture}.scr
