CC = mpicc
CFLAGS = -O2 -g -Wall
LDFLAGS = -lm
# This can be redefined to be heat-asynch
HEAT = heat

all: heat heat-asynch

heat: heat.c grid.c grid.h cycletimer.c cycletimer.h
	$(CC) $(CFLAGS) heat.c grid.c cycletimer.c -o heat $(LDFLAGS)

heat-asynch: heat.c grid.c grid.h cycletimer.c cycletimer.h
	$(CC) $(CFLAGS) -DASYNCH_RECV heat.c grid.c cycletimer.c -o heat-asynch $(LDFLAGS)


BPARAMS = -e 0.0001 -s 10000 -b h

bench-ghc: $(VERSION)
	# Benchmarking MPI performance
	# Scale number of processors
	mpirun -np 1 ./$(VERSION) $(BPARAMS) -n 800
	mpirun -np 2 ./$(VERSION) $(BPARAMS) -n 800
	mpirun -np 3 ./$(VERSION) $(BPARAMS) -n 800
	mpirun -np 4 ./$(VERSION) $(BPARAMS) -n 800
	mpirun -np 5 ./$(VERSION) $(BPARAMS) -n 800
	mpirun -np 6 ./$(VERSION) $(BPARAMS) -n 800
	mpirun -np 7 ./$(VERSION) $(BPARAMS) -n 800
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 800
	# Scale problem size
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 600
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 700
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 800
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 900
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 1000
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 1100
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 1200
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 1600
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 2000
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 2400
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 2800
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 3200
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 3600
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 4000
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 4400
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 4800
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 5200
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 5600
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 6000
	mpirun -np 8 ./$(VERSION) $(BPARAMS) -n 6400

mac:
	# This declaration may be required to run on MacOS
	export PMIX_MCA_gds=hash


clean:
	rm -f *~
	rm -rf *.dSYM
	rm -f heat heat-asynch
