#!/bin/bash

###########################################################################################
#	run_standard
#		version: 	1.0	12/12/13
#
#		original author:	Michele Bracuto		<bracuto@cs.unibo.it>
#		modified by:		Gabriele D'Angelo	<g.dangelo@unibo.it>
#
#	description:
#		called by the "run" wrapper. Standard parallel execution using
#		shared memory / TCP / SCTP communication protocols
#
###########################################################################################

###########################################################################################

HOST="localhost"
SYNCALG=$1
NLP=3
X=0

###########################################################################################

echo "AIRPORT SIMULATOR standard batch..."

# SImulation MAnager (SIMA) execution	
if [ $HOST == $HOSTNAME -o $HOST == "localhost" ]; 
then
       	echo "Starting SIMA (waiting for $NLP LPs)..."
	./sima $NLP channels_$SYNCALG.txt &
fi

# LPs execution
X=0
Y=$(($NLP-1))

while [ $X -le $Y ]
do
	echo "Starting the >>>airports_$1<<< instance number: $X/$Y ..."

	if [ $X -lt $Y ]
        then
		# foreground execution
		./airports_$SYNCALG $X $HOST $NLP >$X.out &
        else
		# background execution
		./airports_$SYNCALG $X $HOST $NLP >$X.out
	fi

	X=$((X+1))
done
