default: buffer mpibnch_latency isend


test: isend buffer mpibnch_latency isend
	rm -f MPI_PROFILING_STATS
	( export MPI_PROFILE_AT_INIT=1; \
	  export MPI_SCOPY_CHECK_AT_INIT=1;\
	  export MPI_BUFFER_MAX=1; \
	  ${CC} -o mpich_test mpich_test.c; \
	  if ( ./mpich_test ) then \
		  echo "Cannot run buffer test with mpich"; \
	  else \
	  	if [ `uname` = "Linux" ]; then \
  			export LD_LIBRARY_PATH=..:${LD_LIBRARY_PATH};mpirun -np 2 ./buffer; \
	  	else \
	  		export _RLD64_LIST=../libproftest.so:DEFAULT;mpirun -np 2 ./buffer; \
	  	fi; \
	  fi ) 
	if [ `uname` != "Linux" ]; then \
	    ${CC} -o mpich_test mpich_test.c; \
	    if ( ./mpich_test ) then \
		echo "Cannot run ./mpibnch_latency test with mpich"; \
  	    else \
		( export MPI_PROFILE_AT_INIT=1; \
	          export MPI_SCOPY_CHECK_AT_INIT=1;\
	          export MPI_BUFFER_MAX=1; \
		  export _RLD64_LIST=../libproftest.so:DEFAULT;mpirun -np 4 ./mpibnch_latency); \
  	    fi; \
	fi ; \
	( export MPI_PROFILE_AT_INIT=1; \
	  export MPI_SCOPY_CHECK_AT_INIT=1;\
	  export MPI_BUFFER_MAX=1; \
	  if [ `uname` = "Linux" ]; then \
	  	export LD_LIBRARY_PATH=..:${LD_LIBRARY_PATH};mpirun -np 2 ./isend; \
	  else \
	  	export _RLD64_LIST=../libproftest.so:DEFAULT;mpirun -np 2 ./isend; \
	  fi ) 
	cat MPI_PROFILING_STATS

buffer: buffer.c 
	set -x; \
	if [ `uname` = "Linux" ]; then \
		${CC} -o mpich_test mpich_test.c; \
		if ( ./mpich_test ) then \
			${CC} -o buffer buffer.c -L.. -lproftest; \
		else \
			${CC} -o buffer buffer.c -L.. -lproftest -lmpi; \
		fi; \
	else \
		${CC} -o mpich_test mpich_test.c; \
		if ( ./mpich_test ) then \
			 ${CC} -64 -o buffer buffer.c  -lexc; \
		else \
			 ${CC} -64 -o buffer buffer.c  -lmpi -lexc; \
		fi; \
	fi

mpibnch_latency: mpibnch_latency.c
	if [ `uname` = "Linux" ]; then \
		echo "Cannot build mpibnch_latency for linux - needs sma"; \
	else \
		${CC} -o mpich_test mpich_test.c; \
		if ( ./mpich_test ) then \
			echo "Cannot build mpibnch_latency for mpich - needs sma"; \
		else \
			${CC} -64 -o mpibnch_latency mpibnch_latency.c -lmpi -lexc -lsma; \
		fi; \
	fi

isend: isend.c 
	if [ `uname` = "Linux" ]; then \
		${CC} -o mpich_test mpich_test.c; \
		if ( ./mpich_test ) then \
			${CC} -o isend isend.c -L.. -lproftest; \
		else \
			${CC} -o isend isend.c -L.. -lproftest -lmpi; \
		fi; \
	else \
		${CC} -o mpich_test mpich_test.c; \
		if ( ./mpich_test ) then \
			${CC} -64 -o isend isend.c  -lexc ; \
		else \
			${CC} -64 -o isend isend.c  -lmpi -lexc ; \
		fi; \
	fi

clean:
	rm -f *.o isend mpibnch_latency buffer mpich_test core*
