CC=gcc
CFLAGS = -O2 -g -Wall
LDFLAGS = -lm

BPARAMS = -e 0.0001 -s 10000 -b h

all: heat heat-omp

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

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

grid.s: grid.c
	$(CC) $(CFLAGS) -S grid.c


bench-seq: heat
	# Benchmarking sequential performance
	./heat $(BPARAMS)

bench-ghc: heat-omp
	# Sequential performance (2x)
	./heat $(BPARAMS) -n 800
	./heat $(BPARAMS) -n 800
	# Benchmarking Open MP performance
	# Scale number of threads
	./heat-omp $(BPARAMS) -t 1 -n 800
	./heat-omp $(BPARAMS) -t 2 -n 800
	./heat-omp $(BPARAMS) -t 3 -n 800
	./heat-omp $(BPARAMS) -t 4 -n 800
	./heat-omp $(BPARAMS) -t 5 -n 800
	./heat-omp $(BPARAMS) -t 6 -n 800
	./heat-omp $(BPARAMS) -t 7 -n 800
	./heat-omp $(BPARAMS) -t 8 -n 800
	# Scale problem size
	./heat-omp $(BPARAMS) -t 8 -n 600
	./heat-omp $(BPARAMS) -t 8 -n 700
	./heat-omp $(BPARAMS) -t 8 -n 800
	./heat-omp $(BPARAMS) -t 8 -n 900
	./heat-omp $(BPARAMS) -t 8 -n 1000
	./heat-omp $(BPARAMS) -t 8 -n 1100
	./heat-omp $(BPARAMS) -t 8 -n 1200
	./heat-omp $(BPARAMS) -t 8 -n 1600
	./heat-omp $(BPARAMS) -t 8 -n 2000
	./heat-omp $(BPARAMS) -t 8 -n 2400
	./heat-omp $(BPARAMS) -t 8 -n 2800
	./heat-omp $(BPARAMS) -t 8 -n 3200
	./heat-omp $(BPARAMS) -t 8 -n 3600
	./heat-omp $(BPARAMS) -t 8 -n 4000
	./heat-omp $(BPARAMS) -t 8 -n 4400
	./heat-omp $(BPARAMS) -t 8 -n 4800
	./heat-omp $(BPARAMS) -t 8 -n 5200
	./heat-omp $(BPARAMS) -t 8 -n 5600
	./heat-omp $(BPARAMS) -t 8 -n 6000
	./heat-omp $(BPARAMS) -t 8 -n 6400


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