# Makefile for testing code by comparing test output with sample output
# For wilson_static

# Tests only su3_static_mr and su3_sum (not su3_hev_cg)  CD 12/06/97

# Example: 
#    make check

# For comparing test output with sample output

# Instructions...
# 1.  Select the appropriate job launch command below.
# 2.  There should already be sample output files constructed from
#     code that you trust.
# 3.  Run the command
#        make -f Make_test test

# Change to suit...

# SGI Origin
#LAUNCH = mpirun -np 4
#LAUNCH2 = 

# T3E
#LAUNCH = mpprun -n 4
#LAUNCH2 = 

# Linux
#  MPICH
#LAUNCH = /uufs/icebox/sys/pkg/mpich/1.2.1/bin/mpirun -np 4 -machinefile $$PBS_NODEFILE
#  VMI
#LAUNCH = /usr/local/bin/vmi-launch -ncpus 8 --
#LAUNCH2 = 

# Compaq Alpha cluster (tcsini)
#LAUNCH = prun -N $$RMS_NODES -n $$RMS_PROCS # (tcsini)
#LAUNCH = prun -p test -B 1 -N 1 -n 4 # (CHPC sierra cluster - private node sierra1)
#LAUNCH2 =

# Scalar
LAUNCH =
LAUNCH2 = 

PATTERNS = Here END
TOL = 1e-5
OUTTEST = out.test.matrix
OUTSAMPLE = out.sample.matrix
BINTEST = bin.test.matrix
READMATRIX = read_matrix_code/look.${PREC}.x

${READMATRIX}: read_matrix_code/read_vary_matrix.c
	cd read_matrix_code; make look.${PREC}.x

${BINTEST}.su3_static_mr.1: su3_static_mr ${READMATRIX} in.sample.su3_static_mr.1
	${LAUNCH} ./su3_static_mr ${LAUNCH2} < in.sample.su3_static_mr.1 > out.test.su3_static_mr.1

${BINTEST}.su3_static_cg.1: su3_static_cg ${READMATRIX} in.sample.su3_static_cg.1
	${LAUNCH} ./su3_static_cg ${LAUNCH2} < in.sample.su3_static_cg.1 > out.test.su3_static_cg.1


${OUTTEST}.su3_static_mr.1: ${READMATRIX} ${BINTEST}.su3_static_mr.1 ${BINTEST}.su3_static_mr.1
	${READMATRIX} ${BINTEST}.su3_static_mr.1 > ${OUTTEST}.su3_static_mr.1
	/bin/rm ${BINTEST}.su3_static_mr.1

${OUTTEST}.su3_static_cg.1: ${READMATRIX} ${BINTEST}.su3_static_cg.1 ${BINTEST}.su3_static_cg.1
	${READMATRIX} ${BINTEST}.su3_static_cg.1 > ${OUTTEST}.su3_static_cg.1
	/bin/rm ${BINTEST}.su3_static_cg.1

out.test.diff.matrix.su3_static_mr.1:  ${OUTTEST}.su3_static_mr.1 ${OUTSAMPLE}.su3_static_mr.1
	perl ../headtail.pl ${PATTERNS} < ${OUTTEST}.su3_static_mr.1 > out.test.matrix.su3_static_mr.1.tmp
	perl ../headtail.pl ${PATTERNS} < ${OUTSAMPLE}.su3_static_mr.1 > out.sample.matrix.su3_static_mr.1.tmp
	perl ../diffn3.pl out.test.matrix.su3_static_mr.1.tmp out.sample.matrix.su3_static_mr.1.tmp out.errtol.matrix.su3_static_mr.1 > \
	   out.test.diff.matrix.su3_static_mr.1
#	rm out.test.matrix.su3_static_mr.1.tmp out.sample.matrix.su3_static_mr.1.tmp

out.test.diff.matrix.su3_static_cg.1:  ${OUTTEST}.su3_static_cg.1 ${OUTSAMPLE}.su3_static_cg.1
	perl ../headtail.pl ${PATTERNS} < ${OUTTEST}.su3_static_cg.1 > out.test.matrix.su3_static_cg.1.tmp
	perl ../headtail.pl ${PATTERNS} < ${OUTSAMPLE}.su3_static_cg.1 > out.sample.matrix.su3_static_cg.1.tmp
	perl ../diffn3.pl out.test.matrix.su3_static_cg.1.tmp out.sample.matrix.su3_static_cg.1.tmp out.errtol.matrix.su3_static_cg.1 > \
	   out.test.diff.matrix.su3_static_cg.1
#	rm out.test.matrix.su3_static_cg.1.tmp out.sample.matrix.su3_static_cg.1.tmp

test:
	${MAKE} su3_static_mr "PRECISION=1"
	${MAKE} -f Make_test out.test.diff.matrix.su3_static_mr.1 "PREC=1"
	${MAKE} su3_static_cg "PRECISION=1"
	${MAKE} -f Make_test out.test.diff.matrix.su3_static_cg.1 "PREC=1"

buildonly:
	${MAKE} su3_static_mr "PRECISION=1"
	${MAKE} su3_static_cg "PRECISION=1"

runonly:
	${MAKE} -f Make_test out.test.diff.matrix.su3_static_mr.1 "PREC=1"
	${MAKE} -f Make_test out.test.diff.matrix.su3_static_cg.1 "PREC=1"


check: test

clean: test_clean
