mpixlcxx-trace-bgp-V1R4.in 10.2 KB
Newer Older
1
#! /bin/bash
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# 
# (C) 2006 by Argonne National Laboratory.
#     See COPYRIGHT in top-level directory.
#
# mpicxx
# Simple script to compile and/or link MPI programs.
# This script knows the default flags and libraries, and can handle
# alternative C++ compilers and the associated flags and libraries.
# The important terms are:
#    includedir, libdir - Directories containing an *installed* mpich2
#    prefix, execprefix - Often used to define includedir and libdir
#    CXX                - C compiler
#    WRAPPER_CXXFLAGS      - Any special flags needed to compile 
#    WRAPPER_LDFLAGS       - Any special flags needed to link
#    MPILIBNAME         - Name of the MPI library
#    MPICXXLIBNAME      - Name of the C++ binding part of the MPI library
#    MPI_OTHERLIBS      - Other libraries needed in order to link 
#    
# We assume that (a) the C++ compiler can both compile and link programs
#
# Handling of command-line options:
#   This is a little tricky because some options may contain blanks.
#
# Special issues with shared libraries - todo
#
# --------------------------------------------------------------------------
# Set the default values of all variables.
#
# Directory locations: Fixed for any MPI implementation
31
prefix=/bgsys/drivers/ppcfloor/comm/default
32 33 34 35
exec_prefix=${prefix}
sysconfdir=${prefix}/etc
includedir=${prefix}/include
libdir=${exec_prefix}/lib
36
opalibdir=${exec_prefix}/lib
37 38 39 40 41

CP_WRAPPERS=@CP_WRAPPERS@
DARSHAN_LIB_PATH=@darshan_lib_path@
CP_ZLIB_LINK_FLAGS=@__CP_ZLIB_LINK_FLAGS@

42 43
#
# Default settings for compiler, flags, and libraries
44
CXX=`which bgxlC`
45
CXX_LINKPATH_SHL="-Wl,-rpath -Wl,"
46
WRAPPER_CXXFLAGS="-I/bgsys/drivers/ppcfloor/comm/sys/include"
47 48 49 50
WRAPPER_LDFLAGS="  "
MPILIBNAME="mpich.cnk"
PMPILIBNAME="pmpich.cnk"
MPICXXLIBNAME="cxxmpich.cnk"
51
MPI_OTHERLIBS=" -L/bgsys/drivers/ppcfloor/comm/sys/lib -Wl,-rpath,/bgsys/drivers/ppcfloor/comm/sys/lib -ldcmf.cnk      -ldcmfcoll.cnk      -lpthread -L/bgsys/drivers/ppcfloor/runtime/SPI -Wl,-rpath,/bgsys/drivers/ppcfloor/runtime/SPI -lSPI.cna -lrt "
52 53
NEEDSPLIB="no"
# MPIVERSION is the version of the MPICH2 library that mpicxx is intended for
54
MPIVERSION="1.1"
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
#
# Internal variables
# Show is set to echo to cause the compilation command to be echoed instead 
# of executed.
Show=
#
# End of initialization of variables
#---------------------------------------------------------------------
# Environment Variables.
# The environment variables MPICH_CXX may be used to override the 
# default choices.
# In addition, if there is a file $sysconfdir/mpicxx-$CXXname.conf, 
# where CXXname is the name of the compiler with all spaces replaced by hyphens
# (e.g., "CC -64" becomes "CC--64", that file is sources, allowing other
# changes to the compilation environment.  See the variables used by the 
# script (defined above)
if [ -n "$MPICH_CXX" ] ; then
    CXX="$MPICH_CXX"
    CXXname=`echo $CXX | sed 's/ /-/g'`
    if [ -s $sysconfdir/mpicxx-$CXXname.conf ] ; then
        . $sysconfdir/mpicxx-$CXXname.conf
    fi
fi
# Allow a profiling option to be selected through an environment variable
if [ -n "$MPICXX_PROFILE" ] ; then
    profConf=$MPICXX_PROFILE
fi
#
# ------------------------------------------------------------------------
# Argument processing.
# This is somewhat awkward because of the handling of arguments within
# the shell.  We want to handle arguments that include spaces without 
# loosing the spacing (an alternative would be to use a more powerful
# scripting language that would allow us to retain the array of values, 
# which the basic (rather than enhanced) Bourne shell does not.  
#
# Look through the arguments for arguments that indicate compile only.
# If these are *not* found, add the library options

