DIRhosts=/home/ubuntu/hosts
DIR=/home/ubuntu
options=-env I_MPI_DEBUG=3
number=10

ex=

all: mpi_hello_world example
.PHONY: all

mpi_hello_world:
	@swarmlab-getworkers > $(DIRhosts) ;\
	mpicc  ./mpi_hello_world.c -o $(DIR)/mpi_hello_world ;\
	while read  line; do\
		echo "scp $(DIR)/mpi_hello_world ubuntu@$$line:$(DIR)/mpi_hello_world " ;\
		scp $(DIR)/mpi_hello_world ubuntu@$$line:$(DIR)/mpi_hello_world ;\
		echo "$$line" ;\
	done < $(DIRhosts);\
	echo "mpirun  $(options) -wdir=$(DIR) -n $(number) -f $(DIRhosts)  $(DIR)/mpi_hello_world" ; \
	mpirun  $(options) -wdir=$(DIR) -n $(number) -f $(DIRhosts)  $(DIR)/mpi_hello_world

example:
	@if [ ! -z  $(ex) ]; then\
		swarmlab-getworkers > $(DIRhosts) ;\
		mpicc  ./$(ex).c -o $(DIR)/$(ex) ;\
		while read  line; do\
			echo "scp $(DIR)/$(ex) ubuntu@$$line:$(DIR)/$(ex) " ;\
			scp $(DIR)/$(ex) ubuntu@$$line:$(DIR)/$(ex) ;\
			echo "$$line" ;\
		done < $(DIRhosts);\
		echo "mpirun  $(options) -wdir=$(DIR) -n $(number) -f $(DIRhosts)  $(DIR)/$(ex)" ; \
		mpirun  $(options) -wdir=$(DIR) -n $(number) -f $(DIRhosts)  $(DIR)/$(ex) ; \
	else\
		echo "usage: make example ex=source file" ; \
		echo "e.g.: make example ex=mv" ; \
	fi\