# RUN = mpiexec -machinefile ~/mpd.hosts
RUN = mpiexec
# FLAGS = -I/opt/local/include -L/opt/local/lib -lgd
FLAGS = -lgd

######################### Sequential Version #########################

specx: diffusion1d_spec.c Makefile
	cc -o specx  $(FLAGS) diffusion1d_spec.c

spec1: specx config1.txt
	rm -f specout/out*
	./specx config1.txt

spec2: specx config2.txt
	rm -f specout/out*
	./specx config2.txt


######################### Parallel Version #########################

par1: par1x
	rm -f parout/out*
	$(RUN) -n 4 ./par1x config1.txt

par1x: diffusion1d_par.c Makefile
	mpicc -o par1x $(FLAGS) -DM=100 -DPWIDTH=2 -DPHEIGHT=100 diffusion1d_par.c

par2: par2x
	rm -f parout/out*
	$(RUN) -n 4 ./par2x config2.txt

par2x: diffusion1d_par.c Makefile
	mpicc -o par2x  $(FLAGS) -DDEBUG -DM=100 -DPWIDTH=2 -DPHEIGHT=100 diffusion1d_par.c

######################### Nonblocking Parallel Version #########################

par1nb: par1nbx
	rm -f parout/out*
	$(RUN) -n 4 ./par1nbx config1.txt

par1nbx: diffusion1d_nb.c Makefile
	mpicc -o par1nbx $(FLAGS) -DM=100 -DPWIDTH=2 -DPHEIGHT=100 diffusion1d_nb.c

par2nb: par2nbx
	rm -f parout/out*
	$(RUN) -n 4 ./par2nbx config2.txt

par2nbx: diffusion1d_nb.c Makefile
	mpicc -o par2nbx  $(FLAGS) -DDEBUG -DM=100 -DPWIDTH=2-DPHEIGHT=100 diffusion1d_nb.c

############################ Bad Version ############################

bad1: bad1x
	rm -f badout/out*
	$(RUN) -n 4 ./bad1x config1.txt

bad1x: diffusion1d_bad.c Makefile
	mpicc -o bad1x $(FLAGS) -DM=100 -DPWIDTH=2 -DPHEIGHT=100 diffusion1d_bad.c

bad2: bad2x
	rm -f badout/out*
	$(RUN) -n 4 ./bad2x config2.txt

bad2x: diffusion1d_bad.c Makefile
	mpicc -o bad2x  $(FLAGS) -DDEBUG -DM=100 -DPWIDTH=2 -DPHEIGHT=100 diffusion1d_bad.c

clean: clean_spec clean_par clean_nb clean_bad

clean_spec:
	rm -f spec*x *.o *~ specout/out*

clean_par:
	rm -f par*x *.o *~ parout/out*

clean_nb:
	rm -f par*x *.o *~ nbout/out*

clean_bad:
	rm -f bad*x *.o *~ badout/out*
