darshan-mpi-io.c 78.9 KB
Newer Older
1 2 3 4 5
/*
 *  (C) 2009 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

6 7 8
#define _XOPEN_SOURCE 500
#define _GNU_SOURCE /* for tdestroy() */

9
#include "darshan-runtime-config.h"
10

11
#include <stdio.h>
12
#ifdef HAVE_MNTENT_H
13
#include <mntent.h>
14
#endif
15 16 17 18 19 20 21
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/types.h>
22
#include <sys/stat.h>
23
#include <sys/vfs.h>
24 25 26 27 28 29
#include <zlib.h>
#include <assert.h>
#include <search.h>

#include "mpi.h"
#include "darshan.h"
30
#include "darshan-dynamic.h"
31

32 33 34 35 36
extern char* __progname;

/* maximum number of memory segments each process will write to the log */
#define CP_MAX_MEM_SEGMENTS 8

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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
/* Some old versions of MPI don't provide all of these COMBINER definitions.  
 * If any are missing then we define them to an arbitrary value just to 
 * prevent compile errors in DATATYPE_INC().
 */
#ifndef MPI_COMBINER_NAMED
    #define MPI_COMBINER_NAMED CP_COMBINER_NAMED
#endif
#ifndef MPI_COMBINER_DUP
    #define MPI_COMBINER_DUP CP_COMBINER_DUP
#endif
#ifndef MPI_COMBINER_CONTIGUOUS
    #define MPI_COMBINER_CONTIGUOUS CP_COMBINER_CONTIGUOUS
#endif
#ifndef MPI_COMBINER_VECTOR
    #define MPI_COMBINER_VECTOR CP_COMBINER_VECTOR
#endif
#ifndef MPI_COMBINER_HVECTOR_INTEGER
    #define MPI_COMBINER_HVECTOR_INTEGER CP_COMBINER_HVECTOR_INTEGER
#endif
#ifndef MPI_COMBINER_HVECTOR
    #define MPI_COMBINER_HVECTOR CP_COMBINER_HVECTOR
#endif
#ifndef MPI_COMBINER_INDEXED
    #define MPI_COMBINER_INDEXED CP_COMBINER_INDEXED
#endif
#ifndef MPI_COMBINER_HINDEXED_INTEGER
    #define MPI_COMBINER_HINDEXED_INTEGER CP_COMBINER_HINDEXED_INTEGER
#endif
#ifndef MPI_COMBINER_HINDEXED
    #define MPI_COMBINER_HINDEXED CP_COMBINER_HINDEXED
#endif
#ifndef MPI_COMBINER_INDEXED_BLOCK
    #define MPI_COMBINER_INDEXED_BLOCK CP_COMBINER_INDEXED_BLOCK
#endif
#ifndef MPI_COMBINER_STRUCT_INTEGER
    #define MPI_COMBINER_STRUCT_INTEGER CP_COMBINER_STRUCT_INTEGER
#endif
#ifndef MPI_COMBINER_STRUCT
    #define MPI_COMBINER_STRUCT CP_COMBINER_STRUCT
#endif
#ifndef MPI_COMBINER_SUBARRAY
    #define MPI_COMBINER_SUBARRAY CP_COMBINER_SUBARRAY
#endif
#ifndef MPI_COMBINER_DARRAY
    #define MPI_COMBINER_DARRAY CP_COMBINER_DARRAY
#endif
#ifndef MPI_COMBINER_F90_REAL
    #define MPI_COMBINER_F90_REAL CP_COMBINER_F90_REAL
#endif
#ifndef MPI_COMBINER_F90_COMPLEX
    #define MPI_COMBINER_F90_COMPLEX CP_COMBINER_F90_COMPLEX
#endif
#ifndef MPI_COMBINER_F90_INTEGER
    #define MPI_COMBINER_F90_INTEGER CP_COMBINER_F90_INTEGER
#endif
#ifndef MPI_COMBINER_RESIZED
    #define MPI_COMBINER_RESIZED CP_COMBINER_RESIZED
#endif

96 97
#define CP_DATATYPE_INC(__file, __datatype) do {\
    int num_integers, num_addresses, num_datatypes, combiner, ret; \
98 99
    ret = DARSHAN_MPI_CALL(PMPI_Type_get_envelope)(__datatype, &num_integers, \
        &num_addresses, &num_datatypes, &combiner); \
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
    if(ret == MPI_SUCCESS) { \
        switch(combiner) { \
            case MPI_COMBINER_NAMED:\
                CP_INC(__file,CP_COMBINER_NAMED,1); break; \
            case MPI_COMBINER_DUP:\
                CP_INC(__file,CP_COMBINER_DUP,1); break; \
            case MPI_COMBINER_CONTIGUOUS:\
                CP_INC(__file,CP_COMBINER_CONTIGUOUS,1); break; \
            case MPI_COMBINER_VECTOR:\
                CP_INC(__file,CP_COMBINER_VECTOR,1); break; \
            case MPI_COMBINER_HVECTOR_INTEGER:\
                CP_INC(__file,CP_COMBINER_HVECTOR_INTEGER,1); break; \
            case MPI_COMBINER_HVECTOR:\
                CP_INC(__file,CP_COMBINER_HVECTOR,1); break; \
            case MPI_COMBINER_INDEXED:\
                CP_INC(__file,CP_COMBINER_INDEXED,1); break; \
            case MPI_COMBINER_HINDEXED_INTEGER:\
                CP_INC(__file,CP_COMBINER_HINDEXED_INTEGER,1); break; \
            case MPI_COMBINER_HINDEXED:\
                CP_INC(__file,CP_COMBINER_HINDEXED,1); break; \
            case MPI_COMBINER_INDEXED_BLOCK:\
                CP_INC(__file,CP_COMBINER_INDEXED_BLOCK,1); break; \
            case MPI_COMBINER_STRUCT_INTEGER:\
                CP_INC(__file,CP_COMBINER_STRUCT_INTEGER,1); break; \
            case MPI_COMBINER_STRUCT:\
                CP_INC(__file,CP_COMBINER_STRUCT,1); break; \
            case MPI_COMBINER_SUBARRAY:\
                CP_INC(__file,CP_COMBINER_SUBARRAY,1); break; \
            case MPI_COMBINER_DARRAY:\
                CP_INC(__file,CP_COMBINER_DARRAY,1); break; \
            case MPI_COMBINER_F90_REAL:\
                CP_INC(__file,CP_COMBINER_F90_REAL,1); break; \
            case MPI_COMBINER_F90_COMPLEX:\
                CP_INC(__file,CP_COMBINER_F90_COMPLEX,1); break; \
            case MPI_COMBINER_F90_INTEGER:\
                CP_INC(__file,CP_COMBINER_F90_INTEGER,1); break; \
            case MPI_COMBINER_RESIZED:\
                CP_INC(__file,CP_COMBINER_RESIZED,1); break; \
        } \
    } \
} while(0)

