# make.inc.  Generated from make.inc.in by configure.

# compilation rules

.SUFFIXES :
.SUFFIXES : .o .c .f90 .h .fh

# most fortran compilers can directly preprocess c-like directives: use
# 	$(MPIF90) $(F90FLAGS) -c $<
# if explicit preprocessing by the C preprocessor is needed, use:
#	$(CPP) $(CPPFLAGS) $< -o $*.F90
#	$(MPIF90) $(F90FLAGS) -c $*.F90 -o $*.o
# remember the tabulator in the first column !!!

.f90.o:
	$(CPP) $(CPPFLAGS) $< -o $(*)_tmp.f90 ; \
        $(MPIF90) $(F90FLAGS) -c $(*)_tmp.f90 -o $(*).o

.c.o:
	$(CC) $(CFLAGS)  -c $<

.h.fh:
	$(CPP) $(CPPFLAGS) $< -o $*.fh



# Top QE directory, useful for locating libraries,  linking QE with plugins
# The following syntax should always point to TOPDIR:
TOPDIR = $(dir $(abspath $(filter %make.inc,$(MAKEFILE_LIST))))
# if it doesn't work, uncomment the following line (edit if needed):

# TOPDIR = /home/siwakorn/ThaiSC-project/QE/install/qe-7.2_gpu

# DFLAGS  = precompilation options (possible arguments to -D and -U)
#           used by the C compiler and preprocessor
# To use libxc (v>=4.3.0), add -D__LIBXC to DFLAGS
# See include/defs.h.README for a list of options and their meaning
# With the exception of IBM xlf, FDFLAGS = $(DFLAGS)
# For IBM xlf, FDFLAGS is the same as DFLAGS with separating commas

# MANUAL_DFLAGS  = additional precompilation option(s), if desired
#                  BEWARE: it does not work for IBM xlf! Manually edit FDFLAGS
MANUAL_DFLAGS  =
DFLAGS         = -D__FFTW3 -D__CUDA -D__MPI
FDFLAGS        = $(DFLAGS) $(MANUAL_DFLAGS)

# IFLAGS = how to locate directories with *.h or *.f90 file to be included
#          typically -I$(TOPDIR)/include -I/some/other/directory/
#          the latter contains .e.g. files needed by FFT libraries
# for libxc add -I/path/to/libxc/include/

IFLAGS         = -I. -I$(TOPDIR)/include -I${FFTW_INC}

# MOD_FLAG = flag used by f90 compiler to locate modules

MOD_FLAG      = -I

# BASEMOD_FLAGS points to directories containing basic modules,
# while BASEMODS points to the corresponding module libraries.
# More package-specific directories can be added in each Makefile
# and stored into MODFLAGS, and the same for module libraries in QEMODS

BASEMOD_FLAGS= $(MOD_FLAG)$(TOPDIR)/upflib \
               $(MOD_FLAG)$(TOPDIR)/XClib \
               $(MOD_FLAG)$(TOPDIR)/Modules \
               $(MOD_FLAG)$(TOPDIR)/FFTXlib/src \
	       $(MOD_FLAG)$(TOPDIR)/LAXlib \
	       $(MOD_FLAG)$(TOPDIR)/UtilXlib \
	       $(MOD_FLAG)$(TOPDIR)/MBD \
	       $(MOD_FLAG)$(TOPDIR)/KS_Solvers $(FOX_MOD)

# If A depends upon B, A should come before B in the list below
# (most compilers don't care but some don't resolve cross links)
BASEMODS= $(TOPDIR)/Modules/libqemod.a \
          $(TOPDIR)/upflib/libupf.a \
          $(TOPDIR)/XClib/xc_lib.a \
          $(TOPDIR)/FFTXlib/src/libqefft.a \
          $(TOPDIR)/LAXlib/libqela.a \
          $(TOPDIR)/UtilXlib/libutil.a \
          $(TOPDIR)/MBD/libmbd.a

# Compilers: fortran-90, fortran-77, C
# If a parallel compilation is desired, MPIF90 should be a fortran-90
# compiler that produces executables for parallel execution using MPI
# (such as for instance mpif90, mpf90, mpxlf90,...);
# otherwise, an ordinary fortran-90 compiler (f90, g95, xlf90, ifort,...)

MPIF90         = ftn
F90           = ftn
CC             = cc

# GPU architecture (Kepler: 35, Pascal: 60, Volta: 70 )
GPU_ARCH=80

# CUDA runtime (Pascal: 8.0, Volta: 9.0)
CUDA_RUNTIME=11.7