linking=yes
allargs=("$@")
argno=0
for arg in "$@" ; do
    # Set addarg to no if this arg should be ignored by the C compiler
    addarg=yes
    case "$arg" in 
 	# ----------------------------------------------------------------
	# Compiler options that affect whether we are linking or no
    -c|-S|-E|-M|-MM)
    # The compiler links by default
    linking=no
    ;;
	# ----------------------------------------------------------------
	# Options that control how we use mpicxx (e.g., -show, 
	# -cxx=* -config=*
    -echo)
    addarg=no
    set -x
    ;;
    -cxx=*)
    CXX=`echo A$arg | sed -e 's/A-cxx=//g'`
    addarg=no
    ;;
    # Backwards compatibility for MPICH1 - scripts
    -CC=*)
    CXX=`echo A$arg | sed -e 's/A-CC=//g'`
    addarg=no
    ;;
    -show)
    addarg=no
    Show=echo
    ;;
    -config=*)
    addarg=no
    CXXname=`echo A$arg | sed -e 's/A-config=//g'`
    if [ -s "$sysconfdir/mpicxx-$CXXname.conf" ] ; then
        . "$sysconfdir/mpicxx-$CXXname.conf"
    else
	echo "Configuration file mpicxx-$CXXname.conf not found"
    fi
    ;;
    -compile-info|-compile_info)
    # -compile_info included for backward compatibility
    Show=echo
    addarg=no
    ;;
    -link-info|-link_info)
    # -link_info included for backward compatibility
    Show=echo
    addarg=no
    ;;
    -v)
    # Pass this argument to the compiler as well.
    echo "mpicxx for $MPIVERSION"
149 150 151 152
    # if there is only 1 argument, it must be -v.
    if [ "$#" -eq "1" ] ; then
        linking=no
    fi
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    ;;
    -profile=*)
    # Pass the name of a profiling configuration.  As
    # a special case, lib<name>.so or lib<name>.la may be used
    # if the library is in $libdir
    profConf=`echo A$arg | sed -e 's/A-profile=//g'`
    addarg=no
    # Loading the profConf file is handled below
    ;;
    -mpe=*)
    # Pass the name of a profiling configuration; this is a special
    # case for the MPE libs.  See -profile
    profConf=`echo A$arg | sed -e 's/A-mpe=//g'`
    profConf="mpe_$profConf"
    addarg=no
    # Loading the profConf file is handled below
    ;;
    -help)
171 172 173 174 175 176 177 178 179 180 181
    NC=`echo "$CXX" | sed 's%\/% %g' | awk '{print $NF}' -`
    if [ -f "$sysconfdir/mpixxx_opts.conf" ] ; then
        . $sysconfdir/mpixxx_opts.conf
        echo "    -cxx=xxx      - Reset the native compiler to xxx."
    else
        if [ -f "./mpixxx_opts.conf" ] ; then
            . ./mpixxx_opts.conf
            echo "    -cxx=xxx      - Reset the native compiler to xxx."
        fi
    fi
    exit 0
182 183 184 185 186 187 188 189 190 191 192 193
    ;;
    *)
    ;;

    esac
    if [ $addarg = no ] ; then
	unset allargs[$argno]
    fi
    # Some versions of bash do not accept ((argno++))
    argno=`expr $argno + 1`
done

