#!/bin/bash

###########################################################################################
#	run_mpi
#		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 MPI
#		and the SImulation MAnager (SIMA)
#
###########################################################################################

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

HOST="localhost"
NLP=$1
SLP=$2
TOT_SMH=$3

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

echo "WIRELESS SIMULATION mpi batch..."

# Partitioning the #SMH among the available LPs
SMH=$((TOT_SMH/NLP))

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

echo "Starting the >>>wireless<<< instances..."

# Lanching the LPs, all on this host
mpirun -np $NLP ./wireless $NLP $SMH
