lled with a series of
# arguments to be forwarded to matlab. 
#
callMpiexec() {
    echo "$MPIEXEC" \
	-noprompt -l -exitcodes -phrase MATLAB_LSF -port ${SMPD_PORT} \
	-hosts ${NUM_PM_HOSTS} ${LSB_MCPU_HOSTS} ${MATLAB_CMD}
    if [ ${REDIRECT_MPIEXEC_STDIN} -eq 1 ]; then
	eval "$MPIEXEC" \
	    -noprompt -l -exitcodes -phrase MATLAB_LSF -port ${SMPD_PORT} \
	    -hosts ${NUM_PM_HOSTS} ${LSB_MCPU_HOSTS} ${MATLAB_CMD} < ${MPIEXEC_STDIN_FNAME}
    else
        # Redirect /dev/null into mpiexec to avoid maxing-out CPU usage.
	eval "$MPIEXEC" \
	    -noprompt -l -exitcodes -phrase MATLAB_LSF -port ${SMPD_PORT} \
	    -hosts ${NUM_PM_HOSTS} ${LSB_MCPU_HOSTS} ${MATLAB_CMD} < /dev/null
    fi

    MPIEXEC_EXIT_CODE=$?
    echo "mpiexec completed with exit code: ${MPIEXEC_EXIT_CODE}"
}

#
# This utility function chooses a port for the SMPD process manager. This can be
# customised to fit in with inter-worker firewalls.
#
chooseSmpdPort() {
    SMPD_PORT=`expr ${LSB_JOBID} % 10000 + 20000`
}

#
# This manipulates smpd everywhere. It uses the LSF utility "lsgrun" to call
# smpd on all hosts. The variable SMPD is used to choose which smpd executable
# to use.
#
callSmpdOnHosts() {
    hosts="$1"
    for host in $hosts
    do
        echo lsgrun -p -m ${host} "${SMPD}" $2 -phrase MATLAB_LSF -port ${SMPD_PORT}
        lsgrun -p -m ${host} "${SMPD}" $2  -phrase MATLAB_LSF -port ${SMPD_PORT}
        lsgrun_exit=$?
        if [ $lsgrun_exit -ne 0 ]
        then
            echo "*** an error occurred calling smpd $2 on ${host}, exiting"
            exit ${lsgrun_exit}
        fi
    done
}

#
# Extract the unique host names, and count them too
#
manipulateHosts() {
    isHost=1
    UNIQUE_PM_HOSTS=""
    NUM_PM_HOSTS=0
    for x in ${LSB_MCPU_HOSTS}
    do
        if [ ${isHost} -eq 1 ]
        then
            UNIQUE_PM_HOSTS="${UNIQUE_PM_HOSTS} ${x}"
            NUM_PM_HOSTS=`expr 1 + ${NUM_PM_HOSTS}`
        fi
        isHost=`expr 1 - ${isHost}`
    done
    
}


#
# This will be called in the event of either a bkill, or normal completion.
#
cleanupAndExit() {
    if [ ${REDIRECT_MPIEXEC_STDIN} -eq 1 ]; then
	rm -f ${MPIEXEC_STDIN_FNAME}
    fi
    shutdownProcessManagers "${UNIQUE_PM_HOSTS}"
    exit ${MPIEXEC_EXIT_CODE}
}

# This function decides whether we should redirect stdin for the
# mpiexec process. This is to work around problems only seen on MAC.
setupInputRedirect() {
    REDIRECT_MPIEXEC_STDIN=0
    if [ -f /bin/uname ]; then
	case "`/bin/uname`" in
	    Darwin)
		REDIRECT_MPIEXEC_STDIN=1
		;;
	esac
    elif [ -f /u//
//    Copyright (C) Microsoft.  All rights reserved.
//
#if !defined(WABMEM_H)
#define WABMEM_H

#include <winapifamily.h>

#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)

#if !defined(MAPIX_H)
typedef SCODE (STDMETHODCALLTYPE MAPIALLOCATEBUFFER)(
        _In_                       ULONG      cbSize,
        _Outptr_result_bytebuffer_(cbSize) LPVOID FAR *lppBuffer
);

typedef SCODE (STDMETHODCALLTYPE MAPIALLOCATEMORE)(
	ULONG			cbSize,
	LPVOID			lpObject,
	LPVOID FAR *	lppBuffer
);

typedef ULONG (STDAPICALLTYPE MAPIFREEBUFFER)(
	LPVOID			lpBuffer
);

typedef MAPIALLOCATEBUFFER FAR	*LPMAPIALLOCATEBUFFER;
typedef MAPIALLOCATEMORE FAR	*LPMAPIALLOCATEMORE;
typedef MAPIFREEBUFFER FAR 		*LPMAPIFREEBUFFER;

#endif  // MAPIX_H

typedef SCODE (STDMETHODCALLTYPE WABALLOCATEBUFFER)(
   LPWABOBJECT     lpWABObject,
	ULONG			cbSize,
	LPVOID FAR *	lppBuffer
);

typedef SCODE (STDMETHODCALLTYPE WABALLOCATEMORE)(
   LPWABOBJECT     lpWABObject,
	ULONG			cbSize,
	LPVOID			lpObject,
	LPVOID FAR *	lppBuffer
);

typedef ULONG (STDAPICALLTYPE WABFREEBUFFER)(
   LPWABOBJECT     lpWABObject,
	LPVOID			lpBuffer
);

typedef WABALLOCATEBUFFER FAR	*LPWABALLOCATEBUFFER;
typedef WABALLOCATEMORE FAR	*LPWABALLOCATEMORE;
typedef WABFREEBUFFER FAR 		*LPWABFREEBUFFER;

#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */
#pragma endregion

#endif  // WABMEM_H
