COMBBLAS = ..
COMBBLAS_INC = $(COMBBLAS)/include/CombBLAS
COMBBLAS_SRC = $(COMBBLAS)/src
INCADD = -I$(COMBBLAS)/include/ -I$(COMBBLAS)/psort-1.0/include/ -I$(COMBBLAS)/usort/include/ -I$(COMBBLAS)/graph500-1.2/generator/include/ 

OPT = -O3 -DMPICH_IGNORE_CXX_SEEK #-DNDEBUG (disables important assertions)
DEB = -g -O0 -fno-inline -DMPICH_IGNORE_CXX_SEEK -DCOMBBLAS_DEBUG
COMPILER = mpicxx -cxx=g++-9 -std=c++14 -DTHREADED -fopenmp
FLAGS = $(OPT) -Wall -Wno-maybe-uninitialized 

#
# build Graph500 generator
#
$(COMBBLAS)/graph500-1.2/generator/libgraph_generator_seq.a:
	$(MAKE) -C $(COMBBLAS)/graph500-1.2/generator

CommGrid.o:	$(COMBBLAS_SRC)/CommGrid.cpp $(COMBBLAS_INC)/CommGrid.h
	$(COMPILER) $(INCADD) $(FLAGS) -c -o CommGrid.o $(COMBBLAS_SRC)/CommGrid.cpp 

mmio.o: $(COMBBLAS_SRC)/mmio.c
	mpicc -cc=gcc $(INCADD) $(FLAGS) -c -o mmio.o $(COMBBLAS_SRC)/mmio.c

MPIType.o:	$(COMBBLAS_SRC)/MPIType.cpp $(COMBBLAS_INC)/MPIType.h
	$(COMPILER) $(INCADD) $(FLAGS) -c -o MPIType.o $(COMBBLAS_SRC)/MPIType.cpp 

MemoryPool.o:	$(COMBBLAS_SRC)/MemoryPool.cpp $(COMBBLAS_INC)/SpDefs.h
	$(COMPILER) $(INCADD) $(FLAGS) -c -o MemoryPool.o $(COMBBLAS_SRC)/MemoryPool.cpp 

hash.o:	$(COMBBLAS_SRC)/hash.cpp $(COMBBLAS_INC)/hash.hpp
	$(COMPILER) $(FLAGS) $(INCADD) -c -o hash.o $(COMBBLAS_SRC)/hash.cpp

TransposeTest.o: TransposeTest.cpp $(COMBBLAS_INC)/SpDCCols.cpp $(COMBBLAS_INC)/dcsc.cpp $(COMBBLAS_INC)/SpHelper.h $(COMBBLAS_INC)/SpParHelper.h $(COMBBLAS_INC)/SpParMat.cpp $(COMBBLAS_INC)/Friends.h $(COMBBLAS_INC)/ParFriends.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o TransposeTest.o TransposeTest.cpp

IteratorTest.o: IteratorTest.cpp $(COMBBLAS_INC)/SpDCCols.cpp $(COMBBLAS_INC)/dcsc.cpp $(COMBBLAS_INC)/SpHelper.h $(COMBBLAS_INC)/SpParHelper.h $(COMBBLAS_INC)/SpParMat.cpp $(COMBBLAS_INC)/Friends.h $(COMBBLAS_INC)/ParFriends.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o IteratorTest.o IteratorTest.cpp

MultTest.o: MultTest.cpp $(COMBBLAS_INC)/SpDCCols.cpp $(COMBBLAS_INC)/dcsc.cpp $(COMBBLAS_INC)/SpHelper.h $(COMBBLAS_INC)/SpParHelper.h $(COMBBLAS_INC)/SpParMat.cpp $(COMBBLAS_INC)/Friends.h $(COMBBLAS_INC)/ParFriends.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o MultTest.o MultTest.cpp

MultTiming.o: MultTiming.cpp $(COMBBLAS_INC)/SpDCCols.cpp $(COMBBLAS_INC)/dcsc.cpp $(COMBBLAS_INC)/SpHelper.h $(COMBBLAS_INC)/SpParHelper.h $(COMBBLAS_INC)/SpParMat.cpp $(COMBBLAS_INC)/Friends.h $(COMBBLAS_INC)/ParFriends.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o MultTiming.o MultTiming.cpp

