#!/bin/bash

###########################################################################################
#	run
#		version: 	1.0	12/12/13
#
#		original author:	Michele Bracuto		<bracuto@cs.unibo.it>
#		modified by:		Gabriele D'Angelo	<g.dangelo@unibo.it>
#
#	description:
#		executes one run of the wireless simulation, it blocks until all LPs have 
#		finished 
#
#	usage:	
#		./run <#TOT_LP> <#LP> <#SMH>
#	
#		mandatory input parameters = #TOT_LP #LP #SMH
#		#TOT_LP 	total number of LPs in the simulation
#		#LP  		number of Logical Processes to execute in this host
#		#SMH		total number of wireless devices (nodes) to simulate
#				(e.g. each LP will simulate #SMH / #TOT_LP devices)
#
#		example: ./run 4 4 1000
#			it runs a parallel simulation composed of 4 LPs
#			in which each LP models 250 nodes
#			all the LPs will be executed in this host
#
#	output:
#		the output can be found in the following files:
#			<LP_ID>.out	model output
#			<LP_ID>.err	middleware output
#
#	notes:
#		1) the simulation execution parameters can be changed using the
#			GAIA APIs in the simulation model
#		2) this is a wrapper that calls the appropriate execution script
#
###########################################################################################

echo -e "\nWIRELESS SIMULATION wrapper..."

if [ "$#" != "3" ]; then
        echo "Incorrect syntax...		 "
        echo "USAGE: $0 [#TOT_LP] [#LP] [#SMH]"
	echo -e "\n#TOT_LP\ttotal number of LPs in the simulation"
	echo -e "#LP\tnumber of Logical Processes to execute in this host"
	echo -e "#SMH\ttotal number of wireless devices (nodes) to simulate"
	echo -e "\t(e.g. each LP will simulate #SMH / #TOT_LP devices)\n"
        exit
fi

# Checking for the building type of ARTÌS
USEMPI=`cat ../../config.mak | grep "USE_MPI" | grep "=" | grep "YES" | wc -l`
USENOIPMPI=`cat ../../config.mak | grep "USE_NOIP_MPI" | grep "=" | grep "YES" | wc -l`

if [ $USEMPI -eq 1 ]; then
	# MPI (with SIMA) execution
	./run_mpi $1 $2 $3
else 
if [ $USENOIPMPI -eq 1 ]; then
	# MPI (with NO SIMA) execution
	./run_noip-mpi $1 $2 $3
else
	# Standard execution
	./run_standard $1 $2 $3
fi
fi

sleep 1
echo "Done!"
