# shellcheck shell=bash
# OpenHPC build script/utilities
#
#-----------------------------------------------------------------------
# Licensed under the Apache License, Version 2.0 (the "License"); you
# may not use this file except in compliance with the License. You may
# obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#-----------------------------------------------------------------------
# Sets up build environment for supported MPI families
#-----------------------------------------------------------------------

if [ "$#" = "1" ]; then
	OHPC_MPI_FAMILY="${1}"
fi

if [ -z "${OHPC_MPI_FAMILY}" ]; then
	echo "OHPC_MPI_FAMILY not defined"
	exit 1
fi

if [ -z "${MODULEPATH}" ]; then
	echo "MODULEPATH not defined"
	exit 1
fi

if [ "${OHPC_MPI_FAMILY}" = "openmpi" ]; then
	module load openmpi
elif [ "${OHPC_MPI_FAMILY}" = "openmpi3" ]; then
	module load openmpi3
elif [ "${OHPC_MPI_FAMILY}" = "openmpi4" ]; then
	module load openmpi4
elif [ "${OHPC_MPI_FAMILY}" = "openmpi5" ]; then
	module load openmpi5
elif [ "${OHPC_MPI_FAMILY}" = "impi" ]; then
	module load impi
elif [ "${OHPC_MPI_FAMILY}" = "mvapich2" ]; then
	module load mvapich2
elif [ "${OHPC_MPI_FAMILY}" = "mpich" ]; then
	module load mpich
else
	echo "Unsupported OHPC_MPI_FAMILY -> ${OHPC_MPI_FAMILY}"
	exit 1
fi
