#######################################################################
# Author: David Goz (david.goz@inaf.it)                               #
# June  2024                                                          #
#######################################################################
#
# To see all the compilation options
# $ make info
#######################################################################

# make.def defines how the application is compiled
include make.def
include make_mpi_path
#######################################################################

.PHONY: info mpi debug valgrind_memcheck valgrind_callgrind valgrind_cachegrind clean

info:
	@echo ' '
	@echo '-----------------------------------------------------------------------------------------'
	@echo '$$ make mpi                 ---> compile the mpi application                             '
	@echo '$$ make debug               ---> compile the mpi application for debugger                '
	@echo '$$ make valgrind_memcheck   ---> run the mpi application using Valgrind under Memcheck   '
	@echo '$$ make valgrind_callgrind  ---> run the mpi application using Valgrind under Callgrind  '
	@echo '$$ make valgrind_cachegrind ---> run the mpi application using Valgrind under Cachegrind '
	@echo '$$ make clean               ---> clean up all                                            '
	@echo '$$ make info                ---> get make info                                           '
	@echo '-----------------------------------------------------------------------------------------'
	@echo ' '

mpi: $(PROG)

debug: $(PROG_DEBUG)

valgrind_memcheck: $(PROG_MEMCHECK)
	@echo 'oooOOO... valgrind_memcheck ...OOOooo'
	mpirun -n 2 valgrind --tool=memcheck -s --default-suppressions=yes --log-file=valgrind_memcheck_log_%p.txt ./$< 5 5
	@echo 'oooOOO... valgrind_memcheck ...OOOooo'

valgrind_callgrind: $(PROG_CALLGRIND)
	@echo 'oooOOO... valgrind_callgrind ...OOOooo'
	mpirun -n 2 valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes --log-file=valgrind_callgrind_log_.%p.txt ./$< 128 128
	@echo ' '
	@echo 'To generate a function-by-function summary from the profile data file:'
	@echo '$$ callgrind_annotate --auto=yes callgrind.out.<pid> | less'
	@echo '(kcachegrind is required in order to visualize the output using the GUI)'

valgrind_cachegrind: $(PROG_CACHEGRIND)
	@echo 'oooOOO... valgrind_cachegrind ...OOOooo'
	mpirun -n 2 valgrind --tool=cachegrind --log-file=valgrind_cachegrind_log_.%p.txt ./$< 128 128
	@echo '$$ cg_annotate --auto=yes cachegrind.out.<pid> | less'
	@echo '(kcachegrind is required in order to visualize the output using the GUI)'
	@echo 'oooOOO... valgrind_cachegrind ...OOOooo'

clean:
	rm -f *~ .*~ ./src/*~ ./src/*# ./include/*~ ./include/*# *~
	rm -f $(PROG) $(PROG_DEBUG) $(PROG_MEMCHECK) $(PROG_CALLGRIND) $(PROG_CACHEGRIND)
	rm -f valgrind_*.txt
	rm -f cachegrind.out.*
	rm -f callgrind.*
	rm -f *bin
	rm -f jacobi_mpi_SendRecv_*
