TIMES = out.times.data
PLOT = Out.times.svg
TIME = time --format "$$nthreads %e %U" --append --output $(TIMES)
MONO = mono

$(PLOT) : $(TIMES) Makefile
	echo '\
	set terminal $(subst .,,$(suffix $@)) background "white" ;\
	set output "$(PLOT)" ;\
	set tics out ;\
	set title "Program running time as function of number of threads" ;\
	set xlabel "number of threads" ;\
	set ylabel "real time in seconds" ;\
	set xtics 1 ;\
	plot [0.9:4.1][0:] \
	 "$(TIMES)" index 0 with linespoints title "mcs mono"\
	,"$(TIMES)" index 1 with linespoints title "clang -Ofast"\
	,"$(TIMES)" index 2 with linespoints title "clang++ -Ofast"\
	,"$(TIMES)" index 3 with linespoints title "august"\
		;\
	' | tee log.gpi | gnuplot

N = 200000000
Out.txt $(TIMES) : main.exe mainc maincpp august
	>Out.txt
	>$(TIMES)
	for nthreads in 1 2 3 4; do \
	echo "nthreads = $$nthreads" ;\
	$(TIME) $(MONO) main.exe -terms:$N -threads:$$nthreads >> Out.txt; \
	done
	echo >>$(TIMES)
	echo >>$(TIMES)
	for nthreads in 1 2 3 4; do \
	echo "nthreads = $$nthreads" ;\
	$(TIME) ./mainc -N $N -n $$nthreads >> Out.txt; \
	done
	echo >>$(TIMES)
	echo >>$(TIMES)
	for nthreads in 1 2 3 4; do \
	echo "nthreads = $$nthreads" ;\
	$(TIME) ./maincpp -N $N -n $$nthreads >> Out.txt; \
	done
	echo >>$(TIMES)
	echo >>$(TIMES)
	for nthreads in 1 2 3 4; do \
	echo "nthreads = $$nthreads" ;\
	$(TIME) ./august $N $$nthreads >> Out.txt; \
	done

main.exe : main.cs
	mcs $<

CFLAGS = -Ofast -march=native -pthread
CXXFLAGS = -Ofast -march=native -pthread
mainc: mainc.c
maincpp: maincpp.cpp
august: august.cpp


N1=2.01e8
N2=2.02e8
N3=2.03e8
N4=2.04e8

test1: out1 out2 out3 out4 # make -j4 test
out1: main.exe
	mono main.exe -terms:$(N1) -threads:1 > $@
out2: main.exe
	mono main.exe -terms:$(N2) -threads:1 > $@
out3: main.exe
	mono main.exe -terms:$(N3) -threads:1 > $@
out4: main.exe
	mono main.exe -terms:$(N4) -threads:1 > $@

test2: main.exe
	mono main.exe -terms:$(N1) -threads:1 > out1 &
	mono main.exe -terms:$(N2) -threads:1 > out2 &
	mono main.exe -terms:$(N3) -threads:1 > out3 &
	mono main.exe -terms:$(N4) -threads:1 > out4 &

clean:
	$(RM) [Oo]ut*

clean:
	$(RM) *.dll *.exe [Oo]ut* log* *log mainc maincpp
