Makefile

#key parameters:
OPENMP=y
PETSC=y
HDF5=y
COMPILER=default
GPU=n
CMD := G2C3
ALL:${CMD}
LIB :=
LD_LIB :=


#------------------------------------------------------

SCRATCH_PATH := /scratch/scratch_run/akuley_ext/Jaya/G2C3/ScratchVer1.0/
CODE_PATH := $(pwd)

#----- inquire the hostname to judge the system name, to determine what target we're compiling on

ifneq (,${HOST})
   SYSTEMS := ${HOST}
  else
   SYSTEMS := $(shell hostname)
endif

#------------------------------------------------------

$(info                                 )
$(info |                               ) 
$(info |     ┏┓┏┓┏┓┏┓                  )
$(info |     ┃┓┏┛┃  ┫   (Ver1.0, 2024) )
$(info |     ┗┛┗━┗┛┗┛                  )
$(info |                               )

#------------------------------------------------------

#----- target machine determines the default compiler, and paths to libraries -----#

#------------- ANTYA

ifneq (,$(findstring login1,$(SYSTEMS)) || $(findstring login2,$(SYSTEMS)))

   ifeq ($(OPENMP),y)
      OPT += -qopenmp
   endif

   ifeq ($(PETSC),y)
      PETSC_HOME=/home/application/petsc/3.8.4
      LIB += -I$(PETSC_HOME)/include -L$(PETSC_HOME)/lib  
      OPT += -static-intel -lpetsc
   endif

   ifeq ($(HDF5),y)
      HDF5_HOME=/home/application/HDF5_P_Intel/1.10.5
      LIB += -I$(HDF5_HOME)/include -L$(HDF5_HOME)/lib
      OPT += -lhdf5_fortran -lhdf5 -lz -lm 
   endif

   CMP := mpiifort 

   OPT += -no-wrap-margin
   OPT += -warn unused

   JOB_RUN := qsub
   JOB_FILE := ./job/jobscript_ANTYA
   JOB_STATUS := qstat
   
endif


#------------- PTG

ifneq (,$(findstring ptg,$(SYSTEMS)))

   ifeq ($(PETSC),y)
      PETSC_solver ?= petsc.o
      PETSC_OPT += -D_PETSc -D_USING_EXT_SOLVER -lpetsc
      OPT += $(PETSC_OPT)
      PETSC_HOME=/exports/apps/installed/spack/opt/spack/linux-rocky8-zen/gcc-8.5.0/petsc-3.18.1-xeuns4w5kms5jertyhfmlqwtmlmyhw3m
      LIB += -I$(PETSC_HOME)/include -L$(PETSC_HOME)/lib
      LD_LIB += $(PETSC_LD_LIB) -L$(PETSC_HOME)/lib
   else
      PETSC_solver :=
   endif

   OMPOPT := -fopenmp

   ifeq ($(OPENMP),y)
      OPT += $(OMPOPT)
      COPT += $(OMPOPT)
   endif

   CMP := mpifort 

   JOB_RUN := sbatch
   JOB_FILE := ./job/jobscript_PTG
   JOB_STATUS := squeue

endif


#-----------------------------------------------------

SRC := ./src
OBJ := ./obj

#### compilation ####

#------------------------------------------------------
# ---------- Ordered based on dependencies

OBJFILES := 	$(OBJ)/module.o \
		$(OBJ)/petsc.o \
		$(OBJ)/h5_write.o \
		$(OBJ)/write_data.o \
		$(OBJ)/mpi.o \
		$(OBJ)/allocate_arrays.o \
		$(OBJ)/read_data.o \
		$(OBJ)/normalize.o \
		$(OBJ)/function.o \
		$(OBJ)/mesh.o \
		$(OBJ)/neural_network.o \
		$(OBJ)/check_zone.o \
		$(OBJ)/maps.o \
		$(OBJ)/gather_scatter.o \
		$(OBJ)/gc_pushi.o \
		$(OBJ)/shifti.o \
		$(OBJ)/loadi.o \
		$(OBJ)/fem.o \
		$(OBJ)/parallel_gradient.o \
		$(OBJ)/initialize_arrays.o \
		$(OBJ)/setup.o \
		$(OBJ)/main.o

