################################################################
# Makefile for ParPre demos.
#
# make sure you suppply the following:
MACH_FILE = mf
# give the debugger time to attach
DEBUGGER_PAUSE = 40
#
# the problem size and type are hard-coded in the mat.c file
#
################################################################

# default production: helpful information
default help info all:
	@echo " "
	@echo "Type: make <method>"
	@echo "where <method> stands for any of:"
	@echo "   none, jacobi, aschwarz, mschwarz, domdec, gbssor"
	@echo "at present."
	@echo
	@echo "Also possible: make OPTIONS=<options> <method>"
	@echo "where <options> can be found in the manual."
	@echo
	@echo "Make sure you have an mpi machine file called" $(MACH_FILE)
	@echo

NP = 2
domdec_OPTIONS  =       -interface_pc_type addschwarz -interface_sub_pc_type lu -sub_pc_type ilu
gbssor_OPTIONS  =       -sub_pc_type sor -sub_pc_sor_symmetric \
	                -sub_pc_sor_its 1 \
			-pc_pipeline none
mlevel_OPTIONS = 	-multilevel_solutionscheme lu \
			-multilevel_fillmethod none
# \
			-presmoother_pc_type jacobi \
			-postsmoother_pc_type jacobi
#mlevel_OPTIONS =	-multilevel_solutionscheme mg \
			-multilevel_fillmethod none \
			-presmoother_pc_type jacobi \
			-postsmoother_pc_type jacobi
aschwarz_OPTIONS =      -pc_halo_size 1 -sub_pc_type ilu -sub_pc_ilu_levels 3
mschwarz_OPTIONS =      -pc_halo_size 1 -sub_pc_type ilu

none jacobi gbssor aschwarz mschwarz domdec mlevel tinker: \
	        test_main.o mat.o cg.o $$@.o
	make METH=$@ OPTIONS="$(OPTIONS)" NP=$(NP) \
		PETSC_OPTIONS="$(PETSC_OPTIONS)" MPI_OPTIONS="$(MPI_OPTIONS)" \
		$@_OPTIONS='$($(@)_OPTIONS)' run

none_debug gbssor_debug aschwarz_debug mschwarz_debug domdec_debug mlevel_debug: test_main.o mat.o cg.o $${@:_debug=}.o
	@make METH=${@:_debug=} NP=$(NP) \
		PETSC_OPTIONS="$(PETSC_OPTIONS)" MPI_OPTIONS="$(MPI_OPTIONS)" \
		$@_OPTIONS='$(${@:_debug=}_OPTIONS)' \
		DEBUG="-start_in_debugger gdb -debugger_pause $(DEBUGGER_PAUSE)" \
		run


run:
	@echo "*******************************"
	@echo "A simple test of $(NP) processor cg"
#	@echo "*******************************"
	-$(FLINKER)  -o test test_main.o cg.o $(METH).o mat.o \
	        $(PARPRE_LIB)
#		$(PETSC_LIB)
	chmod 755 test
	@echo ; echo "Ah! " $(METH) "!" ; echo ;
	mpirun -np $(NP) -machinefile mf $(MPI_OPTIONS) \
	  $(PARPRE_DIR)/Examples/test \
	    $($(METH)_OPTIONS) -optionsleft $(DEBUG) $(PETSC_OPTIONS)

clean_examples:
	rm -f *~ *.o prec.* test mf PI*

include $(PARPRE_DIR)/bmake/parpre_base
