# MODIFY THESE PARAMETERS TO OPTIMIZE THE CALCULATION:
KMP_AFFINITY=compact,1

# END OF PARAMETERS TO MODIFY
CXX = icpc
CXXFLAGS=-qopenmp -mkl
CPUFLAGS = $(CXXFLAGS) -xhost
OPTFLAGS = -qopt-report -qopt-report-file=$@.optrpt

CPUOBJECTS = dgemm.o

TARGET=dgemm-CPU
CXX=icpc

.SUFFIXES: .o .cc

all: $(TARGET) instructions

%-CPU: $(CPUOBJECTS)
	$(info )
	$(info Linking the CPU executable:)
	$(CXX) $(CPUFLAGS) -o $@ $(CPUOBJECTS)

.cc.o:
	$(info )
	$(info Compiling a CPU object file:)
	$(CXX) -c $(CPUFLAGS) $(OPTFLAGS) -o "$@" "$<"

instructions: 
	$(info Execute )
	$(info        make run-c-AO )
	$(info        make run-R-AO )

run-c: dgemm-CPU
	OMP_NUM_THREADS=`lscpu --parse=CORE | grep -v "\#" | sort | uniq | wc -l` KMP_AFFINITY=compact,1 ./dgemm-CPU

run-R:
	OMP_NUM_THREADS=`lscpu --parse=CORE | grep -v "\#" | sort | uniq | wc -l` KMP_AFFINITY=compact,1 R -q -f ./dgemm.R

run-c-AO: dgemm-CPU
	OMP_NUM_THREADS=`lscpu --parse=CORE | grep -v "\#" | sort | uniq | wc -l` KMP_AFFINITY=compact,1 MKL_MIC_ENABLE=1 MIC_ENV_PREFIX=MIC MIC_KMP_PLACE_THREADS=4t MIC_KMP_AFFINITY=compact ./dgemm-CPU

run-R-AO:
	OMP_NUM_THREADS=`lscpu --parse=CORE | grep -v "\#" | sort | uniq | wc -l` KMP_AFFINITY=compact,1 MKL_MIC_ENABLE=1 MIC_ENV_PREFIX=MIC MIC_KMP_PLACE_THREADS=4t MIC_KMP_AFFINITY=compact R -q -f ./dgemm.R

clean: 
	rm -f $(CPUOBJECTS) $(TARGET) *.optrpt

