# Makefile for timing and testing of parallel matrix multiplication (and addition).
# Sets compiler and linker parameters.
# Compiles source code and links objects to generate executable files:
# mmultmp and mmultstp.
# Cleans object and executable files in current directory.

# Hardware specifications
PROC = Intel Xeon 5345
CORES = 4 x dual-core
CLKSPEED = 2.33 GHz
CACHE = 4096 KB per dual-core

# Compiler options
CC = /usr/mpi/intel/mvapich-1.1.0/bin/mpicc
LANGUAGE = -x c++
OPTM = -O3

CFLAGS = -Wall $(LANGUAGE) $(OPTM)
CPPFLAGS = -I$(includedir)
CPPFLAGS +=	"-DCOMPILER=\"$(CC)\"" "-DLANGUAGE=\"$(LANGUAGE)\"" \
	"-DOPTM=\"$(OPTM)\"" "-DPROC=\"$(PROC)\"" "-DCORES=\"$(CORES)\"" \
	"-DCLKSPEED=\"$(CLKSPEED)\"" "-DCACHE=\"$(CACHE)\"" \
	"-DDATADIR=\"$(DATADIR)\""

LDFLAGS = -shared-intel
LIBS = -lm -lrt -lstdc++

prefix = /scratch/st1185
projectdir = $(prefix)
sourcedir = $(projectdir)/source
includedir = $(projectdir)/include
DATADIR = $(projectdir)/data
VPATH = $(sourcedir) $(includedir) $(datadir)

objects1 = mmultmp.o matmultp.o timing.o
objects2 = mmultstp.o matmultp.o
objects = $(objects1) $(objects2)
sources = $(objects:.o=.c)

.PHONY: all
all: mmultmp mmultstp

mmultmp: $(objects1)
mmultmp.o: matmultp.h timing.h
matmultp.o: matmultp.h
timing.o: timing.h

mmultstp: $(objects2)
mmultstp.o: matmultp.h
matmultp.o: matmultp.h

# Pattern rules
%: %.o
	$(CC) $^ $(LDFLAGS) $(LIBS) -o $@
%.o: %.c
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

.PHONY:	cleanall cleanobj
cleanall: cleanobj
	rm -f mmultmp mmultstp
cleanobj: 
	rm -f *.o
