Blob Blame History Raw
#!/bin/sh
# BEGIN_ICS_COPYRIGHT8 ****************************************
# 
# Copyright (c) 2015-2017, Intel Corporation
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 
#     * Redistributions of source code must retain the above copyright notice,
#       this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of Intel Corporation nor the names of its contributors
#       may be used to endorse or promote products derived from this software
#       without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# 
# END_ICS_COPYRIGHT8   ****************************************

# [ICS VERSION STRING: unknown]

# helper script to handle common setup for the sample application run scripts

# this script should be . included in a run_ script
# Input:
#   MPICH_PREFIX    - path to MPICH tools
#   MPI_HOSTS       - mpi_hosts file to use (default is $PWD/mpi_hosts)
#   SHOW_MPI_HOSTS  - set to "y" if MPI_HOSTS contents should be output prior
#                     to starting job.  Set to "n" to disable
#                     defaults to "y"
#   SHOW_MPI_HOSTS_LINES - maximum lines in MPI_HOSTS to show.  Default is 128
#                          Only lines applicable to job will be shown.
#                          Note the file might include some comment lines
#   NUM_PROCESSES   - number of processes in job, if "" no count is specified
#                     if "all" use wc -l $MPI_HOSTS as the process count
#   LOGFILE         - logfile to append results of run to, if ""
#                     this script will define
#   LOGSUFFIX       - suffix to append to logfile name defined by this script
SOS_RPM=sandia-openshmem_gcc_hfi
SOS_TEST_RPM=sandia-openshmem_gcc_hfi-tests

get_shmem_bench_dir()
{

    local TEST_NAME=$1
    local instDir=`rpm -ql $SOS_TEST_RPM |grep -e "/$TEST_NAME$" |sed -e "s%/$TEST_NAME%%"`
	if [[ $? -ne 0 || $instDir = "(none)" || ! -d $instDir ]] ; then
        echo "$TEST_NAME not found"
        exit 1
	fi
	echo $instDir
}

show_mpi_hosts()
{
	local lines

	echo "Using hosts list: $MPI_HOSTS"

	if [ "${SHOW_MPI_HOSTS:-y}" = "y" ]
	then
		show_lines=${SHOW_MPI_HOSTS_LINES:-128}
		if [ "z$NUM_PROCESSES" != "z" ]
		then
			# there may be comments before the last host.  So we number the
			# lines, filter out the lines with comments and blank lines
			# and then get the "NUM_PROCESSES"th line's number
			avail_lines=$(nl -s';' -nln -w1 -ba $MPI_HOSTS|egrep -v '^[0-9]*;[[:space:]]*#'|egrep -v '^[0-9]*;[[:space:]]*$'|head -$NUM_PROCESSES|tail -1|cut -f1 -d';' )
		else
			# no NUM_PROCESSES, so use whole file
			avail_lines=$(cat $MPI_HOSTS|wc -l)
		fi
		if [ $show_lines -ge $avail_lines ]
		then
			echo "Hosts in run:"
			head -n $avail_lines $MPI_HOSTS
		else
			echo "First $show_lines lines in host list for run:"
			head -n $show_lines $MPI_HOSTS
		fi
		echo
	fi
}


if [ -z "$NUM_PROCESSES" ]; then
    NUM_PROCESSES=2
    echo " Defaulting to $NUM_PROCESSES processes"
elif [[ ! "$NUM_PROCESSES" =~ [0-9]+ ]]; then
    echo " Expected number for <number_of_processes> and got: $NUM_PROCESSES"
    exit 1
fi

if [ -z "$LOGFILE" ]
then
	CURTIME=`date +%d%b%y%H%M%S`
	if [ ! -d logs ]
	then
		mkdir -p logs
	fi
	LOGFILE=$PWD/logs/$APP.$CURTIME$LOGSUFFIX
	echo " Running MPI tests with $NUM_PROCESSES processes"
	echo " logfile $LOGFILE"
	> $LOGFILE
fi
SHMEM_PREFIX=${SHMEM_PREFIX:-`rpm -ql $SOS_RPM |grep -e "bin/oshrun" |sed -e "s%/bin/oshrun%%"`}
if [ -z "$SHMEM_PREFIX" ]; then
     echo "Environment variale SHMEM_PREFIX Not defined" >&2
fi

OSHRUN=$SHMEM_PREFIX/bin/oshrun
if [[ ! -e $OSHRUN ]] ; then
	echo "osrun Not found. Expecting it at: $OSHRUN " >&2
	exit 1
fi

export MPI_HOSTS=${MPI_HOSTS:-./shmem_hosts}

if [ ! -f $MPI_HOSTS ] ; then
    echo "No MPI hosts file defined. Set MPI_HOSTS variable pointing to the hosts file"
    exit 1
fi

if [[ -z $MPICH_PREFIX ]] ; then
	. ./select_mpi
	if [[ -z $MPICH_PREFIX ]] ; then
		echo "Error: MPICH_PREFIX not set" >&2
		exit 1
	fi
    echo " Using MVAPICH2 at $MPICH_PREFIX  (in PATH and LD_LIBRARY_PATH)" >&2
fi

rpm -q $SOS_TEST_RPM &>/dev/null
if [ $? -ne 0 ]; then
    echo "Error: RPM $SOS_TEST_RPM is expected to be installed with the tests binaries"
    exit 1
fi

export SHMEM_RUN="$SHMEM_PREFIX/bin/oshrun --hostfile $MPI_HOSTS"
export PATH=${MPICH_PREFIX}/bin:${SHMEM_PREFIX}/bin:${PATH}
export LD_LIBRARY_PATH=${MPICH_PREFIX}/lib64:${SHMEM_PREFIX}/lib64:${LD_LIBRARY_PATH}