# Makefile to compile a parallel Jacobi solver for the Laplacian equation in 2D
# Makefile written by A. Pedrono, H. Neau, P Elyakime and E. Courcelle 
# (IMFT, INPT, CNRS, CALMIP)
# The Makefile variable VISIT enables compilation with VisIt. 
# Otherwise, the program will be compiled in stand-alone mode.

# At IMFT, BEFORE calling make, you can initialize the environment with:
# module purge
# module load mpich/3.2.0/gcc-5.4
# source ../../visit_GUI.sh
# or 
# module purge
# module load openmpi/1.10.3/gcc-5.4 
# source ../../visit_GUI.sh

# On Eos, BEFORE calling make, you can initialize the environment with:
# module purge
# module load intel/17.0.4 intelmpi/5.1.3.210
# if you need VisIt in batch mode please use:
# module load visit/vbatch-2.12.3
# The visit module define the variable VISIT_DIR
# On Eos, please use the following lines: 
# FC = mpiifort 
# INCLUDE = 

# Or using gfortran on your machine:
FC = mpif90  
#
#OPT = -g -O0 
OPT = 

# To compile with visit: 
# 1/ Initiate the environment with .visit_batch.sh, (on Eos: module load visit/vbatch-2.10.2)
# 2/ Decomment the following line:
VISIT = 1

EXE = pjacobi  

ifeq ($(VISIT),1)

  DEFINE = -D_VISIT_ 

#  VISIT_DIR = /PRODCOM/VISIT/visit2_12_0.linux-x86_64_wmesa/2.12.0
  VISIT_DIR = /PRODCOM/VISIT/visit2_13_mpi_compile_u16/2.13.0
  VISIT_INCDIR = -I$(VISIT_DIR)/linux-x86_64/libsim/V2/include
  VISIT_INCLUDE = $(VISIT_INCDIR) 

  VISIT_LIBS = -L$(VISIT_DIR)/linux-x86_64/libsim/V2/lib -lsimV2 -lsimV2f -lstdc++ -Wl,--no-as-needed -ldl
  LIBS = $(VISIT_LIBS)


  SRC  = jacobi_module.f90 pjacobi.f90 simulationexamplev2.f PJacobi_Visit.f
  OBJS = jacobi_module.o pjacobi.o simulationexamplev2.o PJacobi_Visit.o 

else
  SRC  = jacobi_module.f90 pjacobi.f90
  OBJS = jacobi_module.o pjacobi.o 

endif

$(EXE):	$(OBJS)
	$(FC) $(OPT) $(OBJS) $(VISIT_INCLUDE) $(LIBS) -o $(EXE)
	
jacobi_module.o:	jacobi_module.f90
	$(FC) $(OPT) $(VISIT_INCLUDE) $(DEFINE) jacobi_module.f90 -c -cpp
	
pjacobi.o:	pjacobi.f90
	$(FC) $(OPT) $(VISIT_INCLUDE) $(DEFINE) pjacobi.f90 -c -cpp
	
simulationexamplev2.o:	simulationexamplev2.f
	$(FC) $(OPT) $(VISIT_INCLUDE)  simulationexamplev2.f -c

PJacobi_Visit.o:		PJacobi_Visit.f
	$(FC) $(OPT) $(VISIT_INCLUDE)  PJacobi_Visit.f -c

clean :
	/bin/rm -f $(OBJS) *.mod $(EXE)
