darshan-mmap-epilog.sh.in 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash

#
# Copyright (C) 2015 University of Chicago.
# See COPYRIGHT notice in top-level directory.
#

# grab the prefix of the darshan install directory
DARSHAN_INSTALL_DIR=@prefix@

# use the log dir specified at configure time
DARSHAN_LOG_DIR=@__DARSHAN_LOG_PATH@

14 15
JOB_END=$(date +"%s")

16 17 18 19 20 21 22 23 24 25 26
# use the default mmap log directory (/tmp), unless the 
# env variable is set to something
if [ -z "$DARSHAN_MMAP_LOGPATH" ]; then
    DARSHAN_MMAP_LOG_DIR=/tmp
else
    DARSHAN_MMAP_LOG_DIR=$DARSHAN_MMAP_LOGPATH
fi

DARSHAN_MMAP_LOG_GLOB=${DARSHAN_MMAP_LOG_DIR}/*id${SLURM_JOB_ID}*.darshan

# if no mmap logs found for this job, we have nothing to do
Shane Snyder's avatar
Shane Snyder committed
27 28
DARSHAN_MMAP_LOG1=$(ls $DARSHAN_MMAP_LOG_GLOB 2>/dev/null | head -n 1)
if [ -z $DARSHAN_MMAP_LOG1 ]; then
29 30 31 32
    exit 0
fi

# get the job start time from the first log file
Shane Snyder's avatar
Shane Snyder committed
33
JOB_START_DATE=$(${DARSHAN_INSTALL_DIR}/bin/darshan-parser $DARSHAN_MMAP_LOG1 |
34
    grep "# start_time_asci" | cut -d':' -f 2- | cut -d' ' -f 2-)
Shane Snyder's avatar
Shane Snyder committed
35 36 37 38
OUTPUT_YEAR=$(date --date="$(printf "$JOB_START_DATE")" +"%Y")
OUTPUT_MON=$(date --date="$(printf "$JOB_START_DATE")" +"%-m")
OUTPUT_DAY=$(date --date="$(printf "$JOB_START_DATE")" +"%-d")
OUTPUT_SECS=$((
39 40 41 42 43
    ($(date --date="$(printf "$JOB_START_DATE")" +"%-H") * 60 * 60) +
    ($(date --date="$(printf "$JOB_START_DATE")" +"%-M") * 60) +
    ($(date --date="$(printf "$JOB_START_DATE")" +"%-S"))
))

Shane Snyder's avatar
Shane Snyder committed
44 45 46 47 48 49 50 51 52
LOG_NAME_PRE=$(basename $DARSHAN_MMAP_LOG1 | cut -d'_' -f 1-3)

# construct full name of directory to store output log(s)
OUTPUT_LOG_DIR=${DARSHAN_LOG_DIR}/${OUTPUT_YEAR}/${OUTPUT_MON}/${OUTPUT_DAY}/
OUTPUT_NAME_PRE=${LOG_NAME_PRE}_${OUTPUT_MON}-${OUTPUT_DAY}-${OUTPUT_SECS}

if [ $SLURM_NNODES -gt 1 ]; then
    NODE_LOG_DIR=${OUTPUT_LOG_DIR}/${OUTPUT_NAME_PRE}
    NODE_NAME=$(uname -n)
53

Shane Snyder's avatar
Shane Snyder committed
54 55
    # multiple nodes, create a node log directory for everyone to write to
    mkdir -p $NODE_LOG_DIR
56

Shane Snyder's avatar
Shane Snyder committed
57
    # construct the per-node log file and store in the output directory
58
    $DARSHAN_INSTALL_DIR/bin/darshan-merge --job-end-time $JOB_END \
Shane Snyder's avatar
Shane Snyder committed
59 60 61 62 63 64 65
        --output ${NODE_LOG_DIR}/${LOG_NAME_PRE}_${NODE_NAME}.darshan \
        $DARSHAN_MMAP_LOG_GLOB
else
    TMP_LOG=${OUTPUT_NAME_PRE}.darshan

    # single node, just create the final output darshan log
    LOG_WRITE_START=$(date +%s)
66
    $DARSHAN_INSTALL_DIR/bin/darshan-merge --job-end-time $JOB_END \
Shane Snyder's avatar
Shane Snyder committed
67 68 69
        --shared-redux --output ${OUTPUT_LOG_DIR}/${TMP_LOG} \
        $DARSHAN_MMAP_LOG_GLOB
    LOG_WRITE_END=$(date +%s)
70

Shane Snyder's avatar
Shane Snyder committed
71 72
    WRITE_TM=$(($LOG_WRITE_END - $LOG_WRITE_START + 1))
    FINAL_LOG=${OUTPUT_NAME_PRE}-${RANDOM}_${WRITE_TM}.darshan
73

Shane Snyder's avatar
Shane Snyder committed
74 75
    mv ${OUTPUT_LOG_DIR}/${TMP_LOG} ${OUTPUT_LOG_DIR}/${FINAL_LOG}
fi
76

77 78
rm -f $DARSHAN_MMAP_LOG_GLOB

79
exit 0