# emacs mode line -*- mode: makefile -*-
# needs $(PGM)

OPTS=
CDIR=../../..
CHARMC=$(CDIR)/bin/charmc -language charm++ $(OPTS)

# Rules to convert .ci to .decl.h and .def.h
.SUFFIXES:
.SUFFIXES: .o .C .def.h .decl.h .ci .h

.ci.decl.h:
	$(CHARMC) -c $<

.decl.h.def.h:
	@true

all: opt

test: $(PGM)
	./charmrun +p4 $(PGM) $(TEST_ARGS)

$(PGM) : $(PGM).o
	$(CHARMC) -o $(PGM) -module msa $(PGM).o -lm

headers: $(PGM).decl.h $(PGM).def.h $(HEADERS)
	touch headers

$(PGM).o : $(PGM).ci $(PGM).C headers
	$(CHARMC) -c $(PGM).C

proj:
	make OPTS="-tracemode projections -O3" $(PGM)

para:
	make OPTS="-memory paranoid -g $(OPTS)" $(PGM)

opt:
	make OPTS="-O3 $(OPTS)" $(PGM)

g:
	make OPTS="-g $(OPTS)" $(PGM)

gprof:
	make OPTS="-pg $(OPTS)" $(PGM)

clean:
	rm -f *.o *.decl.h *.def.h charmrun test $(PGM) headers

c: clean

tests: w2 w3 w4

# test with two worker threads
w2: opt
	@echo ================================================================
	./charmrun +p1 $(PGM) 2
	@echo ================================================================
	./charmrun +p2 $(PGM) 2
	@echo ================================================================
	./charmrun +p3 $(PGM) 2
	@echo ================================================================
	./charmrun +p4 $(PGM) 2

# test with three worker threads
w3: opt
	@echo ================================================================
	./charmrun +p1 $(PGM) 3
	@echo ================================================================
	./charmrun +p2 $(PGM) 3
	@echo ================================================================
	./charmrun +p3 $(PGM) 3
	@echo ================================================================
	./charmrun +p4 $(PGM) 3

#test with various worker threads
w4: opt
	@echo ================================================================
	./charmrun +p1 $(PGM) 4
	@echo ================================================================
	./charmrun +p2 $(PGM) 4
	@echo ================================================================
	./charmrun +p3 $(PGM) 4
	@echo ================================================================
	./charmrun +p4 $(PGM) 4
	@echo ================================================================
	./charmrun +p4 $(PGM) 8
	@echo ================================================================
	./charmrun +p4 $(PGM) 32