# CUDA F90 Flags
CUDA_F90FLAGS=-cuda -gpu=cc80,cuda11.7 $(MOD_FLAG)$(TOPDIR)/external/devxlib/src $(MOD_FLAG)$(TOPDIR)/external/devxlib/include -acc $(MOD_FLAG)$(TOPDIR)/external/devxlib/src

# CUDA C Flags
CUDA_CFLAGS= -I/opt/nvidia/hpc_sdk/Linux_x86_64/22.7/cuda/include -cuda -gpu=cc80,cuda11.7 -acc

# C preprocessor and preprocessing flags - for explicit preprocessing,
# if needed (see the compilation rules above)
# preprocessing flags must include DFLAGS and IFLAGS

CPP            = cpp
CPPFLAGS       = -P -traditional -Uvector $(DFLAGS) $(IFLAGS)

# compiler flags: C, F90
# C flags must include DFLAGS and IFLAGS
# F90 flags must include MODFLAGS, IFLAGS, and FDFLAGS with appropriate syntax

CFLAGS         = -O3 $(DFLAGS) $(IFLAGS) $(CUDA_CFLAGS)
F90FLAGS       = $(FFLAGS)  $(FDFLAGS) $(CUDA_F90FLAGS) $(IFLAGS) $(MODFLAGS)

# compiler flags with and without optimization for fortran-77
# the latter is NEEDED to properly compile dlamch.f, used by lapack
FFLAGS         = -O1 
FFLAGS_NOOPT   = -O0

# compiler flag needed by some compilers when the main program is not fortran
# Currently used for Yambo

FFLAGS_NOMAIN   = 

# Linker, linker-specific flags (if any)
# Typically LD coincides with F90 or MPIF90, LD_LIBS is empty
# for libxc, set LD_LIBS=-L/path/to/libxc/lib/ -lxcf03 -lxc
# If libxc release is 5.0.0 replace -lxcf03 with -lxcf90

LD             = ftn
LDFLAGS        =   -cuda -gpu=cc80,cuda11.7 -acc
LD_LIBS        = 

# External Libraries (if any) : blas, lapack, fft, MPI

# If you have nothing better, use the local copy
# BLAS_LIBS = $(TOPDIR)/external/lapack/libblas.a

BLAS_LIBS      = ${CRAY_NVIDIA_PREFIX}/compilers/lib/libblas.so

# If you have nothing better, use the local copy
# LAPACK = liblapack
# LAPACK_LIBS = $(TOPDIR)/external/lapack/liblapack.a

LAPACK      = 
LAPACK_LIBS = ${CRAY_NVIDIA_PREFIX}/compilers/lib/liblapack.so ${CRAY_NVIDIA_PREFIX}/compilers/lib/libblas.so

SCALAPACK_LIBS = 

# nothing needed here if the the internal copy of FFTW is compiled
# (needs -D__FFTW in DFLAGS)

FFT_LIBS       = $(FFTW_DIR)/libfftw3.so $(FFTW_DIR)/libfftw3_threads.so $(FFTW_DIR)/libfftw3_omp.so \
           -L/opt/nvidia/hpc_sdk/Linux_x86_64/22.7/cuda/11.7/lib64  -lstdc++

# HDF5
HDF5_LIBS = 

# FOX
FOX      = 
FOX_MOD  = 
FOX_LIB  = 
FOX_FLAGS = 

# ENVIRON
ENVIRON_LIBS = 

# MPI libraries (should not be needed)

MPI_LIBS       = 

# IBM-specific: MASS libraries, if available and if -D__MASS is defined in FDFLAGS

MASS_LIBS      = 

# CUDA libraries
CUDA_LIBS=-cudalib=cufft,cublas,cusolver,curand $(TOPDIR)/external/devxlib/src/libdevXlib.a -L$(TOPDIR)/external/devxlib/src -ldevXlib
CUDA_EXTLIBS = devxlib

# ar command and flags - for most architectures: AR = ar, ARFLAGS = ruv

AR             = ar
ARFLAGS        = ruv

# ranlib command. If ranlib is not needed (it isn't in most cases) use
# RANLIB = echo

RANLIB         = ranlib

# all internal and external libraries - do not modify

FLIB_TARGETS   = all

LIBXC_LIBS     = 
QELIBS         = $(LIBXC_LIBS) \
                 $(CUDA_LIBS) $(SCALAPACK_LIBS) $(LAPACK_LIBS) $(FOX_LIB) \
		 		 $(FFT_LIBS) $(BLAS_LIBS) $(MPI_LIBS) $(MASS_LIBS) $(HDF5_LIBS) \
			 	 $(ENVIRON_LIBS) $(LD_LIBS)

# wget or curl - useful to download from network
WGET = wget -O

# Install directory - "make install" copies *.x executables there
PREFIX = /usr/local