ReduceTest.o: ReduceTest.cpp $(COMBBLAS_INC)/SpDCCols.cpp $(COMBBLAS_INC)/dcsc.cpp $(COMBBLAS_INC)/SpHelper.h $(COMBBLAS_INC)/SpParHelper.h $(COMBBLAS_INC)/SpParMat.cpp $(COMBBLAS_INC)/Friends.h $(COMBBLAS_INC)/ParFriends.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o ReduceTest.o ReduceTest.cpp

VectorIndexing.o: VectorIndexing.cpp $(COMBBLAS_INC)/FullyDistSpVec.cpp $(COMBBLAS_INC)/FullyDistVec.cpp $(COMBBLAS_INC)/FullyDistSpVec.h $(COMBBLAS_INC)/FullyDistVec.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o VectorIndexing.o VectorIndexing.cpp

VectorIO.o: VectorIOPermute.cpp $(COMBBLAS_INC)/FullyDistSpVec.cpp $(COMBBLAS_INC)/FullyDistVec.cpp $(COMBBLAS_INC)/FullyDistSpVec.h $(COMBBLAS_INC)/FullyDistVec.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o VectorIO.o VectorIO.cpp


SplitMergeTest.o: SplitMergeTest.cpp $(COMBBLAS_INC)/FullyDistSpVec.cpp $(COMBBLAS_INC)/FullyDistVec.cpp $(COMBBLAS_INC)/FullyDistSpVec.h $(COMBBLAS_INC)/FullyDistVec.h 
	$(COMPILER) $(INCADD) $(FLAGS) -c -o SplitMergeTest.o SplitMergeTest.cpp

ParIOTest.o: ParIOTest.cpp $(COMBBLAS_INC)/SpDCCols.cpp $(COMBBLAS_INC)/dcsc.cpp $(COMBBLAS_INC)/SpHelper.h $(COMBBLAS_INC)/SpParHelper.h $(COMBBLAS_INC)/SpParMat.cpp $(COMBBLAS_INC)/Friends.h $(COMBBLAS_INC)/ParFriends.h  $(COMBBLAS_INC)/SpParHelper.cpp
	$(COMPILER) $(INCADD) $(FLAGS) -c -o ParIOTest.o ParIOTest.cpp

GenWriteMat.o: ParIOTest.cpp $(COMBBLAS_INC)/SpDCCols.cpp $(COMBBLAS_INC)/dcsc.cpp $(COMBBLAS_INC)/SpHelper.h $(COMBBLAS_INC)/SpParHelper.h $(COMBBLAS_INC)/SpParMat.cpp $(COMBBLAS_INC)/Friends.h $(COMBBLAS_INC)/ParFriends.h  $(COMBBLAS_INC)/SpParHelper.cpp
	$(COMPILER) $(INCADD) $(FLAGS) -c -o GenWriteMat.o GenWriteMatrix.cpp

ReadWriteMtx.o: ReadWriteMtx.cpp $(COMBBLAS_INC)/SpDCCols.cpp $(COMBBLAS_INC)/dcsc.cpp $(COMBBLAS_INC)/SpHelper.h $(COMBBLAS_INC)/SpParHelper.h $(COMBBLAS_INC)/SpParMat.cpp $(COMBBLAS_INC)/Friends.h $(COMBBLAS_INC)/ParFriends.h  $(COMBBLAS_INC)/SpParHelper.cpp
	$(COMPILER) $(INCADD) $(FLAGS) -c -o ReadWriteMtx.o ReadWriteMtx.cpp

Mtx2Bin.o: Mtx2Bin.cpp $(COMBBLAS_INC)/SpDCCols.cpp $(COMBBLAS_INC)/dcsc.cpp $(COMBBLAS_INC)/SpHelper.h $(COMBBLAS_INC)/SpParHelper.h $(COMBBLAS_INC)/SpParMat.cpp $(COMBBLAS_INC)/Friends.h $(COMBBLAS_INC)/ParFriends.h  $(COMBBLAS_INC)/SpParHelper.cpp
	$(COMPILER) $(INCADD) $(FLAGS) -DIODEBUG -c -o Mtx2Bin.o Mtx2Bin.cpp