#define CP_RECORD_MPI_WRITE(__ret, __fh, __count, __datatype, __counter, __tm1, __tm2) do { \
    struct darshan_file_runtime* file; \
    int size = 0; \
    MPI_Aint extent = 0; \
    if(__ret != MPI_SUCCESS) break; \
    file = darshan_file_by_fh(__fh); \
    if(!file) break; \
149
    DARSHAN_MPI_CALL(PMPI_Type_size)(__datatype, &size);  \
150
    size = size * __count; \
151
    DARSHAN_MPI_CALL(PMPI_Type_extent)(__datatype, &extent); \
152 153 154 155
    CP_BUCKET_INC(file, CP_SIZE_WRITE_AGG_0_100, size); \
    CP_BUCKET_INC(file, CP_EXTENT_WRITE_0_100, extent); \
    CP_INC(file, __counter, 1); \
    CP_DATATYPE_INC(file, __datatype); \
156
    CP_F_INC_NO_OVERLAP(file, __tm1, __tm2, file->last_mpi_write_end, CP_F_MPI_WRITE_TIME); \
157 158 159 160 161 162 163 164 165 166 167 168
    if(CP_F_VALUE(file, CP_F_WRITE_START_TIMESTAMP) == 0) \
        CP_F_SET(file, CP_F_WRITE_START_TIMESTAMP, __tm1); \
    CP_F_SET(file, CP_F_WRITE_END_TIMESTAMP, __tm2); \
} while(0)

#define CP_RECORD_MPI_READ(__ret, __fh, __count, __datatype, __counter, __tm1, __tm2) do { \
    struct darshan_file_runtime* file; \
    int size = 0; \
    MPI_Aint extent = 0; \
    if(__ret != MPI_SUCCESS) break; \
    file = darshan_file_by_fh(__fh); \
    if(!file) break; \
169
    DARSHAN_MPI_CALL(PMPI_Type_size)(__datatype, &size);  \
170
    size = size * __count; \
171
    DARSHAN_MPI_CALL(PMPI_Type_extent)(__datatype, &extent); \
172 173 174 175
    CP_BUCKET_INC(file, CP_SIZE_READ_AGG_0_100, size); \
    CP_BUCKET_INC(file, CP_EXTENT_READ_0_100, extent); \
    CP_INC(file, __counter, 1); \
    CP_DATATYPE_INC(file, __datatype); \
176
    CP_F_INC_NO_OVERLAP(file, __tm1, __tm2, file->last_mpi_read_end, CP_F_MPI_READ_TIME); \
177 178 179 180 181
    if(CP_F_VALUE(file, CP_F_READ_START_TIMESTAMP) == 0) \
        CP_F_SET(file, CP_F_READ_START_TIMESTAMP, __tm1); \
    CP_F_SET(file, CP_F_READ_END_TIMESTAMP, __tm2); \
} while(0)

182
static void cp_normalize_timestamps(struct darshan_job_runtime* final_job);
183 184 185
static void cp_log_construct_indices(struct darshan_job_runtime* final_job,
    int rank, int* inout_count, int* lengths, void** pointers, char*
    trailing_data);
186
static int cp_log_write(struct darshan_job_runtime* final_job, int rank, 
187
    char* logfile_name, int count, int* lengths, void** pointers, double start_log_time);
188
static void cp_log_record_hints_and_ver(struct darshan_job_runtime* final_job, int rank);
189
static int cp_log_reduction(struct darshan_job_runtime* final_job, int rank, 
190
    char* logfile_name, MPI_Offset* next_offset);
191 192 193 194 195 196
static void darshan_file_reduce(void* infile_v, 
    void* inoutfile_v, int *len, 
    MPI_Datatype *datatype);
static int cp_log_compress(struct darshan_job_runtime* final_job,
    int rank, int* inout_count, int* lengths, void** pointers);
static int file_compare(const void* a, const void* b);
197 198 199 200 201 202
static int darshan_file_variance(
    struct darshan_file *infile_array,
    struct darshan_file *outfile_array,
    int count, int rank);
static void pairwise_variance_reduce (
    void *invec, void *inoutvec, int *len, MPI_Datatype *dt);
Philip Carns's avatar
Philip Carns committed
203
#if 0
204
static void debug_mounts(const char* mtab_file, const char* out_file);
Philip Carns's avatar
Philip Carns committed
205
#endif
206

207 208 209
static struct darshan_file_runtime* darshan_file_by_fh(MPI_File fh);
static void darshan_file_close_fh(MPI_File fh);
static struct darshan_file_runtime* darshan_file_by_name_setfh(const char* name, MPI_File fh);
210

211
#define CP_MAX_MNTS 64
Philip Carns's avatar
Philip Carns committed
212 213 214
#define CP_MAX_MNT_PATH 256
#define CP_MAX_MNT_TYPE 32
struct mnt_data
Philip Carns's avatar
Philip Carns committed
215
{
Philip Carns's avatar
Philip Carns committed
216 217 218 219 220 221 222
    int64_t hash;
    int64_t block_size;
    char path[CP_MAX_MNT_PATH];
    char type[CP_MAX_MNT_TYPE];
};
static struct mnt_data mnt_data_array[CP_MAX_MNTS];
static int mnt_data_count = 0;
223

