CXXFLAGS = -Ofast -march=native #-pthread
LDLIBS = -lstdc++ -lm
TIMES = out.times.data
PLOT = Out.times.svg
TIME = time --format "$$nthreads %e %U" --append --output $(TIMES)
#CSC   = csc -o+
CSC   = mcs -o+
#ILRUN = ilrun
ILRUN = 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:][0:] \
	 "$(TIMES)" index 0 with linespoints title "csharp"\
	,"$(TIMES)" index 1 with linespoints title "c++"\
		;\
	' | tee log.gpi | gnuplot

N = 200000000
Out.txt $(TIMES) : main.exe main
	>Out.txt
	>$(TIMES)
	for nthreads in `seq 10`; do \
	echo "nthreads = $$nthreads" ;\
	$(TIME) $(ILRUN) main.exe -terms:$N -threads:$$nthreads >> Out.txt; \
	done
	echo >>$(TIMES)
	echo >>$(TIMES)
	for nthreads in `seq 10`; do \
	echo "nthreads = $$nthreads" ;\
	$(TIME) ./main -N $N -n $$nthreads >> Out.txt; \
	done

main.exe : main.cs
	$(CSC) $<

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

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

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

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