#
#  This makefile is currently set up to be used with the "run" csh
#  script.  It can also be modified and used directly.  To do this
#  you will need to: 
#
#  1. Add any local flags to HPFFLAGS,
#  2. Define SYS (to "sgi", "pgn", or some target-specific extension)
#  3. Define RUN if necessary (i.e. to use "prun" or "mpirun")
#  4. Define RUNFLAGS if necessary (i.e. to specify # procs to use)
#  5. Define the run line under "$(SYS)_run" target appropriately.  The 
#     commented run line should work for standard pghpf environments
#     if the previous definitions are all in place.  An appropriate
#     permutation thereof must be used to satisfy the order-of-args
#     requirements for explicit run commands such as prun and mpirun.
#
#  The size of the problem to be run can be modified to 64, 256, 512
#  or 1024.  This can be done on the make line with a SIZE=n macro
#  def'n where "n" is one of the available sizes.
#
#  A simple way of running on multiple configurations is to define
#  the desired configurations under the "$(SYS)_time" target, define
#  appropriate new make rules similar to those provided for 1 and 2 
#  processors, and then make "sgi_time", "pgn_time", or whatever is
#  the appropriate target.
#
.f.o:
	$(FC) $(FFLAGS) -c $<

.s.o:
	$(AS) $(AFLAGS) -o $@ $<

HPF      = pghpf
HPFFLAGS = $(EXTRA_HPFFLAGS)
F77      = pgf77
FFLAGS   = -O
CC       = cc
CFLAGS   = -O
LDFLAGS  = $(EXTRA_LDFLAGS)

SYS      = linux
RUN      = /u1/local/mpich-1.2.5/bin/mpirun
RUNARG   = -pghpf -np 8 -host cp0-7,cp0-2,cp0-3,cp0-4,cp0-5,cp0-6 -stat alls
RUNFLAGS =

PROG     = pde1_$(SYS)
HOBJS    = pde1_$(SYS).o \
           header_$(SYS).o \
           prtres_$(SYS).o \
           setdat_$(SYS).o \
           setdtl_$(SYS).o \
           timer_$(SYS).o

SIZE      = 64
NP        = 1

TIME=/usr/bin/time
DIFF=spiff -P -q -r0.05
RM=rm -f
RESULTDIR = .
REFDIR = result.ref

$(SYS)_test: $(PROG) $(SYS)_run # $(SYS)_verify

pde1_$(SYS).o: pde1.F pde1.$(SIZE).inc
	cp pde1.$(SIZE).inc pde1.inc
	$(HPF) $(HPFFLAGS) -c -o pde1_$(SYS).o pde1.F

header_$(SYS).o: header.F
	$(HPF) $(HPFFLAGS) -c -o header_$(SYS).o header.F

prtres_$(SYS).o: prtres.F
	$(HPF) $(HPFFLAGS) -c -o prtres_$(SYS).o prtres.F

setdat_$(SYS).o: setdat.F
	$(HPF) $(HPFFLAGS) -c -o setdat_$(SYS).o setdat.F

setdtl_$(SYS).o: setdtl.F
	$(HPF) $(HPFFLAGS) -c -o setdtl_$(SYS).o setdtl.F

timer_$(SYS).o: timer.F
	$(HPF) $(HPFFLAGS) -c -o timer_$(SYS).o timer.F

$(PROG): $(HOBJS)
	$(HPF) $(LDFLAGS) -o $@ $(HOBJS)

#$(SYS)_verify:
#	-$(DIFF) $(REFDIR)/result.out $(RESULTDIR)/result.out 

$(SYS)_run: $(PROG)
	-$(RM) result.out
	$(TIME) $(RUN) $(PROG) $(RUNARG) $(RUNFLAGS)
#	$(TIME) $(RUNLINE)

$(SYS)_time: pde1.$(SYS).$(SIZE).2 \
             pde1.$(SYS).$(SIZE).1

pde1.$(SYS).$(SIZE).1 : pde1_$(SYS)
	$(RUN) pde1_$(SYS) -pghpf -np 1 -stat cpu
	mv result.out pde1.$(SYS).$(SIZE).1
 
pde1.$(SYS).$(SIZE).2 : pde1_$(SYS)
	$(RUN) pde1_$(SYS) -pghpf -np 2 -stat cpu
	mv result.out pde1.$(SYS).$(SIZE).2
clean:
	$(RM) *.o *.out core pde1_* result