TransposeTest: MemoryPool.o CommGrid.o MPIType.o TransposeTest.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o TransposeTest TransposeTest.o MemoryPool.o CommGrid.o MPIType.o mmio.o

MultTest: MemoryPool.o CommGrid.o MPIType.o MultTest.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o MultTest MultTest.o MemoryPool.o CommGrid.o MPIType.o mmio.o

MultTime: MemoryPool.o CommGrid.o MPIType.o MultTiming.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o MultTime MultTiming.o MemoryPool.o CommGrid.o MPIType.o mmio.o

IteratorTest: MemoryPool.o CommGrid.o MPIType.o IteratorTest.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o IteratorTest IteratorTest.o MemoryPool.o CommGrid.o MPIType.o mmio.o

SplitMergeTest: MemoryPool.o CommGrid.o MPIType.o SplitMergeTest.o mmio.o $(COMBBLAS)/graph500-1.2/generator/libgraph_generator_seq.a
	$(COMPILER) $(FLAGS) $(INCADD) -o SplitMergeTest SplitMergeTest.o MemoryPool.o CommGrid.o MPIType.o mmio.o -L$(COMBBLAS)/graph500-1.2/generator -lgraph_generator_seq 

ReduceTest: MemoryPool.o CommGrid.o MPIType.o ReduceTest.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o ReduceTest ReduceTest.o MemoryPool.o CommGrid.o MPIType.o mmio.o

VectorInd: MemoryPool.o CommGrid.o MPIType.o VectorIndexing.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o VectorInd VectorIndexing.o MemoryPool.o CommGrid.o MPIType.o mmio.o

VectorIO: MemoryPool.o CommGrid.o MPIType.o VectorIO.o mmio.o
	$(COMPILER) $(FLAGS) $(INCADD) -o VectorIO VectorIO.o MemoryPool.o CommGrid.o MPIType.o mmio.o

ParIOMM: MemoryPool.o CommGrid.o MPIType.o ParIOTest.o mmio.o hash.o
	$(COMPILER) $(FLAGS) $(INCADD) -o ParIOMM ParIOTest.o MemoryPool.o CommGrid.o MPIType.o mmio.o hash.o

Mtx2Bin: MemoryPool.o CommGrid.o MPIType.o Mtx2Bin.o mmio.o hash.o
	$(COMPILER) $(FLAGS) $(INCADD) -DIODEBUG -o Mtx2Bin Mtx2Bin.o MemoryPool.o CommGrid.o MPIType.o mmio.o hash.o

GenWrMat: MemoryPool.o CommGrid.o MPIType.o GenWriteMat.o mmio.o hash.o $(COMBBLAS)/graph500-1.2/generator/libgraph_generator_seq.a
	$(COMPILER) $(FLAGS) $(INCADD) -o GenWrMat GenWriteMat.o MemoryPool.o CommGrid.o MPIType.o mmio.o hash.o -L$(COMBBLAS)/graph500-1.2/generator -lgraph_generator_seq

ReadWriteMtx: MemoryPool.o CommGrid.o MPIType.o ReadWriteMtx.o mmio.o hash.o
	$(COMPILER) $(FLAGS) $(INCADD) -o ReadWriteMtx ReadWriteMtx.o MemoryPool.o CommGrid.o MPIType.o mmio.o hash.o


clean: 
	rm -f TransposeTest
	rm -f SplitMergeTest
	rm -f MultTest
	rm -f ReduceTest
	rm -f VectorInd
	rm -f VectorIOPerm
	rm -f IteratorTest
	rm -f ParIOMM
	rm -f ReadWriteMtx
	rm -f Mtx2Bin
	rm -f MultTime
	rm -f GenWrMat
	rm -f *.o
	rm -f $(COMBBLAS)/graph500-1.2/generator/*.o
	rm -f $(COMBBLAS)/graph500-1.2/generator/libgraph_generator_seq.a

cleanout:
	rm out.*
	rm err.*
