#!/bin/sh
mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

export HPCX_DIR=$mydir
export HPCX_FCA_DIR=$HPCX_DIR/fca
export HPCX_MXM_DIR=$HPCX_DIR/mxm
export HPCX_UCX_DIR=$HPCX_DIR/ucx
export HPCX_SHARP_DIR=$HPCX_DIR/sharp
export HPCX_HCOLL_DIR=$HPCX_DIR/hcoll
export HPCX_IBPROF_DIR=$HPCX_DIR/ibprof
export HPCX_IBPROF_LIB=$HPCX_IBPROF_DIR/lib/libibprof.so
export HPCX_MPI_DIR=$HPCX_DIR/ompi-v3.0.x
export HPCX_OSHMEM_DIR=$HPCX_MPI_DIR
export HPCX_MPI_TESTS_DIR=$HPCX_MPI_DIR/tests
export HPCX_IPM_DIR=$HPCX_MPI_TESTS_DIR/ipm-2.0.6
export HPCX_IPM_LIB=$HPCX_IPM_DIR/lib/libipm.so
export HPCX_BUPC_DIR=$HPCX_DIR/bupc
export OMPI_HOME=$HPCX_MPI_DIR
export MPI_HOME=$HPCX_MPI_DIR
export OSHMEM_HOME=$HPCX_MPI_DIR
export SHMEM_HOME=$HPCX_MPI_DIR

function hpcx_load()
{
    export OLD_PATH=$PATH
    export OLD_OPAL_PREFIX=$OPAL_PREFIX
    export OPAL_PREFIX=$HPCX_MPI_DIR
    export PATH=$HPCX_MPI_DIR/bin:$PATH
    export PATH=$HPCX_MXM_DIR/bin:$PATH
    export PATH=$HPCX_UCX_DIR/bin:$PATH
    export PATH=$HPCX_HCOLL_DIR/bin:$PATH
    export PATH=$HPCX_BUPC_DIR/bin:$PATH

    export OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=$HPCX_MPI_DIR/lib:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=$HPCX_MXM_DIR/lib:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=$HPCX_HCOLL_DIR/lib:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=$HPCX_SHARP_DIR/lib:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=$HPCX_UCX_DIR/lib:$LD_LIBRARY_PATH

    export OLD_LIBRARY_PATH=$LIBRARY_PATH
    export LIBRARY_PATH=$HPCX_MPI_DIR/lib:$LIBRARY_PATH
    export LIBRARY_PATH=$HPCX_MXM_DIR/lib:$LIBRARY_PATH
    export LIBRARY_PATH=$HPCX_HCOLL_DIR/lib:$LIBRARY_PATH
    export LIBRARY_PATH=$HPCX_SHARP_DIR/lib:$LIBRARY_PATH
    export LIBRARY_PATH=$HPCX_MPI_DIR/lib:$LIBRARY_PATH

    export CPATH=$HPCX_HCOLL_DIR/include:$CPATH
    export CPATH=$HPCX_MXM_DIR/include:$CPATH
    export CPATH=$HPCX_SHARP_DIR/include:$CPATH
    export CPATH=$HPCX_UCX_DIR/include:$CPATH
    export CPATH=$HPCX_MPI_DIR/include:$CPATH

    export LIBRARY_PATH=$HPCX_UCX_DIR/lib:$LIBRARY_PATH
}

function hpcx_unload()
{
    export PATH=$OLD_PATH
    export LD_LIBRARY_PATH=$OLD_LD_LIBRARY_PATH
    export LIBRARY_PATH=$OLD_LIBRARY_PATH
    export OPAL_PREFIX=$OLD_OPAL_PREFIX
    for var in $(env|grep HPCX_|cut -f1 -d=) MPI_HOME OSHMEM_HOME SHMEM_HOME OMPI_HOME; do
        unset $var
    done
}


