darshan-mmap-epilog.sh.in 2.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/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@

# 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
25 26
DARSHAN_MMAP_LOG1=$(ls $DARSHAN_MMAP_LOG_GLOB 2>/dev/null | head -n 1)
if [ -z $DARSHAN_MMAP_LOG1 ]; then
27 28 29 30
    exit 0
fi

# get the job start time from the first log file
Shane Snyder's avatar
Shane Snyder committed
31
JOB_START_DATE=$(${DARSHAN_INSTALL_DIR}/bin/darshan-parser $DARSHAN_MMAP_LOG1 |
32
    grep "# start_time_asci" | cut -d':' -f 2- | cut -d' ' -f 2-)
Shane Snyder's avatar
Shane Snyder committed
33 34 35 36
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=$((
37 38 39 40 41
    ($(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
42 43 44 45 46 47 48 49 50
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)
51

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

Shane Snyder's avatar
Shane Snyder committed
55 56 57 58 59 60 61 62 63 64 65 66 67
    # construct the per-node log file and store in the output directory
    $DARSHAN_INSTALL_DIR/bin/darshan-merge \
        --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)
    $DARSHAN_INSTALL_DIR/bin/darshan-merge
        --shared-redux --output ${OUTPUT_LOG_DIR}/${TMP_LOG} \
        $DARSHAN_MMAP_LOG_GLOB
    LOG_WRITE_END=$(date +%s)
68

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

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

exit 0