#		$(OBJ)/petsc.o \
#		$(OBJ)/initial_data_dump.o \
#		$(OBJ)/write_data.o \
#		$(OBJ)/initial.o \
#		$(OBJ)/function.o \
#		$(OBJ)/interface.o \
#		$(OBJ)/loadprofile.o \
#		$(OBJ)/eqdata.o \
#	        $(OBJ)/eqplot.o \
#		$(OBJ)/domain.o \
#		$(OBJ)/field_lines.o \
#		$(OBJ)/estimate_thetafgrid.o \
#		$(OBJ)/poloidal_grid.o \
#		$(OBJ)/NN_Predictor.o \
#		$(OBJ)/check_zone.o \
#		$(OBJ)/maps.o \
#		$(OBJ)/gather_scatter.o \
#		$(OBJ)/gc_pushi.o \
#        	$(OBJ)/shifti.o \
#        	$(OBJ)/loadi.o \
#		$(OBJ)/estimate_volume.o \
#		$(OBJ)/poisson_solver.o \
#		$(OBJ)/parallel_gradient.o \
#		$(OBJ)/setup.o \
#		$(OBJ)/main.o


#--------------------------------------------------------------------


$(CMD): $(OBJFILES)
		$(CMP) -o $(CMD) $(OBJFILES) $(LIB) $(OPT)


#--------------------------------------------------------------------


$(OBJ)/main.o: $(SRC)/main.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/main.F90                $(LIB) $(OPT) -o $(OBJ)/main.o

$(OBJ)/mpi.o: $(SRC)/mpi.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/mpi.F90		$(LIB) $(OPT) -o $(OBJ)/mpi.o

$(OBJ)/allocate_arrays.o: $(SRC)/allocate_arrays.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/allocate_arrays.F90	$(LIB) $(OPT) -o $(OBJ)/allocate_arrays.o

$(OBJ)/module.o: $(SRC)/module.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/module.F90              $(LIB) $(OPT) -o $(OBJ)/module.o

$(OBJ)/normalize.o: $(SRC)/normalize.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/normalize.F90		$(LIB) $(OPT) -o $(OBJ)/normalize.o

$(OBJ)/initialize_arrays.o: $(SRC)/initialize_arrays.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/initialize_arrays.F90	$(LIB) $(OPT) -o $(OBJ)/initialize_arrays.o

$(OBJ)/write_data.o: $(SRC)/write_data.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/write_data.F90          $(LIB) $(OPT) -o $(OBJ)/write_data.o

$(OBJ)/h5_write.o: $(SRC)/h5_write.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/h5_write.F90		$(LIB) $(OPT) -o $(OBJ)/h5_write.o

$(OBJ)/read_data.o: $(SRC)/read_data.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/read_data.F90          $(LIB) $(OPT) -o $(OBJ)/read_data.o

$(OBJ)/eq_b.o: $(SRC)/eq_b.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/eq_b.F90		$(LIB) $(OPT) -o $(OBJ)/eq_b.o

$(OBJ)/function.o: $(SRC)/function.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/function.F90		$(LIB) $(OPT) -o $(OBJ)/function.o

$(OBJ)/interpolate.o: $(SRC)/interpolate.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/interpolate.F90	$(LIB) $(OPT) -o $(OBJ)/interpolate.o

$(OBJ)/initial.o: $(SRC)/initial.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/initial.F90             $(LIB) $(OPT) -o $(OBJ)/initial.o

$(OBJ)/interface.o: $(SRC)/interface.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/interface.F90           $(LIB) $(OPT) -o $(OBJ)/interface.o

$(OBJ)/eqdata.o: $(SRC)/eqdata.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/eqdata.F90              $(LIB) $(OPT) -o $(OBJ)/eqdata.o