194 195 196 197 198 199
if [ $# -eq 0 ] ; then
    echo "Error: Command line argument is needed!"
    "$0" -help
    exit 1
fi

200 201 202 203 204
# -----------------------------------------------------------------------
# Derived variables.  These are assembled from variables set from the
# default, environment, configuration file (if any) and command-line
# options (if any)
if [ "$NEEDSPLIB" = yes ] ; then
205
    mpilibs="-l$PMPILIBNAME -l$MPILIBNAME -lopa"
206
else
207
    mpilibs="-l$MPILIBNAME -lopa"
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
fi
cxxlibs=
if [ "$MPICXXLIBNAME" != "$MPILIBNAME" ] ; then
    cxxlibs="-l$MPICXXLIBNAME"
fi
#
# Init with the ones needed by MPI
CXXFLAGS="$WRAPPER_CXXFLAGS"
LDFLAGS="$WRAPPER_LDFLAGS"
#
#
# Handle the case of a profile switch
if [ -n "$profConf" ] ; then
    profConffile=
    if [ -s "$libdir/lib$profConf.a" -o -s "$libdir/lib$profConf.so" ] ; then
	mpilibs="-l$profConf $mpilibs"
    elif [ -s "$sysconfdir/$profConf.conf" ] ; then
	profConffile="$sysconfdir/$profConf.conf"
    elif [ -s "$profConf.conf" ] ; then
        profConffile="$profConf.conf"
    else
        echo "Profiling configuration file $profConf.conf not found in $sysconfdir"
    fi
    if [ -n "$profConffile" -a -s "$profConffile" ] ; then
	. $profConffile
	if [ -n "$PROFILE_INCPATHS" ] ; then
	    CXXFLAGS="$PROFILE_INCPATHS $CXXFLAGS"
        fi
        if [ -n "$PROFILE_PRELIB" ] ; then
	    mpilibs="$PROFILE_PRELIB $mpilibs"
        fi
        if [ -n "$PROFILE_POSTLIB" ] ; then
	    mpilibs="$mpilibs $PROFILE_POSTLIB"
        fi
    fi
fi
# A temporary statement to invoke the compiler
# Place the -L before any args incase there are any mpi libraries in there.
# Eventually, we'll want to move this after any non-MPI implementation 
# libraries
if [ "$linking" = yes ] ; then
    if [ -n "$CXX_LINKPATH_SHL" ] ; then
        # Prepend the path for the shared libraries to the library list
        shllibpath="$CXX_LINKPATH_SHL$libdir"
    fi
253 254 255 256 257 258 259 260 261 262 263

    # Trial run to generate a symbol listing.  We only enable Darshan if:
    # a) MPI is used
    # b) PMPI is _not_ used
    #
    # We want Darshan to get out of the way if the user is doing a runtime
    # test in configure (in which case MPI objects break the executable) or
    # if the user is using another PMPI based tool
    
    stock_link_cmd="$CXX ${allargs[@]} -I$includedir $CXXFLAGS $LDFLAGS -L$libdir -L$opalibdir $shllibpath $cxxlibs $mpilibs $MPI_OTHERLIBS"
    
264 265 266 267
    # if allargs includes any libraries, then we need to get 
    # -ldarshan-mpi-io in there first
    newallargs=`echo ${allargs[@]} | sed 's/ -l/ -ldarshan-mpi-io -l/'`
    darshan_link_cmd="$CXX $newallargs -L${DARSHAN_LIB_PATH} ${CP_ZLIB_LINK_FLAGS} -lcxxmpich.cnk -ldarshan-mpi-io -lz -I$includedir $CXXFLAGS ${CP_WRAPPERS} $LDFLAGS -L$libdir -L$opalibdir $shllibpath $cxxlibs $mpilibs $MPI_OTHERLIBS -L${DARSHAN_LIB_PATH} -ldarshan-posix" 
268 269 270 271 272 273

    used_darshan=0

    # create a temporary file
    tmpfile=`mktemp`
    # generate a map of the symbol names
274 275 276
    # don't use -shared for this step
    stock_link_cmd_no_shared=`echo $stock_link_cmd | sed 's/ -shared / /g'`
    $stock_link_cmd_no_shared -Wl,-Map,$tmpfile $LDFLAGS -o /dev/null >& /dev/null
277 278 279
    # is MPI in there?
    grep MPI $tmpfile >& /dev/null
    rc_mpi=$?
280 281
    # is PMPI being used for any init, finalize, or MPI-IO calls?
    grep -E \(PMPI_File_\)\|\(PMPI_Init\)\|\(PMPI_Finalize\) $tmpfile |grep -v mpich.cnk.a |grep \(PMPI >& /dev/null
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
    rc_pmpi=$?
    rm $tmpfile >& /dev/null

    # disable darshan if the executable is not an MPI program (this feature
    # mainly allows runtime configure tests to work
    if [ $rc_mpi -eq 0 ] ; then
        # disable darshan if something else is already using PMPI; we don't
        # want to cause any symbol conflicts
        if [ $rc_pmpi -ne 0 ] ; then
            $Show $darshan_link_cmd
            used_darshan=1
        fi
    fi

    # otherwise use the normal command line
    if [ "$used_darshan" = "0" ] ; then
        $Show $stock_link_cmd
299
    fi
300 301 302 303 304 305 306
    rc=$?
else
    $Show $CXX "${allargs[@]}" -I$includedir $CXXFLAGS
    rc=$?
fi

exit $rc