#!/usr/bin/bash

###################################
# MPI-Bash convenience wrappper   #
# By Scott Pakin <pakin@lanl.gov> #
###################################

# This script sets two environment variables then invokes the script
# named on the command line.  First, it sets LD_LIBRARY_PATH to point
# to the full path of the mpibash.so file.  This saves scripts from
# having to hard-wire -- or even specify -- the path.  Instead, they
# can load MPI-Bash simply with "enable -f mpibash.so mpi_init".
# Secondly, it sets LD_PRELOAD to mpibash.so.  This is a workaround
# for a workaround in Open MPI.  Basically, we need to make sure that
# Open MPI's dlopen() takes precedence over the default dlopen(), and
# to do that, Open MPI has to be loaded into memory before bash.  See
# http://www.open-mpi.org/faq/?category=troubleshooting#missing-symbols
# for a discussion of the "deep run time linker voodoo" that makes
# this trickiness necessary.

prefix="/usr"
exec_prefix="/usr"
mpibashdir="/usr/lib64/mpich/lib/mpibash/"
export LD_LIBRARY_PATH="$mpibashdir${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"
export LD_PRELOAD="$mpibashdir/mpibash.so"
exec bash "$@"
