#!/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"
NLP=$1
SLP=$2
TOT_IA=$3

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

echo -e "WIRELESS SIMULATION standard batch..."

# Partitioning the #IA among the available LPs
IA=$((TOT_IA/NLP))

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

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

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

	if [ $X -lt $Y ]
        then
		# foreground execution
        	./mig-agents	$NLP $IA &
        else
		# background execution
        	./mig-agents	$NLP $IA
	fi

	X=$((X+1))
done