$(OBJ)/loadprofile.o: $(SRC)/loadprofile.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/loadprofile.F90         $(LIB) $(OPT) -o $(OBJ)/loadprofile.o

$(OBJ)/eqplot.o: $(SRC)/eqplot.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/eqplot.F90              $(LIB) $(OPT) -o $(OBJ)/eqplot.o

$(OBJ)/domain.o: $(SRC)/domain.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/domain.F90              $(LIB) $(OPT) -o $(OBJ)/domain.o

$(OBJ)/field_lines.o: $(SRC)/field_lines.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/field_lines.F90         $(LIB) $(OPT) -o $(OBJ)/field_lines.o

$(OBJ)/poloidal_grid.o: $(SRC)/poloidal_grid.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/poloidal_grid.F90       $(LIB) $(OPT) -o $(OBJ)/poloidal_grid.o

$(OBJ)/mesh.o: $(SRC)/mesh.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/mesh.F90		$(LIB) $(OPT) -o $(OBJ)/mesh.o

$(OBJ)/gc_pushi.o: $(SRC)/gc_pushi.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/gc_pushi.F90            $(LIB) $(OPT) -o $(OBJ)/gc_pushi.o

$(OBJ)/loadi.o: $(SRC)/loadi.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/loadi.F90               $(LIB) $(OPT) -o $(OBJ)/loadi.o

$(OBJ)/setup.o: $(SRC)/setup.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/setup.F90               $(LIB) $(OPT) -o $(OBJ)/setup.o

$(OBJ)/shifti.o: $(SRC)/shifti.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/shifti.F90              $(LIB) $(OPT) -o $(OBJ)/shifti.o

$(OBJ)/fem.o: $(SRC)/fem.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/fem.F90		$(LIB) $(OPT) -o $(OBJ)/fem.o

$(OBJ)/parallel_gradient.o: $(SRC)/parallel_gradient.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/parallel_gradient.F90	$(LIB) $(OPT) -o $(OBJ)/parallel_gradient.o

$(OBJ)/maps.o: $(SRC)/maps.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/maps.F90		$(LIB) $(OPT) -o $(OBJ)/maps.o

$(OBJ)/gather_scatter.o: $(SRC)/gather_scatter.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/gather_scatter.F90      $(LIB) $(OPT) -o $(OBJ)/gather_scatter.o

$(OBJ)/check_zone.o: $(SRC)/check_zone.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/check_zone.F90          $(LIB) $(OPT) -o $(OBJ)/check_zone.o

$(OBJ)/neural_network.o: $(SRC)/neural_network.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/neural_network.F90	$(LIB) $(OPT) -o $(OBJ)/neural_network.o

$(OBJ)/estimate_thetafgrid.o: $(SRC)/estimate_thetafgrid.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/estimate_thetafgrid.F90 $(LIB) $(OPT) -o $(OBJ)/estimate_thetafgrid.o

$(OBJ)/estimate_volume.o: $(SRC)/estimate_volume.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/estimate_volume.F90     $(LIB) $(OPT) -o $(OBJ)/estimate_volume.o

$(OBJ)/initial_data_dump.o: $(SRC)/initial_data_dump.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/initial_data_dump.F90	$(LIB) $(OPT) -o $(OBJ)/initial_data_dump.o

$(OBJ)/petsc.o: $(SRC)/petsc.F90
		$(CMP) -module $(OBJ)/ -c $(SRC)/petsc.F90               $(LIB) $(OPT) -o $(OBJ)/petsc.o




#------------------------------------------------------------------------

sc:
	@cp -rf * /scratch/scratch_run/akuley_ext/Jaya/G2C3/ScratchVer1.0/
	@echo "Copied files to $(SCRATCH_PATH)"
	@echo " "

clean:
	@rm -f G2C3 ./obj/* ./output/* *.o* *.e* fort.*
	@echo "Files cleaned..."
	@echo " "

run:
	$(JOB_RUN) $(JOB_FILE)

status:
	$(JOB_STATUS)