224 225 226 227 228 229 230
struct variance_dt
{
    double n;
    double T;
    double S;
};

231
void darshan_mpi_initialize(int *argc, char ***argv)
232 233 234
{
    int nprocs;
    int rank;
Philip Carns's avatar
Philip Carns committed
235 236
    int timing_flag = 0;
    double init_start, init_time, init_max;
237

238 239
    DARSHAN_MPI_CALL(PMPI_Comm_size)(MPI_COMM_WORLD, &nprocs);
    DARSHAN_MPI_CALL(PMPI_Comm_rank)(MPI_COMM_WORLD, &rank);
Philip Carns's avatar
Philip Carns committed
240 241 242 243 244 245
    
    if(getenv("DARSHAN_INTERNAL_TIMING"))
        timing_flag = 1;

    if(timing_flag)
        init_start = DARSHAN_MPI_CALL(PMPI_Wtime)();
246 247 248 249 250 251 252 253 254 255

    if(argc && argv)
    {
        darshan_initialize(*argc, *argv, nprocs, rank);
    }
    else
    {
        /* we don't see argc and argv here in fortran */
        darshan_initialize(0, NULL, nprocs, rank);
    }
Philip Carns's avatar
Philip Carns committed
256 257 258 259 260 261 262 263 264 265 266 267
    
    if(timing_flag)
    {
        init_time = DARSHAN_MPI_CALL(PMPI_Wtime)() - init_start;
        DARSHAN_MPI_CALL(PMPI_Reduce)(&init_time, &init_max, 1,
            MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
        if(rank == 0)
        {
            printf("#darshan:<op>\t<nprocs>\t<time>\n");
            printf("darshan:init\t%d\t%f\n", nprocs, init_max);
        }
    }
268

269
    return;
270 271 272 273 274 275 276 277 278 279 280
}

void darshan_shutdown(int timing_flag)
{
    int rank;
    char* logfile_name;
    struct darshan_job_runtime* final_job;
    double start_log_time = 0;
    int all_ret = 0;
    int local_ret = 0;
    MPI_Offset next_offset = 0;
281
    char* user_logfile_name;
282
    char* jobid_str;
283 284
    char* envjobid;
    char* logpath;
285 286 287 288 289 290
    int jobid;
    int index_count = 0;
    int lengths[CP_MAX_MEM_SEGMENTS];
    void* pointers[CP_MAX_MEM_SEGMENTS];
    int ret;
    double red1=0, red2=0, gz1=0, gz2=0, write1=0, write2=0, tm_end=0;
Philip Carns's avatar
Philip Carns committed
291
    double bcst=0;
292
    int nprocs;
293
    time_t start_time_tmp = 0;
294 295
    uint64_t logmod;
    char hname[HOST_NAME_MAX];
296 297 298 299 300
    char* logpath_override = NULL;
#ifdef __CP_LOG_ENV
    char env_check[256];
    char* env_tok;
#endif
301
    uint64_t hlevel;
302 303
    int64_t first_start_time;
    int64_t last_end_time;
304 305 306 307 308

    CP_LOCK();
    if(!darshan_global_job)
    {
        CP_UNLOCK();
309
        return;
310 311 312 313 314 315 316 317
    }
    /* disable further tracing while hanging onto the data so that we can
     * write it out
     */
    final_job = darshan_global_job;
    darshan_global_job = NULL;
    CP_UNLOCK();

318
    start_log_time = DARSHAN_MPI_CALL(PMPI_Wtime)();
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364

    /* figure out which access sizes to log */
    darshan_walk_file_accesses(final_job);

    /* if the records have been condensed, then zero out fields that are no
     * longer valid for safety 
     */
    if(final_job->flags & CP_FLAG_CONDENSED && final_job->file_count)
    {
        CP_SET(&final_job->file_runtime_array[0], CP_MODE, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_CONSEC_READS, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_CONSEC_WRITES, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_SEQ_READS, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_SEQ_WRITES, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_STRIDE1_STRIDE, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_STRIDE2_STRIDE, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_STRIDE3_STRIDE, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_STRIDE4_STRIDE, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_STRIDE1_COUNT, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_STRIDE2_COUNT, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_STRIDE3_COUNT, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_STRIDE4_COUNT, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_ACCESS1_ACCESS, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_ACCESS2_ACCESS, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_ACCESS3_ACCESS, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_ACCESS4_ACCESS, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_ACCESS1_COUNT, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_ACCESS2_COUNT, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_ACCESS3_COUNT, 0);
        CP_SET(&final_job->file_runtime_array[0], CP_ACCESS4_COUNT, 0);
        
        CP_F_SET(&final_job->file_runtime_array[0], CP_F_OPEN_TIMESTAMP, 0);
        CP_F_SET(&final_job->file_runtime_array[0], CP_F_CLOSE_TIMESTAMP, 0);
        CP_F_SET(&final_job->file_runtime_array[0], CP_F_READ_START_TIMESTAMP, 0);
        CP_F_SET(&final_job->file_runtime_array[0], CP_F_READ_END_TIMESTAMP, 0);
        CP_F_SET(&final_job->file_runtime_array[0], CP_F_WRITE_START_TIMESTAMP, 0);
        CP_F_SET(&final_job->file_runtime_array[0], CP_F_WRITE_END_TIMESTAMP, 0);
    }

    logfile_name = malloc(PATH_MAX);
    if(!logfile_name)
    {
        darshan_finalize(final_job);
        return;
    }

365
    DARSHAN_MPI_CALL(PMPI_Comm_rank)(MPI_COMM_WORLD, &rank);
366 367 368 369

    /* construct log file name */
    if(rank == 0)
    {
370 371 372 373 374 375 376
        /* Use CP_JOBID_OVERRIDE for the env var or CP_JOBID */
        envjobid = getenv(CP_JOBID_OVERRIDE);
        if (!envjobid)
        {
            envjobid = CP_JOBID;
        }

377
        /* find a job id */
378
        jobid_str = getenv(envjobid);
379 380 381 382 383 384 385 386 387 388 389
        if(jobid_str)
        {
            /* in cobalt we can find it in env var */
            ret = sscanf(jobid_str, "%d", &jobid);
        }
        if(!jobid_str || ret != 1)
        {
            /* use pid as fall back */
            jobid = getpid();
        }

390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
        /* add jobid to darshan runtime info */
        final_job->log_job.jobid = (int64_t)jobid;

        /* if user specifies a logfile name (and path), use that. otherwise automatically generate */
        user_logfile_name = getenv("DARSHAN_LOGFILE");
        if(user_logfile_name)
        {
            if(strlen(user_logfile_name) >= PATH_MAX)
            {
                logfile_name[0] = '\0';
                fprintf(stderr, "darshan library warning: user given log file path too long\n");
            }
            else
            {
                strncpy(logfile_name, user_logfile_name, PATH_MAX);
            }
        }
        else
        {
            char cuser[L_cuserid] = {0};
            struct tm* my_tm;

            /* Use CP_LOG_PATH_OVERRIDE for the value or __CP_LOG_PATH */
            logpath = getenv(CP_LOG_PATH_OVERRIDE);
            if (!logpath)
            {
#ifdef __CP_LOG_PATH
                logpath = __CP_LOG_PATH;
#endif
            }

            /* break out time into something human readable */
            start_time_tmp += final_job->log_job.start_time;
            my_tm = localtime(&start_time_tmp);

            /* get the username for this job.  In order we will try each of the
             * following until one of them succeeds:
             *
             * - cuserid()
             * - getenv("LOGNAME")
             * - snprintf(..., geteuid());
             *
             * Note that we do not use getpwuid() because it generally will not
             * work in statically compiled binaries.
             */
435

436
#ifndef DARSHAN_DISABLE_CUSERID
437
            cuserid(cuser);
438
#endif
439

440 441
            /* if cuserid() didn't work, then check the environment */
            if (strcmp(cuser, "") == 0)
442
            {
443 444 445 446 447 448
                char* logname_string;
                logname_string = getenv("LOGNAME");
                if(logname_string)
                {
                    strncpy(cuser, logname_string, (L_cuserid-1));
                }
449

450
            }
451

452 453 454 455 456 457
            /* if cuserid() and environment both fail, then fall back to uid */
            if (strcmp(cuser, "") == 0)
            {
                uid_t uid = geteuid();
                snprintf(cuser, sizeof(cuser), "%u", uid);
            }
458

459 460 461 462
            /* generate a random number to help differentiate the log */
            hlevel=DARSHAN_MPI_CALL(PMPI_Wtime)() * 1000000;
            (void) gethostname(hname, sizeof(hname));
            logmod = darshan_hash((void*)hname,strlen(hname),hlevel);
463

464 465 466 467
            /* see if darshan was configured using the --with-logpath-by-env
             * argument, which allows the user to specify an absolute path to
             * place logs via an env variable.
             */
468
#ifdef __CP_LOG_ENV
469 470
            /* just silently skip if the environment variable list is too big */
            if(strlen(__CP_LOG_ENV) < 256)
471
            {
472 473 474 475 476
                /* copy env variable list to a temporary buffer */
                strcpy(env_check, __CP_LOG_ENV);
                /* tokenize the comma-separated list */
                env_tok = strtok(env_check, ",");
                if(env_tok)
477
                {
478
                    do
479
                    {
480 481 482 483 484 485 486 487 488
                        /* check each env variable in order */
                        logpath_override = getenv(env_tok); 
                        if(logpath_override)
                        {
                            /* stop as soon as we find a match */
                            break;
                        }
                    }while((env_tok = strtok(NULL, ",")));
                }
489 490
            }
#endif
491 492 493 494 495 496 497 498
           
            if(logpath_override)
            {
                ret = snprintf(logfile_name, PATH_MAX, 
                    "%s/%s_%s_id%d_%d-%d-%d-%" PRIu64 ".darshan_partial",
                    logpath_override, 
                    cuser, __progname, jobid,
                    (my_tm->tm_mon+1), 
499 500 501
                my_tm->tm_mday, 
                (my_tm->tm_hour*60*60 + my_tm->tm_min*60 + my_tm->tm_sec),
                logmod);
502 503 504 505 506 507 508 509 510
                if(ret == (PATH_MAX-1))
                {
                    /* file name was too big; squish it down */
                    snprintf(logfile_name, PATH_MAX,
                        "%s/id%d.darshan_partial",
                        logpath_override, jobid);
                }
            }
            else if(logpath)
511
            {
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
                ret = snprintf(logfile_name, PATH_MAX, 
                    "%s/%d/%d/%d/%s_%s_id%d_%d-%d-%d-%" PRIu64 ".darshan_partial",
                    logpath, (my_tm->tm_year+1900), 
                    (my_tm->tm_mon+1), my_tm->tm_mday, 
                    cuser, __progname, jobid,
                    (my_tm->tm_mon+1), 
                    my_tm->tm_mday, 
                    (my_tm->tm_hour*60*60 + my_tm->tm_min*60 + my_tm->tm_sec),
                    logmod);
                if(ret == (PATH_MAX-1))
                {
                    /* file name was too big; squish it down */
                    snprintf(logfile_name, PATH_MAX,
                        "%s/id%d.darshan_partial",
                        logpath, jobid);
                }
528
            }
529
            else
530
            {
531
                logfile_name[0] = '\0';
532
            }
533 534 535 536
        }
    }

    /* broadcast log file name */
Philip Carns's avatar
Philip Carns committed
537
    bcst=DARSHAN_MPI_CALL(PMPI_Wtime)();
538 539
    DARSHAN_MPI_CALL(PMPI_Bcast)(logfile_name, PATH_MAX, MPI_CHAR, 0,
        MPI_COMM_WORLD);
540

541 542 543 544
    if(strlen(logfile_name) == 0)
    {
        /* failed to generate log file name */
        darshan_finalize(final_job);
545
        return;
546 547
    }

548 549
    final_job->log_job.end_time = time(NULL);

550 551 552 553 554 555 556 557 558 559 560
    /* reduce to report first start time and last end time across all ranks
     * at rank 0
     */
    DARSHAN_MPI_CALL(PMPI_Reduce)(&final_job->log_job.start_time, &first_start_time, 1, MPI_LONG_LONG, MPI_MIN, 0, MPI_COMM_WORLD); 
    DARSHAN_MPI_CALL(PMPI_Reduce)(&final_job->log_job.end_time, &last_end_time, 1, MPI_LONG_LONG, MPI_MAX, 0, MPI_COMM_WORLD); 
    if(rank == 0)
    {
        final_job->log_job.start_time = first_start_time;
        final_job->log_job.end_time = last_end_time;
    }

561 562
    /* reduce records for shared files */
    if(timing_flag)
563
        red1 = DARSHAN_MPI_CALL(PMPI_Wtime)();
564 565 566 567 568 569 570 571 572
    if(getenv("DARSHAN_DISABLE_SHARED_REDUCTION"))
    {
        local_ret = 0;
    }
    else
    {
        local_ret = cp_log_reduction(final_job, rank, logfile_name, 
            &next_offset);
    }
573
    if(timing_flag)
574 575
        red2 = DARSHAN_MPI_CALL(PMPI_Wtime)();
    DARSHAN_MPI_CALL(PMPI_Allreduce)(&local_ret, &all_ret, 1, MPI_INT, MPI_LOR, 
576 577
        MPI_COMM_WORLD);

578 579 580
    /* adjust timestamps in any remaining records */
    cp_normalize_timestamps(final_job);

581 582 583
    /* if we are using any hints to write the log file, then record those
     * hints in the log file header
     */
584
    cp_log_record_hints_and_ver(final_job, rank);
585

586 587 588 589
    if(all_ret == 0)
    {
        /* collect data to write from local process */
        cp_log_construct_indices(final_job, rank, &index_count, lengths, 
590
            pointers, final_job->trailing_data);
591 592 593 594 595 596
    }

    if(all_ret == 0)
    {
        /* compress data */
        if(timing_flag)
597
            gz1 = DARSHAN_MPI_CALL(PMPI_Wtime)();
598 599 600
        local_ret = cp_log_compress(final_job, rank, &index_count, 
            lengths, pointers);
        if(timing_flag)
601 602 603
            gz2 = DARSHAN_MPI_CALL(PMPI_Wtime)();
        DARSHAN_MPI_CALL(PMPI_Allreduce)(&local_ret, &all_ret, 1,
            MPI_INT, MPI_LOR, MPI_COMM_WORLD);
604 605 606 607 608 609
    }

    if(all_ret == 0)
    {
        /* actually write out log file */
        if(timing_flag)
610
            write1 = DARSHAN_MPI_CALL(PMPI_Wtime)();
611
        local_ret = cp_log_write(final_job, rank, logfile_name, 
612 613
            index_count, lengths, pointers, start_log_time);
        if(timing_flag)
614 615 616
            write2 = DARSHAN_MPI_CALL(PMPI_Wtime)();
        DARSHAN_MPI_CALL(PMPI_Allreduce)(&local_ret, &all_ret, 1,
            MPI_INT, MPI_LOR, MPI_COMM_WORLD);
617 618
    }

619
    if(rank == 0)
620
    {
621 622 623 624 625 626 627 628
        if(all_ret != 0)
        {
            fprintf(stderr, "darshan library warning: unable to write log file %s\n", logfile_name);
            /* if any process failed to write log, then delete the whole 
             * file so we don't leave corrupted results
             */
            unlink(logfile_name);
        }
629 630 631 632 633 634 635 636 637
        else if (user_logfile_name)
        {
            /* we do not need to rename file, just change the permissions */
#ifdef __CP_GROUP_READABLE_LOGS
            chmod(user_logfile_name, (S_IRUSR|S_IRGRP));
#else
            chmod(user_logfile_name, (S_IRUSR));
#endif
        }
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
        else
        {
            /* rename from *.darshan_partial to *-<logwritetime>.darshan.gz,
             * which indicates that this log file is complete and ready for
             * analysis
             */ 
            char* mod_index;
            double end_log_time;
            char* new_logfile_name;

            new_logfile_name = malloc(PATH_MAX);
            if(new_logfile_name)
            {
                new_logfile_name[0] = '\0';
                end_log_time = DARSHAN_MPI_CALL(PMPI_Wtime)();
                strcat(new_logfile_name, logfile_name);
                mod_index = strstr(new_logfile_name, ".darshan_partial");
                sprintf(mod_index, "_%d.darshan.gz", (int)(end_log_time-start_log_time+1));
                rename(logfile_name, new_logfile_name);
                /* set permissions on log file */
658 659 660
#ifdef __CP_GROUP_READABLE_LOGS
                chmod(new_logfile_name, (S_IRUSR|S_IRGRP)); 
#else
661
                chmod(new_logfile_name, (S_IRUSR)); 
662
#endif
663 664 665
                free(new_logfile_name);
            }
        }
666 667
    }

668 669
    if(final_job->trailing_data)
        free(final_job->trailing_data);
Philip Carns's avatar
Philip Carns committed
670
    mnt_data_count = 0;
671 672 673 674 675 676 677 678 679
    free(logfile_name);
    darshan_finalize(final_job);
    
    if(timing_flag)
    {
        double red_tm, red_slowest;
        double gz_tm, gz_slowest;
        double write_tm, write_slowest;
        double all_tm, all_slowest;
680
        double bcst_tm, bcst_slowest;
681
        
682
        tm_end = DARSHAN_MPI_CALL(PMPI_Wtime)();
683

Philip Carns's avatar
Philip Carns committed
684
        bcst_tm= red1-bcst;
685 686 687 688 689
        red_tm = red2-red1;
        gz_tm = gz2-gz1;
        write_tm = write2-write1;
        all_tm = tm_end-start_log_time;

690 691 692 693 694 695 696 697 698 699
        DARSHAN_MPI_CALL(PMPI_Reduce)(&red_tm, &red_slowest, 1,
            MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
        DARSHAN_MPI_CALL(PMPI_Reduce)(&gz_tm, &gz_slowest, 1,
            MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
        DARSHAN_MPI_CALL(PMPI_Reduce)(&write_tm, &write_slowest, 1,
            MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
        DARSHAN_MPI_CALL(PMPI_Reduce)(&all_tm, &all_slowest, 1,
            MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
        DARSHAN_MPI_CALL(PMPI_Reduce)(&bcst_tm, &bcst_slowest, 1,
            MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
700 701 702

        if(rank == 0)
        {
703
            DARSHAN_MPI_CALL(PMPI_Comm_size)(MPI_COMM_WORLD, &nprocs);
Philip Carns's avatar
Philip Carns committed
704 705 706 707 708
            printf("#darshan:<op>\t<nprocs>\t<time>\n");
            printf("darshan:bcst\t%d\t%f\n", nprocs, bcst_slowest);
            printf("darshan:reduce\t%d\t%f\n", nprocs, red_slowest);
            printf("darshan:gzip\t%d\t%f\n", nprocs, gz_slowest);
            printf("darshan:write\t%d\t%f\n", nprocs, write_slowest);
Philip Carns's avatar
Philip Carns committed
709
            printf("darshan:bcast+reduce+gzip+write\t%d\t%f\n", nprocs, all_slowest);
710 711 712 713 714 715
        }
    }

    return;
}

716 717 718
#ifdef HAVE_MPIIO_CONST
int MPI_File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info, MPI_File *fh) 
#else
719
int MPI_File_open(MPI_Comm comm, char *filename, int amode, MPI_Info info, MPI_File *fh) 
720
#endif
721 722 723 724 725 726 727 728
{
    int ret;
    struct darshan_file_runtime* file;
    char* tmp;
    int comm_size;
    double tm1, tm2;

    tm1 = darshan_wtime();
729
    ret = DARSHAN_MPI_CALL(PMPI_File_open)(comm, filename, amode, info, fh);
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
    tm2 = darshan_wtime();

    if(ret == MPI_SUCCESS)
    {
        CP_LOCK();

        /* use ROMIO approach to strip prefix if present */
        /* strip off prefix if there is one, but only skip prefixes
         * if they are greater than length one to allow for windows
         * drive specifications (e.g. c:\...) 
         */
        tmp = strchr(filename, ':');
        if (tmp > filename + 1) {
            filename = tmp + 1;
        }

746 747
        file = darshan_file_by_name_setfh(filename, (*fh));
        if(file)
748 749
        {
            CP_SET(file, CP_MODE, amode);
750
            CP_F_INC_NO_OVERLAP(file, tm1, tm2, file->last_mpi_meta_end, CP_F_MPI_META_TIME);
751
            if(CP_F_VALUE(file, CP_F_OPEN_TIMESTAMP) == 0)
752
                CP_F_SET(file, CP_F_OPEN_TIMESTAMP,
Philip Carns's avatar
Philip Carns committed
753
                tm1);
754
            DARSHAN_MPI_CALL(PMPI_Comm_size)(comm, &comm_size);
755 756 757 758 759 760 761 762 763 764 765 766 767
            if(comm_size == 1)
            {
                CP_INC(file, CP_INDEP_OPENS, 1);
            }
            else
            {
                CP_INC(file, CP_COLL_OPENS, 1);
            }
            if(info != MPI_INFO_NULL)
            {
                CP_INC(file, CP_HINTS, 1);
            }
        }
768

769 770 771 772 773 774 775 776 777 778 779 780 781 782
        CP_UNLOCK();
    }

    return(ret);
}

int MPI_File_close(MPI_File *fh) 
{
    struct darshan_file_runtime* file;
    MPI_File tmp_fh = *fh;
    double tm1, tm2;
    int ret;
    
    tm1 = darshan_wtime();
783
    ret = DARSHAN_MPI_CALL(PMPI_File_close)(fh);
784 785 786 787 788 789
    tm2 = darshan_wtime();

    CP_LOCK();
    file = darshan_file_by_fh(tmp_fh);
    if(file)
    {
790
        CP_F_SET(file, CP_F_CLOSE_TIMESTAMP, DARSHAN_MPI_CALL(PMPI_Wtime)());
791
        CP_F_INC_NO_OVERLAP(file, tm1, tm2, file->last_mpi_meta_end, CP_F_MPI_META_TIME);
792
        darshan_file_close_fh(tmp_fh);
793 794 795 796 797 798 799 800 801 802 803 804 805
    }
    CP_UNLOCK();

    return(ret);
}

int MPI_File_sync(MPI_File fh)
{
    int ret;
    struct darshan_file_runtime* file;
    double tm1, tm2;

    tm1 = darshan_wtime();
806
    ret = DARSHAN_MPI_CALL(PMPI_File_sync)(fh);
807 808 809 810 811 812 813
    tm2 = darshan_wtime();
    if(ret == MPI_SUCCESS)
    {
        CP_LOCK();
        file = darshan_file_by_fh(fh);
        if(file)
        {
814
            CP_F_INC_NO_OVERLAP(file, tm1, tm2, file->last_mpi_write_end, CP_F_MPI_WRITE_TIME);
815 816 817 818 819 820 821 822 823
            CP_INC(file, CP_SYNCS, 1);
        }
        CP_UNLOCK();
    }

    return(ret);
}


824 825 826 827
#ifdef HAVE_MPIIO_CONST
int MPI_File_set_view(MPI_File fh, MPI_Offset disp, MPI_Datatype etype, 
    MPI_Datatype filetype, const char *datarep, MPI_Info info)
#else
828 829
int MPI_File_set_view(MPI_File fh, MPI_Offset disp, MPI_Datatype etype, 
    MPI_Datatype filetype, char *datarep, MPI_Info info)
830
#endif
831 832 833 834 835 836
{
    int ret;
    struct darshan_file_runtime* file;
    double tm1, tm2;

    tm1 = darshan_wtime();
837 838
    ret = DARSHAN_MPI_CALL(PMPI_File_set_view)(fh, disp, etype,
        filetype, datarep, info);
839 840 841 842 843 844 845 846 847 848
    tm2 = darshan_wtime();
    if(ret == MPI_SUCCESS)
    {
        CP_LOCK();
        file = darshan_file_by_fh(fh);
        if(file)
        {
            CP_INC(file, CP_VIEWS, 1);
            if(info != MPI_INFO_NULL)
            {
849
                CP_F_INC_NO_OVERLAP(file, tm1, tm2, file->last_mpi_meta_end, CP_F_MPI_META_TIME);
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
                CP_INC(file, CP_HINTS, 1);
            }
            CP_DATATYPE_INC(file, filetype);
        }
        CP_UNLOCK();
    }

    return(ret);
}

int MPI_File_read(MPI_File fh, void *buf, int count, 
    MPI_Datatype datatype, MPI_Status *status)
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
867
    ret = DARSHAN_MPI_CALL(PMPI_File_read)(fh, buf, count, datatype, status);
868 869 870 871 872 873 874 875 876 877 878 879 880 881
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_READ(ret, fh, count, datatype, CP_INDEP_READS, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

int MPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf,
    int count, MPI_Datatype datatype, MPI_Status *status)
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
882 883
    ret = DARSHAN_MPI_CALL(PMPI_File_read_at)(fh, offset, buf,
        count, datatype, status);
884 885 886 887 888 889 890 891 892 893 894 895 896 897
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_READ(ret, fh, count, datatype, CP_INDEP_READS, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

int MPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void * buf,
    int count, MPI_Datatype datatype, MPI_Status * status)
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
898 899
    ret = DARSHAN_MPI_CALL(PMPI_File_read_at_all)(fh, offset, buf,
        count, datatype, status);
900 901 902 903 904 905 906 907 908 909 910 911 912
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_READ(ret, fh, count, datatype, CP_COLL_READS, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

int MPI_File_read_all(MPI_File fh, void * buf, int count, MPI_Datatype datatype, MPI_Status *status)
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
913 914
    ret = DARSHAN_MPI_CALL(PMPI_File_read_all)(fh, buf, count,
        datatype, status);
915 916 917 918 919 920 921 922 923 924 925 926 927
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_READ(ret, fh, count, datatype, CP_COLL_READS, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

int MPI_File_read_shared(MPI_File fh, void * buf, int count, MPI_Datatype datatype, MPI_Status *status)
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
928 929
    ret = DARSHAN_MPI_CALL(PMPI_File_read_shared)(fh, buf, count,
        datatype, status);
930 931 932 933 934 935 936 937 938 939 940 941 942 943
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_READ(ret, fh, count, datatype, CP_INDEP_READS, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

int MPI_File_read_ordered(MPI_File fh, void * buf, int count, 
    MPI_Datatype datatype, MPI_Status * status)
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
944 945
    ret = DARSHAN_MPI_CALL(PMPI_File_read_ordered)(fh, buf, count,
        datatype, status);
946 947 948 949 950 951 952 953 954 955 956 957 958 959
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_READ(ret, fh, count, datatype, CP_COLL_READS, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

int MPI_File_read_at_all_begin(MPI_File fh, MPI_Offset offset, void * buf,
    int count, MPI_Datatype datatype)
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
960 961
    ret = DARSHAN_MPI_CALL(PMPI_File_read_at_all_begin)(fh, offset, buf,
        count, datatype);
962 963 964 965 966 967 968 969 970 971 972 973 974
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_READ(ret, fh, count, datatype, CP_SPLIT_READS, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

int MPI_File_read_all_begin(MPI_File fh, void * buf, int count, MPI_Datatype datatype)
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
975
    ret = DARSHAN_MPI_CALL(PMPI_File_read_all_begin)(fh, buf, count, datatype);
976 977 978 979 980 981 982 983 984 985 986 987 988
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_READ(ret, fh, count, datatype, CP_SPLIT_READS, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

int MPI_File_read_ordered_begin(MPI_File fh, void * buf, int count, MPI_Datatype datatype)
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
989 990
    ret = DARSHAN_MPI_CALL(PMPI_File_read_ordered_begin)(fh, buf, count,
        datatype);
991 992 993 994 995 996 997 998
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_READ(ret, fh, count, datatype, CP_SPLIT_READS, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

int MPI_File_iread_at(MPI_File fh, MPI_Offset offset, void * buf,
Philip Carns's avatar
Philip Carns committed
999
    int count, MPI_Datatype datatype, __D_MPI_REQUEST *request)
1000 1001 1002 1003 1004
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
1005 1006
    ret = DARSHAN_MPI_CALL(PMPI_File_iread_at)(fh, offset, buf, count,
        datatype, request);
1007 1008 1009 1010 1011 1012 1013
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_READ(ret, fh, count, datatype, CP_NB_READS, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

Philip Carns's avatar
Philip Carns committed
1014
int MPI_File_iread(MPI_File fh, void * buf, int count, MPI_Datatype datatype, __D_MPI_REQUEST * request)
1015 1016 1017 1018 1019
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
1020
    ret = DARSHAN_MPI_CALL(PMPI_File_iread)(fh, buf, count, datatype, request);
1021 1022 1023 1024 1025 1026 1027 1028
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_READ(ret, fh, count, datatype, CP_NB_READS, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

int MPI_File_iread_shared(MPI_File fh, void * buf, int count,
Philip Carns's avatar
Philip Carns committed
1029
    MPI_Datatype datatype, __D_MPI_REQUEST * request)
1030 1031 1032 1033 1034
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
1035 1036
    ret = DARSHAN_MPI_CALL(PMPI_File_iread_shared)(fh, buf, count,
        datatype, request);
1037 1038 1039 1040 1041 1042 1043 1044
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_READ(ret, fh, count, datatype, CP_NB_READS, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}


1045 1046 1047 1048
#ifdef HAVE_MPIIO_CONST
int MPI_File_write(MPI_File fh, const void *buf, int count, 
    MPI_Datatype datatype, MPI_Status *status)
#else
1049 1050
int MPI_File_write(MPI_File fh, void *buf, int count, 
    MPI_Datatype datatype, MPI_Status *status)
1051
#endif
1052 1053 1054 1055 1056
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
1057
    ret = DARSHAN_MPI_CALL(PMPI_File_write)(fh, buf, count, datatype, status);
1058 1059 1060 1061 1062 1063 1064
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_WRITE(ret, fh, count, datatype, CP_INDEP_WRITES, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

1065 1066 1067 1068
#ifdef HAVE_MPIIO_CONST
int MPI_File_write_at(MPI_File fh, MPI_Offset offset, const void *buf,
    int count, MPI_Datatype datatype, MPI_Status *status)
#else
1069 1070
int MPI_File_write_at(MPI_File fh, MPI_Offset offset, void *buf,
    int count, MPI_Datatype datatype, MPI_Status *status)
1071
#endif
1072 1073 1074 1075 1076
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
1077 1078
    ret = DARSHAN_MPI_CALL(PMPI_File_write_at)(fh, offset, buf,
        count, datatype, status);
1079 1080 1081 1082 1083 1084 1085
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_WRITE(ret, fh, count, datatype, CP_INDEP_WRITES, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

1086 1087 1088 1089
#ifdef HAVE_MPIIO_CONST
int MPI_File_write_at_all(MPI_File fh, MPI_Offset offset, const void * buf,
    int count, MPI_Datatype datatype, MPI_Status * status)
#else
1090 1091
int MPI_File_write_at_all(MPI_File fh, MPI_Offset offset, void * buf,
    int count, MPI_Datatype datatype, MPI_Status * status)
1092
#endif
1093 1094 1095 1096 1097
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
1098 1099
    ret = DARSHAN_MPI_CALL(PMPI_File_write_at_all)(fh, offset, buf,
        count, datatype, status);
1100 1101 1102 1103 1104 1105 1106
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_WRITE(ret, fh, count, datatype, CP_COLL_WRITES, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

1107 1108 1109
#ifdef HAVE_MPIIO_CONST
int MPI_File_write_all(MPI_File fh, const void * buf, int count, MPI_Datatype datatype, MPI_Status *status)
#else
1110
int MPI_File_write_all(MPI_File fh, void * buf, int count, MPI_Datatype datatype, MPI_Status *status)
1111
#endif
1112 1113 1114 1115 1116
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
1117 1118
    ret = DARSHAN_MPI_CALL(PMPI_File_write_all)(fh, buf, count,
        datatype, status);
1119 1120 1121 1122 1123 1124 1125
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_WRITE(ret, fh, count, datatype, CP_COLL_WRITES, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

1126 1127 1128
#ifdef HAVE_MPIIO_CONST
int MPI_File_write_shared(MPI_File fh, const void * buf, int count, MPI_Datatype datatype, MPI_Status *status)
#else
1129
int MPI_File_write_shared(MPI_File fh, void * buf, int count, MPI_Datatype datatype, MPI_Status *status)
1130
#endif
1131 1132 1133 1134 1135
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
1136 1137
    ret = DARSHAN_MPI_CALL(PMPI_File_write_shared)(fh, buf, count,
        datatype, status);
1138 1139 1140 1141 1142 1143 1144
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_WRITE(ret, fh, count, datatype, CP_INDEP_WRITES, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

1145 1146 1147 1148
#ifdef HAVE_MPIIO_CONST
int MPI_File_write_ordered(MPI_File fh, const void * buf, int count, 
    MPI_Datatype datatype, MPI_Status * status)
#else
1149 1150
int MPI_File_write_ordered(MPI_File fh, void * buf, int count, 
    MPI_Datatype datatype, MPI_Status * status)
1151
#endif
1152 1153 1154 1155 1156
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
1157 1158
    ret = DARSHAN_MPI_CALL(PMPI_File_write_ordered)(fh, buf, count,
         datatype, status);
1159 1160 1161 1162 1163 1164 1165
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_WRITE(ret, fh, count, datatype, CP_COLL_WRITES, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

1166 1167 1168 1169
#ifdef HAVE_MPIIO_CONST
int MPI_File_write_at_all_begin(MPI_File fh, MPI_Offset offset, const void * buf,
    int count, MPI_Datatype datatype)
#else
1170 1171
int MPI_File_write_at_all_begin(MPI_File fh, MPI_Offset offset, void * buf,
    int count, MPI_Datatype datatype)
1172
#endif
1173 1174 1175 1176 1177
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
1178 1179
    ret = DARSHAN_MPI_CALL(PMPI_File_write_at_all_begin)(fh, offset,
        buf, count, datatype);
1180 1181 1182 1183 1184 1185 1186
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_WRITE(ret, fh, count, datatype, CP_SPLIT_WRITES, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}

1187 1188 1189
#ifdef HAVE_MPIIO_CONST
int MPI_File_write_all_begin(MPI_File fh, const void * buf, int count, MPI_Datatype datatype)
#else
1190
int MPI_File_write_all_begin(MPI_File fh, void * buf, int count, MPI_Datatype datatype)
1191
#endif
1192 1193 1194 1195 1196
{
    int ret;
    double tm1, tm2;

    tm1 = darshan_wtime();
1197
    ret = DARSHAN_MPI_CALL(PMPI_File_write_all_begin)(fh, buf, count, datatype);
1198 1199 1200 1201 1202 1203 1204
    tm2 = darshan_wtime();
    CP_LOCK();
    CP_RECORD_MPI_WRITE(ret, fh, count, datatype, CP_SPLIT_WRITES, tm1, tm2);
    CP_UNLOCK();
    return(ret);
}