darshan-apmpi.c 77.1 KB
Newer Older
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2017 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

#define _XOPEN_SOURCE 500
#define _GNU_SOURCE

#include "darshan-runtime-config.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <assert.h>

#include "uthash.h"
#include "darshan.h"
#include "darshan-dynamic.h"
Sudheer Chunduri's avatar
Sudheer Chunduri committed
20 21
#include "darshan-apmpi-log-format.h"

Sudheer Chunduri's avatar
Sudheer Chunduri committed
22
typedef long long ap_bytes_t;
23
#define MAX(x,y) ((x>y)?x:y)
24
#define MIN(x,y) ((x==0.0)?y:((x<y)?x:y))
Sudheer Chunduri's avatar
Sudheer Chunduri committed
25

26 27
#ifdef __APMPI_COLL_SYNC

28 29 30 31 32 33 34 35 36 37
#define TIME_SYNC(FUNC) \
          double tm1, tm2, tm3, tdiff, tsync;\
          int ret; \
          tm1 = darshan_core_wtime(); \
          ret = __real_PMPI_Barrier(comm); \
          tm2 = darshan_core_wtime(); \
          ret = FUNC; \
          tm3 = darshan_core_wtime(); \
          tdiff = tm3-tm2; \
          tsync = tm2-tm1
38
#else
39

40 41 42 43 44 45 46
#define TIME_SYNC(FUNC) \
          double tm1, tm2, tdiff, tsync;\
          int ret; \
          tm1 = darshan_core_wtime(); \
          ret = FUNC; \
          tm2 = darshan_core_wtime(); \
          tdiff = tm2-tm1; \
47
          tsync = 0
48 49

#endif
50 51 52 53 54 55 56 57
#define TIME(FUNC) \
          double tm1, tm2, tdiff;\
          int ret; \
          tm1 = darshan_core_wtime(); \
          ret = FUNC; \
          tm2 = darshan_core_wtime(); \
          tdiff = tm2-tm1

Sudheer Chunduri's avatar
Sudheer Chunduri committed
58 59 60 61 62 63 64 65 66 67
#define BYTECOUNT(TYPE, COUNT) \
          int tsize; \
          PMPI_Type_size(TYPE, &tsize); \
          ap_bytes_t bytes = (COUNT) * tsize

#define BYTECOUNTND(TYPE, COUNT) \
          int tsize2; \
          PMPI_Type_size(TYPE, &tsize2); \
          bytes = (COUNT) * tsize2

68 69


Sudheer Chunduri's avatar
Sudheer Chunduri committed
70 71 72
/* increment histogram bucket depending on the given __value
 *
 * NOTE: This macro can be used to build a histogram of access
73
 * sizes, offsets, etc. It assumes a 6-bucket histogram, with
Sudheer Chunduri's avatar
Sudheer Chunduri committed
74 75 76 77 78
 * __bucket_base_p pointing to the first counter in the sequence
 * of buckets (i.e., the smallest bucket). The size ranges of each
 * bucket are:
 *      * 0 - 256 bytes
 *      * 256 - 1 KiB
79
 *      * 1 KiB - 8 KiB
Sudheer Chunduri's avatar
Sudheer Chunduri committed
80 81
 *      * 32 KiB - 256 KiB
 *      * 256 KiB - 1 MiB
82
 *      * 1 MiB +
Sudheer Chunduri's avatar
Sudheer Chunduri committed
83 84 85 86 87 88
 */
#define DARSHAN_MSG_BUCKET_INC(__bucket_base_p, __value) do {\
    if(__value < 257) \
        *(__bucket_base_p) += 1; \
    else if(__value < 1025) \
        *(__bucket_base_p + 1) += 1; \
89
    else if(__value < 8193) \
Sudheer Chunduri's avatar
Sudheer Chunduri committed
90 91 92 93 94 95
        *(__bucket_base_p + 2) += 1; \
    else if(__value < 262145) \
        *(__bucket_base_p + 3) += 1; \
    else if(__value < 1048577) \
        *(__bucket_base_p + 4) += 1; \
    else \
96
        *(__bucket_base_p + 5) += 1; \
Sudheer Chunduri's avatar
Sudheer Chunduri committed
97 98 99
} while(0)


Sudheer Chunduri's avatar
Sudheer Chunduri committed
100
DARSHAN_FORWARD_DECL(PMPI_Send, int, (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm));
101 102 103 104 105 106 107 108 109
DARSHAN_FORWARD_DECL(PMPI_Ssend, int, (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Rsend, int, (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Bsend, int, (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Recv, int, (void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status));
DARSHAN_FORWARD_DECL(PMPI_Sendrecv, int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag,
                 void *recvbuf, int recvcount, MPI_Datatype recvtype,
                 int source, int recvtag, MPI_Comm comm, MPI_Status * status));
DARSHAN_FORWARD_DECL(PMPI_Sendrecv_replace, int, (const void *buf, int count, MPI_Datatype datatype, int dest, int sendtag,
                 int source, int recvtag, MPI_Comm comm, MPI_Status * status));
110 111 112 113 114 115 116 117 118 119
DARSHAN_FORWARD_DECL(PMPI_Isend, int, (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request));
DARSHAN_FORWARD_DECL(PMPI_Issend, int, (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request));
DARSHAN_FORWARD_DECL(PMPI_Irsend, int, (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request));
DARSHAN_FORWARD_DECL(PMPI_Ibsend, int, (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request));
DARSHAN_FORWARD_DECL(PMPI_Irecv, int, (void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Request *request));
/*
DARSHAN_FORWARD_DECL(PMPI_Isendrecv, int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag, void *recvbuf,
int recvcount, MPI_Datatype recvtype, int source, int recvtag, MPI_Comm comm, MPI_Request *request));
DARSHAN_FORWARD_DECL(PMPI_Isendrecv_replace, int, (void *buf, int count, MPI_Datatype datatype, int dest, int sendtag, int source, int recvtag, MPI_Comm comm, MPI_Request *request));
*/
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
DARSHAN_FORWARD_DECL(PMPI_Probe, int, (int source, int tag, MPI_Comm comm, MPI_Status * status));
DARSHAN_FORWARD_DECL(PMPI_Iprobe, int, (int source, int tag, MPI_Comm comm, int *flag, MPI_Status * status));
DARSHAN_FORWARD_DECL(PMPI_Test, int, (MPI_Request *request, int *flag, MPI_Status *status));
DARSHAN_FORWARD_DECL(PMPI_Testany, int, (int count, MPI_Request array_of_requests[], int *indx,
               int *flag, MPI_Status *status));
DARSHAN_FORWARD_DECL(PMPI_Testall, int, (int count, MPI_Request array_of_requests[], int *flag, 
               MPI_Status array_of_statuses[]));
DARSHAN_FORWARD_DECL(PMPI_Testsome, int, (int incount, MPI_Request array_of_requests[], int *outcount,
                 int array_of_indices[], MPI_Status array_of_statuses[]));
DARSHAN_FORWARD_DECL(PMPI_Wait, int, (MPI_Request * request, MPI_Status * status));
DARSHAN_FORWARD_DECL(PMPI_Waitany, int, (int count, MPI_Request array_of_requests[], int *indx, MPI_Status * status));
DARSHAN_FORWARD_DECL(PMPI_Waitall, int, (int count, MPI_Request array_of_requests[], 
               MPI_Status array_of_statuses[]));
DARSHAN_FORWARD_DECL(PMPI_Waitsome, int, (int incount, MPI_Request array_of_requests[],
                 int *outcount, int array_of_indices[], MPI_Status array_of_statuses[]));
135 136 137 138 139 140
DARSHAN_FORWARD_DECL(PMPI_Put, int, (const void *origin_addr, int origin_count, MPI_Datatype
            origin_datatype, int target_rank, MPI_Aint target_disp,
            int target_count, MPI_Datatype target_datatype, MPI_Win win));
DARSHAN_FORWARD_DECL(PMPI_Get, int, (void *origin_addr, int origin_count, MPI_Datatype
            origin_datatype, int target_rank, MPI_Aint target_disp,
            int target_count, MPI_Datatype target_datatype, MPI_Win win));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
141 142 143 144 145 146 147 148 149
DARSHAN_FORWARD_DECL(PMPI_Barrier, int, (MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Bcast, int, (void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Reduce, int,  (const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Allreduce, int,  (const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Alltoall, int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype,
                 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Alltoallv, int, (const void *sendbuf, const int *sendcounts, const int *sdispls,
                 MPI_Datatype sendtype, void *recvbuf, const int *recvcounts, const int *rdispls,
                 MPI_Datatype recvtype, MPI_Comm comm));
150 151 152
DARSHAN_FORWARD_DECL(PMPI_Alltoallw, int, (const void *sendbuf, const int sendcounts[], const int sdispls[],
                 const MPI_Datatype sendtypes[], void *recvbuf, const int recvcounts[], const int rdispls[],
                 const MPI_Datatype recvtypes[], MPI_Comm comm));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
DARSHAN_FORWARD_DECL(PMPI_Allgather, int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype,
                  void *recvbuf, int recvcount, MPI_Datatype recvtype,
                  MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Allgatherv, int, ());
DARSHAN_FORWARD_DECL(PMPI_Gather , int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype,
               void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Gatherv , int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype,
                void *recvbuf, const int *recvcounts, const int *displs,
                MPI_Datatype recvtype, int root, MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Scatter, int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype,
               void *recvbuf, int recvcount, MPI_Datatype recvtype, int root,
               MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Scatterv, int, (const void *sendbuf, const int *sendcounts, const int *displs,
                 MPI_Datatype sendtype, void *recvbuf, int recvcount,
                 MPI_Datatype recvtype,
                 int root, MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Reduce_scatter, int, (const void *sendbuf, void *recvbuf, const int recvcounts[],
                       MPI_Datatype datatype, MPI_Op op, MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Scan, int, (const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
             MPI_Op op, MPI_Comm comm));
DARSHAN_FORWARD_DECL(PMPI_Exscan, int, (const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
               MPI_Op op, MPI_Comm comm));
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
DARSHAN_FORWARD_DECL(PMPI_Ibarrier, int, (MPI_Comm comm, MPI_Request * request));
DARSHAN_FORWARD_DECL(PMPI_Ibcast, int, (void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm, MPI_Request * request));
DARSHAN_FORWARD_DECL(PMPI_Ireduce, int,  (const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm, MPI_Request * request));
DARSHAN_FORWARD_DECL(PMPI_Iallreduce, int,  (const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, MPI_Request * request));
DARSHAN_FORWARD_DECL(PMPI_Ialltoall, int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype,
                 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm, MPI_Request * request));
DARSHAN_FORWARD_DECL(PMPI_Ialltoallv, int, (const void *sendbuf, const int *sendcounts, const int *sdispls,
                 MPI_Datatype sendtype, void *recvbuf, const int *recvcounts, const int *rdispls,
                 MPI_Datatype recvtype, MPI_Comm comm, MPI_Request * request));
DARSHAN_FORWARD_DECL(PMPI_Ialltoallw, int, (const void *sendbuf, const int sendcounts[], const int sdispls[],
                 const MPI_Datatype sendtypes[], void *recvbuf, const int recvcounts[], const int rdispls[],
                 const MPI_Datatype recvtypes[], MPI_Comm comm, MPI_Request * request));
DARSHAN_FORWARD_DECL(PMPI_Iallgather, int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype,
                  void *recvbuf, int recvcount, MPI_Datatype recvtype,
                  MPI_Comm comm, MPI_Request * request));
DARSHAN_FORWARD_DECL(PMPI_Iallgatherv, int, ());
DARSHAN_FORWARD_DECL(PMPI_Igather , int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype,
               void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request * request));
DARSHAN_FORWARD_DECL(PMPI_Igatherv , int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype,
                void *recvbuf, const int *recvcounts, const int *displs,
                MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request * request));
DARSHAN_FORWARD_DECL(PMPI_Iscatter, int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype,
               void *recvbuf, int recvcount, MPI_Datatype recvtype, int root,
               MPI_Comm comm, MPI_Request * request));
DARSHAN_FORWARD_DECL(PMPI_Iscatterv, int, (const void *sendbuf, const int *sendcounts, const int *displs,
                 MPI_Datatype sendtype, void *recvbuf, int recvcount,
                 MPI_Datatype recvtype,
                 int root, MPI_Comm comm, MPI_Request * request));
DARSHAN_FORWARD_DECL(PMPI_Ireduce_scatter, int, (const void *sendbuf, void *recvbuf, const int recvcounts[],
                       MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, MPI_Request * request));
DARSHAN_FORWARD_DECL(PMPI_Iscan, int, (const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
             MPI_Op op, MPI_Comm comm, MPI_Request * request)); 
DARSHAN_FORWARD_DECL(PMPI_Iexscan, int, (const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
               MPI_Op op, MPI_Comm comm, MPI_Request * request));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
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 253 254 255
DARSHAN_FORWARD_DECL(PMPI_Accumulate, int, (const void *origin_addr, int origin_count, MPI_Datatype
                   origin_datatype, int target_rank, MPI_Aint
                   target_disp, int target_count, MPI_Datatype
                   target_datatype, MPI_Op op, MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Get_accumulate, int, (const void *origin_addr, int origin_count,
        MPI_Datatype origin_datatype, void *result_addr, int result_count,
        MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp,
        int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Fetch_and_op, int, (const void *origin_addr, void *result_addr,
        MPI_Datatype datatype, int target_rank, MPI_Aint target_disp,
        MPI_Op op, MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Compare_and_swap, int, (const void *origin_addr, const void *compare_addr,
        void *result_addr, MPI_Datatype datatype, int target_rank,
        MPI_Aint target_disp, MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Win_fence, int, (int assert, MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Win_start, int, (MPI_Group group, int assert, MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Win_complete, int, (MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Win_post, int, (MPI_Group group, int assert, MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Win_wait, int, (MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Win_test, int, (MPI_Win win, int *flag));

DARSHAN_FORWARD_DECL(PMPI_Win_lock, int, (int lock_type, int rank, int assert, MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Win_unlock, int, (int rank, MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Win_unlock_all, int, (MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Win_flush, int, (int rank, MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Win_flush_all, int, (MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Win_flush_local, int, (int rank, MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Win_flush_local_all, int, (MPI_Win win));

DARSHAN_FORWARD_DECL(PMPI_Win_sync, int, (MPI_Win win));

Sudheer Chunduri's avatar
Sudheer Chunduri committed
256 257 258
/*
 * Global runtime struct for tracking data needed at runtime
 */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
259
struct apmpi_runtime
Sudheer Chunduri's avatar
Sudheer Chunduri committed
260
{
Sudheer Chunduri's avatar
Sudheer Chunduri committed
261
    struct darshan_apmpi_perf_record *perf_record;
262
    struct darshan_apmpi_header_record *header_record;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
263
    darshan_record_id rec_id;
264
    darshan_record_id header_id;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
265 266
};

Sudheer Chunduri's avatar
Sudheer Chunduri committed
267 268
static struct apmpi_runtime *apmpi_runtime = NULL;
static pthread_mutex_t apmpi_runtime_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
269 270 271 272

/* my_rank indicates the MPI rank of this process */
static int my_rank = -1;

Sudheer Chunduri's avatar
Sudheer Chunduri committed
273
/* internal helper functions for the apmpi module */
274
static void apmpi_runtime_initialize(void);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
275 276 277

/* forward declaration for shutdown function needed to interface with darshan-core */
#ifdef HAVE_MPI
Sudheer Chunduri's avatar
Sudheer Chunduri committed
278
static void apmpi_mpi_redux(
Sudheer Chunduri's avatar
Sudheer Chunduri committed
279 280 281 282 283
    void *buffer, 
    MPI_Comm mod_comm,
    darshan_record_id *shared_recs, 
    int shared_rec_count);
#endif
Sudheer Chunduri's avatar
Sudheer Chunduri committed
284
static void apmpi_shutdown(
Sudheer Chunduri's avatar
Sudheer Chunduri committed
285 286 287
        void **buffer, 
        int *size);

Sudheer Chunduri's avatar
Sudheer Chunduri committed
288 289 290
/* macros for obtaining/releasing the apmpi module lock */
#define APMPI_LOCK() pthread_mutex_lock(&apmpi_runtime_mutex)
#define APMPI_UNLOCK() pthread_mutex_unlock(&apmpi_runtime_mutex)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
291 292

/*
Sudheer Chunduri's avatar
Sudheer Chunduri committed
293
 * Initialize counters 
Sudheer Chunduri's avatar
Sudheer Chunduri committed
294 295 296 297
 */
static void initialize_counters (void)
{
    int i;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
298
    for (i = 0; i < APMPI_NUM_INDICES; i++)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
299
    {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
300 301
        apmpi_runtime->perf_record->counters[i] = 0; 
    }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
302
    for (i = 0; i < APMPI_F_MPIOP_TOTALTIME_NUM_INDICES; i++)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
303 304
    {
        apmpi_runtime->perf_record->fcounters[i] = 0; 
Sudheer Chunduri's avatar
Sudheer Chunduri committed
305
    }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
306
    for (i = 0; i < APMPI_F_MPIOP_SYNCTIME_NUM_INDICES; i++)
307 308 309
    {
        apmpi_runtime->perf_record->fsynccounters[i] = 0;
    }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
310
    for (i = 0; i < APMPI_F_MPI_GLOBAL_NUM_INDICES; i++)
311 312 313
    {
        apmpi_runtime->perf_record->fsynccounters[i] = 0;
    }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
314 315 316 317 318 319 320 321 322 323 324 325
    return;
}

static void finalize_counters (void)
{

    return;
}

/*
 * Function which updates all the counter data
 */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
326
static void capture(struct darshan_apmpi_perf_record *rec,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
327 328 329 330
                    darshan_record_id rec_id)
{
    rec->base_rec.id = rec_id;
    rec->base_rec.rank = my_rank;
331 332
    int name_len;
    MPI_Get_processor_name(rec->node_name, &name_len);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
333 334 335 336

    return;
}

337
static void apmpi_runtime_initialize()
Sudheer Chunduri's avatar
Sudheer Chunduri committed
338
{
Sudheer Chunduri's avatar
Sudheer Chunduri committed
339 340
    int apmpi_buf_size;
    char rec_name[128];
Sudheer Chunduri's avatar
Sudheer Chunduri committed
341 342 343

    darshan_module_funcs mod_funcs = {
#ifdef HAVE_MPI
Sudheer Chunduri's avatar
Sudheer Chunduri committed
344
        .mod_redux_func = &apmpi_mpi_redux,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
345
#endif
Sudheer Chunduri's avatar
Sudheer Chunduri committed
346
        .mod_shutdown_func = &apmpi_shutdown
Sudheer Chunduri's avatar
Sudheer Chunduri committed
347 348
        };

Sudheer Chunduri's avatar
Sudheer Chunduri committed
349
    APMPI_LOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
350 351

    /* don't do anything if already initialized */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
352
    if(apmpi_runtime)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
353
    {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
354
        APMPI_UNLOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
355 356 357
        return;
    }

358 359
    apmpi_buf_size = sizeof(struct darshan_apmpi_header_record) +
                     sizeof(struct darshan_apmpi_perf_record);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
360

Sudheer Chunduri's avatar
Sudheer Chunduri committed
361
    /* register the apmpi module with the darshan-core component */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
362
    darshan_core_register_module(
363
        DARSHAN_APMPI_MOD,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
364
        mod_funcs,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
365
        &apmpi_buf_size,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
366 367 368 369
        &my_rank,
        NULL);

    /* initialize module's global state */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
370 371
    apmpi_runtime = malloc(sizeof(*apmpi_runtime));
    if(!apmpi_runtime)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
372
    {
373
        darshan_core_unregister_module(DARSHAN_APMPI_MOD);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
374
        APMPI_UNLOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
375 376
        return;
    }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
377
    memset(apmpi_runtime, 0, sizeof(*apmpi_runtime));
378 379 380 381 382 383 384 385 386 387

    if (my_rank == 0)
    {   
        apmpi_runtime->header_id = darshan_core_gen_record_id("darshan-apmpi-header");
        
        /* register the apmpi record with darshan-core */
        apmpi_runtime->header_record = darshan_core_register_record(
            apmpi_runtime->header_id,
            //NULL,
            "darshan-apmpi-header",
388
            DARSHAN_APMPI_MOD,
389 390 391 392
            sizeof(struct darshan_apmpi_header_record),
            NULL);
        if(!(apmpi_runtime->header_record))
        {   
393
            darshan_core_unregister_module(DARSHAN_APMPI_MOD);
394 395 396 397 398 399 400 401
            free(apmpi_runtime);
            apmpi_runtime = NULL;
            APMPI_UNLOCK();
           return;
        }
        apmpi_runtime->header_record->base_rec.id = apmpi_runtime->header_id;
        apmpi_runtime->header_record->base_rec.rank = my_rank;
        apmpi_runtime->header_record->magic = APMPI_MAGIC;
402 403 404 405 406
#ifdef __APMPI_COLL_SYNC
        apmpi_runtime->header_record->sync_flag = 1;
#else
        apmpi_runtime->header_record->sync_flag = 0;
#endif
407
        apmpi_runtime->header_record->version = APMPI_VER;
408 409
    }

410
    apmpi_runtime->rec_id = darshan_core_gen_record_id("APMPI"); //record name
Sudheer Chunduri's avatar
Sudheer Chunduri committed
411 412 413 414

    apmpi_runtime->perf_record = darshan_core_register_record(
        apmpi_runtime->rec_id,
        "APMPI",
415
        DARSHAN_APMPI_MOD,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
416
        sizeof(struct darshan_apmpi_perf_record),
Sudheer Chunduri's avatar
Sudheer Chunduri committed
417
        NULL);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
418
    if(!(apmpi_runtime->perf_record))
Sudheer Chunduri's avatar
Sudheer Chunduri committed
419
    {
420
        darshan_core_unregister_module(DARSHAN_APMPI_MOD);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
421 422 423
        free(apmpi_runtime);
        apmpi_runtime = NULL;
        APMPI_UNLOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
424 425 426 427
        return;
    }

    initialize_counters();
428 429
    /* collect perf counters */
    capture(apmpi_runtime->perf_record, apmpi_runtime->rec_id);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
430

Sudheer Chunduri's avatar
Sudheer Chunduri committed
431
    APMPI_UNLOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
432 433 434

    return;
}
Sudheer Chunduri's avatar
Sudheer Chunduri committed
435
#if 0
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
static void apmpi_record_reduction_op (void* inrec_v, void* inoutrec_v,
    int *len, MPI_Datatype *datatype)
{
    struct darshan_apmpi_perf_record tmp_rec;
    struct darshan_apmpi_perf_record *inrec = inrec_v;
    struct darshan_apmpi_perf_record *inoutrec = inoutrec_v;
    int i, j, k;

    for (i=0; i<*len; i++)
    {
        memset(&tmp_rec, 0, sizeof(struct darshan_apmpi_perf_record));
        tmp_rec.base_rec.id = inrec->base_rec.id;
        tmp_file.base_rec.rank = -1;
    }
}
#endif
452
static void apmpi_shared_record_variance(MPI_Comm mod_comm)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
453 454 455 456 457 458 459 460 461 462 463 464 465
{
    MPI_Datatype var_dt;
    MPI_Op var_op;
    int i;
    struct darshan_variance_dt *var_send_buf = NULL;
    struct darshan_variance_dt *var_recv_buf = NULL;

    PMPI_Type_contiguous(sizeof(struct darshan_variance_dt),
        MPI_BYTE, &var_dt);
    PMPI_Type_commit(&var_dt);

    PMPI_Op_create(darshan_variance_reduce, 1, &var_op);

466
    var_send_buf = malloc(sizeof(struct darshan_variance_dt));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
467 468 469 470 471
    if(!var_send_buf)
        return;

    if(my_rank == 0)
    {   
472
        var_recv_buf = malloc(sizeof(struct darshan_variance_dt));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
473 474 475 476 477

        if(!var_recv_buf)
            return;
    }   

478
    /* get total mpi time variances across the ranks */
479 480
    var_send_buf->n = 1;
    var_send_buf->S = 0;
481
    var_send_buf->T = apmpi_runtime->perf_record->fglobalcounters[RANK_TOTAL_MPITIME];
Sudheer Chunduri's avatar
Sudheer Chunduri committed
482

483
    PMPI_Reduce(var_send_buf, var_recv_buf, 1,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
484 485 486 487
        var_dt, var_op, 0, mod_comm);

    if(my_rank == 0)
    {   
488
       apmpi_runtime->header_record->apmpi_f_variance_total_mpitime =
489
                (var_recv_buf->S / var_recv_buf->n);
490
    }
491 492 493 494 495 496 497 498 499 500 501 502 503
    /* get total mpi sync time variances across the ranks */
    var_send_buf->n = 1;
    var_send_buf->S = 0;
    var_send_buf->T = apmpi_runtime->perf_record->fglobalcounters[RANK_TOTAL_MPISYNCTIME];

    PMPI_Reduce(var_send_buf, var_recv_buf, 1,
        var_dt, var_op, 0, mod_comm);

    if(my_rank == 0)
    {   
       apmpi_runtime->header_record->apmpi_f_variance_total_mpisynctime =
                (var_recv_buf->S / var_recv_buf->n);
    }   
Sudheer Chunduri's avatar
Sudheer Chunduri committed
504 505 506 507 508 509 510 511
    PMPI_Type_free(&var_dt);
    PMPI_Op_free(&var_op);
    free(var_send_buf);
    free(var_recv_buf);

    return;
}

Sudheer Chunduri's avatar
Sudheer Chunduri committed
512 513 514 515 516

/********************************************************************************
 * shutdown function exported by this module for coordinating with darshan-core *
 ********************************************************************************/

Sudheer Chunduri's avatar
Sudheer Chunduri committed
517
/* Pass data for the apmpi module back to darshan-core to log to file. */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
518
//#ifdef HAVE_MPI
Sudheer Chunduri's avatar
Sudheer Chunduri committed
519 520
static void apmpi_mpi_redux(
    void *apmpi_buf,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
521 522 523 524 525
    MPI_Comm mod_comm,
    darshan_record_id *shared_recs,
    int shared_rec_count)
{
    int i;
526
#if 0
Sudheer Chunduri's avatar
Sudheer Chunduri committed
527 528
    struct darshan_apmpi_perf_record *red_send_buf = NULL;
    struct darshan_apmpi_perf_record *red_recv_buf = NULL;
529
    struct darshan_apmpi_perf_record *apmpi_rec_buf = (struct darshan_apmpi_perf_record *)apmpi_buf;
530
#endif
Sudheer Chunduri's avatar
Sudheer Chunduri committed
531
    MPI_Datatype red_type;
532
    //MPI_Op red_op;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
533

Sudheer Chunduri's avatar
Sudheer Chunduri committed
534 535 536
    APMPI_LOCK();

    if (!apmpi_runtime)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
537
    {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
538
        APMPI_UNLOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
539 540
        return;
    }
541
    double mpisync_time = 0.0;
542
    /* Compute Total MPI time per rank: RANK_TOTAL_MPITIME */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
543
    for (i=MPI_SEND_TOTAL_TIME; i<APMPI_F_MPIOP_TOTALTIME_NUM_INDICES; i+=3){     // times (total_time, max_time, min_time)
544
        apmpi_runtime->perf_record->fglobalcounters[RANK_TOTAL_MPITIME] += apmpi_runtime->perf_record->fcounters[i];
545
    }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
546
    for (i=MPI_BARRIER_TOTAL_SYNC_TIME; i<APMPI_F_MPIOP_SYNCTIME_NUM_INDICES; i++){
547
        mpisync_time += apmpi_runtime->perf_record->fsynccounters[i];
548
    }
549 550
    apmpi_runtime->perf_record->fglobalcounters[RANK_TOTAL_MPITIME] += mpisync_time;
    apmpi_runtime->perf_record->fglobalcounters[RANK_TOTAL_MPISYNCTIME] = mpisync_time;
551 552
#if 0
    red_send_buf = apmpi_runtime->perf_record;
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576

    if (my_rank == 0){
        red_recv_buf = malloc(sizeof(struct darshan_apmpi_perf_record));
        if(!red_recv_buf)
            {
                APMPI_UNLOCK();
                return;
            }
    }
    /* construct a datatype for a APMPI file record.  This is serving no purpose
     * except to make sure we can do a reduction on proper boundaries
     */
    PMPI_Type_contiguous(sizeof(struct darshan_apmpi_perf_record),
        MPI_BYTE, &red_type);
    PMPI_Type_commit(&red_type);

    /* register a APMPI file record reduction operator */
    PMPI_Op_create(apmpi_record_reduction_op, 1, &red_op);

    /* reduce shared APMPI file records */
    PMPI_Reduce(red_send_buf, red_recv_buf,
        shared_rec_count, red_type, red_op, 0, mod_comm);
#endif
    /* get the time variance across all ranks */
577 578
     apmpi_shared_record_variance(mod_comm);
#if 0
579 580 581 582 583
    /* clean up reduction state */
    if(my_rank == 0)
    {   
        free(red_recv_buf);
    }   
584
#endif    
585 586 587
    //PMPI_Type_free(&red_type);
    //PMPI_Op_free(&red_op);

Sudheer Chunduri's avatar
Sudheer Chunduri committed
588
    APMPI_UNLOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
589

Sudheer Chunduri's avatar
Sudheer Chunduri committed
590 591
    return;
}
Sudheer Chunduri's avatar
Sudheer Chunduri committed
592

Sudheer Chunduri's avatar
Sudheer Chunduri committed
593 594 595 596 597 598
//#endif
static void apmpi_shutdown(
    void **apmpi_buf,
    int *apmpi_buf_sz)
{
    int apmpi_rec_count;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
599

Sudheer Chunduri's avatar
Sudheer Chunduri committed
600 601
    APMPI_LOCK();
    assert(apmpi_runtime);
602 603 604 605 606 607
    *apmpi_buf_sz = 0;
    if(my_rank == 0) {
    *apmpi_buf_sz += sizeof( *apmpi_runtime->header_record);
    }
    *apmpi_buf_sz += sizeof( *apmpi_runtime->perf_record);

Sudheer Chunduri's avatar
Sudheer Chunduri committed
608 609 610
    finalize_counters();
    free(apmpi_runtime);
    apmpi_runtime = NULL;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
611

Sudheer Chunduri's avatar
Sudheer Chunduri committed
612 613 614
    APMPI_UNLOCK();
    return;
}
Sudheer Chunduri's avatar
Sudheer Chunduri committed
615

Sudheer Chunduri's avatar
Sudheer Chunduri committed
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
#define APMPI_PRE_RECORD() do { \
       APMPI_LOCK(); \
       if(!darshan_core_disabled_instrumentation()) { \
           if(!apmpi_runtime) { \
               apmpi_runtime_initialize(); \
           } \
           if(apmpi_runtime) break; \
       } \
       APMPI_UNLOCK(); \
       return(ret); \
   } while(0)

#define APMPI_POST_RECORD() do { \
       APMPI_UNLOCK(); \
   } while(0)

632
#define APMPI_RECORD_UPDATE(MPI_OP) do { \
633
    if(ret != MPI_SUCCESS) break; \
634 635 636 637 638 639
    apmpi_runtime->perf_record->counters[MPI_OP ## _CALL_COUNT]++; \
    apmpi_runtime->perf_record->counters[MPI_OP ## _TOTAL_BYTES] += bytes; \
    DARSHAN_MSG_BUCKET_INC(&(apmpi_runtime->perf_record->counters[MPI_OP ## _MSG_SIZE_AGG_0_256]), bytes); \
    apmpi_runtime->perf_record->fcounters[MPI_OP ## _TOTAL_TIME] += tdiff; \
    apmpi_runtime->perf_record->fcounters[MPI_OP ## _MAX_TIME] = MAX(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MAX_TIME)], tdiff); \
    apmpi_runtime->perf_record->fcounters[MPI_OP ## _MIN_TIME] = MIN(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MIN_TIME)], tdiff); \
640 641 642
    } while(0)

#define APMPI_RECORD_UPDATE_NOMSG(MPI_OP) do { \
643
    if(ret != MPI_SUCCESS) break; \
644 645 646 647
    apmpi_runtime->perf_record->counters[MPI_OP ## _CALL_COUNT]++; \
    apmpi_runtime->perf_record->fcounters[MPI_OP ## _TOTAL_TIME] += tdiff; \
    apmpi_runtime->perf_record->fcounters[MPI_OP ## _MAX_TIME] = MAX(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MAX_TIME)], tdiff); \
    apmpi_runtime->perf_record->fcounters[MPI_OP ## _MIN_TIME] = MIN(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MIN_TIME)], tdiff); \
648 649 650
    } while(0)

#define APMPI_RECORD_UPDATE_SYNC(MPI_OP) do { \
651
    if(ret != MPI_SUCCESS) break; \
652 653 654 655 656 657 658
    apmpi_runtime->perf_record->counters[MPI_OP ## _CALL_COUNT]++; \
    apmpi_runtime->perf_record->counters[MPI_OP ## _TOTAL_BYTES] += bytes; \
    DARSHAN_MSG_BUCKET_INC(&(apmpi_runtime->perf_record->counters[MPI_OP ## _MSG_SIZE_AGG_0_256]), bytes); \
    apmpi_runtime->perf_record->fcounters[MPI_OP ## _TOTAL_TIME] += tdiff; \
    apmpi_runtime->perf_record->fsynccounters[MPI_OP ## _TOTAL_SYNC_TIME] += tsync; \
    apmpi_runtime->perf_record->fcounters[MPI_OP ## _MAX_TIME] = MAX(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MAX_TIME)], tdiff); \
    apmpi_runtime->perf_record->fcounters[MPI_OP ## _MIN_TIME] = MIN(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MIN_TIME)], tdiff); \
659 660 661
    } while(0)

#define APMPI_RECORD_UPDATE_SYNC_NOMSG(MPI_OP) do { \
662
    if(ret != MPI_SUCCESS) break; \
663 664 665 666 667
    apmpi_runtime->perf_record->counters[MPI_OP ## _CALL_COUNT]++; \
    apmpi_runtime->perf_record->fcounters[MPI_OP ## _TOTAL_TIME] += tdiff; \
    apmpi_runtime->perf_record->fsynccounters[MPI_OP ## _TOTAL_SYNC_TIME] += tsync; \
    apmpi_runtime->perf_record->fcounters[MPI_OP ## _MAX_TIME] = MAX(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MAX_TIME)], tdiff); \
    apmpi_runtime->perf_record->fcounters[MPI_OP ## _MIN_TIME] = MIN(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MIN_TIME)], tdiff); \
668 669 670
    } while(0)
#define Y(a) a

Sudheer Chunduri's avatar
Sudheer Chunduri committed
671 672 673 674
/**********************************************************
 *        Wrappers for MPI functions of interest       * 
 **********************************************************/

675
int DARSHAN_DECL(MPI_Send)(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
676 677
{
    MAP_OR_FAIL(PMPI_Send);
678 679
    TIME(__real_PMPI_Send(buf, count, datatype, dest, tag, comm));
    BYTECOUNT(datatype, count);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
680
    APMPI_PRE_RECORD();
681
    // Potential optimization: Lock around the count - lock only if MPI_THREAD_MULTIPLE is used ... locking mutex
682 683
    APMPI_RECORD_UPDATE(MPI_SEND);
    APMPI_POST_RECORD();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
684 685 686
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Send, int,  (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm), MPI_Send)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
687

688
int DARSHAN_DECL(MPI_Ssend)(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
689
{
690 691 692 693 694 695 696 697 698
    MAP_OR_FAIL(PMPI_Ssend);
    TIME(__real_PMPI_Ssend(buf, count, datatype, dest, tag, comm));
    BYTECOUNT(datatype, count);
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE(MPI_SSEND);
    APMPI_POST_RECORD();
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Ssend, int,  (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm), MPI_Ssend)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
699

700 701 702 703
int DARSHAN_DECL(MPI_Rsend)(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
{
    MAP_OR_FAIL(PMPI_Rsend);
    TIME(__real_PMPI_Rsend(buf, count, datatype, dest, tag, comm));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
704
    BYTECOUNT(datatype, count);
705
    APMPI_PRE_RECORD();
706
    APMPI_RECORD_UPDATE(MPI_RSEND);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
707 708 709
    APMPI_POST_RECORD();
    return ret;
}
710 711 712 713 714 715 716 717 718 719 720 721 722 723
DARSHAN_WRAPPER_MAP(PMPI_Rsend, int,  (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm), MPI_Rsend)

int DARSHAN_DECL(MPI_Bsend)(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
{
    MAP_OR_FAIL(PMPI_Bsend);
    TIME(__real_PMPI_Bsend(buf, count, datatype, dest, tag, comm));
    BYTECOUNT(datatype, count);
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE(MPI_BSEND);
    APMPI_POST_RECORD();
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Bsend, int,  (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm), MPI_Bsend)

Sudheer Chunduri's avatar
Sudheer Chunduri committed
724 725 726 727
int DARSHAN_DECL(MPI_Isend)(const void *buf, int count, MPI_Datatype datatype, int dest, int tag,
             MPI_Comm comm, MPI_Request *request)
{
    MAP_OR_FAIL(PMPI_Isend);
728 729
    TIME(__real_PMPI_Isend(buf, count, datatype, dest, tag, comm, request));
    BYTECOUNT(datatype, count);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
730
    APMPI_PRE_RECORD();
731
    APMPI_RECORD_UPDATE(MPI_ISEND);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
732 733
    APMPI_POST_RECORD();
    return ret;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
734
}
Sudheer Chunduri's avatar
Sudheer Chunduri committed
735
DARSHAN_WRAPPER_MAP(PMPI_Isend, int,  (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request), MPI_Isend)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
736

737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
int DARSHAN_DECL(MPI_Issend)(const void *buf, int count, MPI_Datatype datatype, int dest, int tag,
             MPI_Comm comm, MPI_Request *request)
{
    MAP_OR_FAIL(PMPI_Issend);
    TIME(__real_PMPI_Issend(buf, count, datatype, dest, tag, comm, request));
    BYTECOUNT(datatype, count);
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE(MPI_ISSEND);
    APMPI_POST_RECORD();
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Issend, int,  (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request), MPI_Issend)

int DARSHAN_DECL(MPI_Irsend)(const void *buf, int count, MPI_Datatype datatype, int dest, int tag,
             MPI_Comm comm, MPI_Request *request)
{
    MAP_OR_FAIL(PMPI_Irsend);
    TIME(__real_PMPI_Irsend(buf, count, datatype, dest, tag, comm, request));
    BYTECOUNT(datatype, count);
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE(MPI_IRSEND);
    APMPI_POST_RECORD();
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Irsend, int,  (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request), MPI_Irsend)

int DARSHAN_DECL(MPI_Ibsend)(const void *buf, int count, MPI_Datatype datatype, int dest, int tag,
             MPI_Comm comm, MPI_Request *request)
{
    MAP_OR_FAIL(PMPI_Ibsend);
    TIME(__real_PMPI_Ibsend(buf, count, datatype, dest, tag, comm, request));
    BYTECOUNT(datatype, count);
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE(MPI_IBSEND);
    APMPI_POST_RECORD();
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Ibsend, int,  (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request), MPI_Ibsend)

int DARSHAN_DECL(MPI_Recv)(void *buf, int count, MPI_Datatype datatype, int source, int tag,
             MPI_Comm comm, MPI_Status *status)
{
    MAP_OR_FAIL(PMPI_Recv);
    TIME(__real_PMPI_Recv(buf, count, datatype, source, tag, comm, status));
    int count_received, src;
    if (status != MPI_STATUS_IGNORE) {
        PMPI_Get_count(status, datatype, &count_received);
        if (count_received == MPI_UNDEFINED) count_received = count;
785
        //src = status->MPI_SOURCE;
786 787 788
    } 
    else {
        count_received = count;
789
        //src = source;
790 791 792 793 794 795 796 797 798 799
    }

    BYTECOUNT(datatype, count_received);
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE(MPI_RECV);
    APMPI_POST_RECORD();
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Recv, int,  (void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status), MPI_Recv)

Sudheer Chunduri's avatar
Sudheer Chunduri committed
800 801 802 803 804
int DARSHAN_DECL(MPI_Irecv)(void *buf, int count, MPI_Datatype datatype, int source, int tag,
             MPI_Comm comm, MPI_Request * request)
{
    MAP_OR_FAIL(PMPI_Irecv);

805 806
    TIME(__real_PMPI_Irecv(buf, count, datatype, source, tag, comm, request));
    BYTECOUNT(datatype, count);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
807
    APMPI_PRE_RECORD();
808
    APMPI_RECORD_UPDATE(MPI_IRECV);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
809 810 811 812 813
    APMPI_POST_RECORD();
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Irecv, int,  (void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Request *request), MPI_Irecv)

814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
int DARSHAN_DECL(MPI_Sendrecv)(const void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag,
                 void *recvbuf, int recvcount, MPI_Datatype recvtype,
                 int source, int recvtag, MPI_Comm comm, MPI_Status * status)
{
    MAP_OR_FAIL(PMPI_Sendrecv);
    
    TIME(__real_PMPI_Sendrecv(sendbuf, sendcount, sendtype, dest, sendtag, recvbuf, recvcount, recvtype, source, recvtag, comm, status));
    
    int count_received; //, src;
    if (status != MPI_STATUS_IGNORE) {
        PMPI_Get_count(status, recvtype, &count_received);
        if (count_received == MPI_UNDEFINED) count_received = recvcount;
        //src = status->MPI_SOURCE;
    }
    else {
        count_received = recvcount;
        //src = source;
    }
    BYTECOUNT(sendtype, sendcount);
    ap_bytes_t sbytes = bytes;
    BYTECOUNTND(recvtype, count_received);
    bytes += sbytes;
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE(MPI_SENDRECV);
    APMPI_POST_RECORD();
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Sendrecv, int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag,
                 void *recvbuf, int recvcount, MPI_Datatype recvtype,
                 int source, int recvtag, MPI_Comm comm, MPI_Status * status), MPI_Sendrecv)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
int DARSHAN_DECL(MPI_Sendrecv_replace)(void *buf, int count, MPI_Datatype datatype, int dest, int sendtag,
                 int source, int recvtag, MPI_Comm comm, MPI_Status * status)
{
    MAP_OR_FAIL(PMPI_Sendrecv_replace);
    TIME(__real_PMPI_Sendrecv_replace(buf, count, datatype, dest, sendtag, source, recvtag, comm, status));
    
    int count_received; //, src;
    if (status != MPI_STATUS_IGNORE) {
        PMPI_Get_count(status, datatype, &count_received);
        if (count_received == MPI_UNDEFINED) count_received = count;
        //src = status->MPI_SOURCE;
    }
    else {
        count_received = count;
        //src = source;
    }
    BYTECOUNT(datatype, count + count_received);
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE(MPI_SENDRECV_REPLACE);
    APMPI_POST_RECORD();

    return ret;
}
868 869 870 871
/*
int DARSHAN_DECL(MPI_Isendrecv)(const void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag,
                 void *recvbuf, int recvcount, MPI_Datatype recvtype,
                 int source, int recvtag, MPI_Comm comm, MPI_Request *request)
872
{
873
    MAP_OR_FAIL(PMPI_Isendrecv);
874
    
875
    TIME(__real_PMPI_Isendrecv(sendbuf, sendcount, sendtype, dest, sendtag, recvbuf, recvcount, recvtype, source, recvtag, comm, request));
876
    
877
    BYTECOUNT(sendtype, sendcount + recvcount);
878 879
    
    APMPI_PRE_RECORD();
880
    APMPI_RECORD_UPDATE(MPI_ISENDRECV);
881 882 883
    APMPI_POST_RECORD();
    return ret;
}
884 885 886
DARSHAN_WRAPPER_MAP(PMPI_Isendrecv, int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag,
                 void *recvbuf, int recvcount, MPI_Datatype recvtype,
                 int source, int recvtag, MPI_Comm comm, MPI_Request *request), MPI_Isendrecv)
887

888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904
int DARSHAN_DECL(MPI_Isendrecv_replace)(void *buf, int count, MPI_Datatype datatype, int dest, int sendtag,
                 int source, int recvtag, MPI_Comm comm, MPI_Request *request)
{
    MAP_OR_FAIL(PMPI_Isendrecv_replace);
    
    TIME(__real_PMPI_Isendrecv_replace(buf, count, datatype, dest, sendtag, source, recvtag, comm, request));
    
    BYTECOUNT(datatype, count + count);
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE(MPI_ISENDRECV_REPLACE);
    APMPI_POST_RECORD();
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Isendrecv_replace, int, (void *buf, int count, MPI_Datatype datatype, int dest, int sendtag,
                 int source, int recvtag, MPI_Comm comm, MPI_Request *request), MPI_Isendrecv_replace)
*/
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
int DARSHAN_DECL(MPI_Put)(const void *origin_addr, int origin_count, MPI_Datatype
            origin_datatype, int target_rank, MPI_Aint target_disp,
            int target_count, MPI_Datatype target_datatype, MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Put);
    TIME(__real_PMPI_Put(origin_addr, origin_count, origin_datatype, target_rank,
            target_disp, target_count, target_datatype, win));
    BYTECOUNT(origin_datatype, origin_count); 
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE(MPI_PUT);
    APMPI_POST_RECORD();

    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Put, int, (const void *origin_addr, int origin_count, MPI_Datatype
            origin_datatype, int target_rank, MPI_Aint target_disp,
            int target_count, MPI_Datatype target_datatype, MPI_Win win), MPI_Put)

int DARSHAN_DECL(MPI_Get)(void *origin_addr, int origin_count, MPI_Datatype
            origin_datatype, int target_rank, MPI_Aint target_disp,
            int target_count, MPI_Datatype target_datatype, MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Get);
    TIME(__real_PMPI_Get(origin_addr, origin_count, origin_datatype, target_rank,
               target_disp, target_count, target_datatype, win));
    
    BYTECOUNT(target_datatype, target_count); 
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE(MPI_GET);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Get, int, (void *origin_addr, int origin_count, MPI_Datatype
            origin_datatype, int target_rank, MPI_Aint target_disp,
            int target_count, MPI_Datatype target_datatype, MPI_Win win), MPI_Get)

942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208

int DARSHAN_DECL(MPI_Accumulate)(const void *origin_addr, int origin_count, MPI_Datatype
                   origin_datatype, int target_rank, MPI_Aint
                   target_disp, int target_count, MPI_Datatype
                   target_datatype, MPI_Op op, MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Accumulate);
    TIME(__real_PMPI_Accumulate(origin_addr, origin_count, 
                   origin_datatype, target_rank, 
                   target_disp, target_count, 
                   target_datatype, op, win));
    
    BYTECOUNT(target_datatype, target_count);
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE(MPI_ACCUMULATE);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Accumulate, int, (const void *origin_addr, int origin_count, MPI_Datatype
                   origin_datatype, int target_rank, MPI_Aint
                   target_disp, int target_count, MPI_Datatype
                   target_datatype, MPI_Op op, MPI_Win win), MPI_Accumulate)

int DARSHAN_DECL(MPI_Get_accumulate)(const void *origin_addr, int origin_count,
        MPI_Datatype origin_datatype, void *result_addr, int result_count,
        MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp,
        int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Get_accumulate);
    TIME(__real_PMPI_Get_accumulate(origin_addr, origin_count,
        origin_datatype, result_addr, result_count,
        result_datatype, target_rank, target_disp,
        target_count, target_datatype, op, win));
    
    BYTECOUNT(target_datatype, target_count);
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE(MPI_GET_ACCUMULATE);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Get_accumulate, int, (const void *origin_addr, int origin_count,
        MPI_Datatype origin_datatype, void *result_addr, int result_count,
        MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp,
        int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win), MPI_Get_accumulate)

int DARSHAN_DECL(MPI_Fetch_and_op)(const void *origin_addr, void *result_addr,
        MPI_Datatype datatype, int target_rank, MPI_Aint target_disp,
        MPI_Op op, MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Fetch_and_op);
    TIME(__real_PMPI_Fetch_and_op(origin_addr, result_addr,
        datatype, target_rank, target_disp,
        op, win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_FETCH_AND_OP);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Fetch_and_op, int, (const void *origin_addr, void *result_addr,
        MPI_Datatype datatype, int target_rank, MPI_Aint target_disp,
        MPI_Op op, MPI_Win win), MPI_Fetch_and_op)

int DARSHAN_DECL(MPI_Compare_and_swap)(const void *origin_addr, const void *compare_addr,
        void *result_addr, MPI_Datatype datatype, int target_rank,
        MPI_Aint target_disp, MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Compare_and_swap);
    TIME(__real_PMPI_Compare_and_swap(origin_addr, compare_addr,
        result_addr, datatype, target_rank,
        target_disp, win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_COMPARE_AND_SWAP);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Compare_and_swap, int, (const void *origin_addr, const void *compare_addr,
        void *result_addr, MPI_Datatype datatype, int target_rank,
        MPI_Aint target_disp, MPI_Win win), MPI_Compare_and_swap)

int DARSHAN_DECL(MPI_Win_fence)(int assert, MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Win_fence);
    TIME(__real_PMPI_Win_fence(assert, win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_FENCE);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_fence, int, (int assert, MPI_Win win), MPI_Win_fence)

int DARSHAN_DECL(MPI_Win_start)(MPI_Group group, int assert, MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Win_start);
    TIME(__real_PMPI_Win_start(group, assert, win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_START);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_start, int, (MPI_Group group, int assert, MPI_Win win), MPI_Win_start)

int DARSHAN_DECL(MPI_Win_complete)(MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Win_complete);
    TIME(__real_PMPI_Win_complete(win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_COMPLETE);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_complete, int, (MPI_Win win), MPI_Win_complete)

int DARSHAN_DECL(MPI_Win_post)(MPI_Group group, int assert, MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Win_post);
    TIME(__real_PMPI_Win_post(group, assert, win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_POST);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_post, int, (MPI_Group group, int assert, MPI_Win win), MPI_Win_post)

int DARSHAN_DECL(MPI_Win_wait)(MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Win_wait);
    TIME(__real_PMPI_Win_wait(win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_WAIT);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_wait, int, (MPI_Win win), MPI_Win_wait)

int DARSHAN_DECL(MPI_Win_test)(MPI_Win win, int *flag)
{
    MAP_OR_FAIL(PMPI_Win_test);
    TIME(__real_PMPI_Win_test(win, flag));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_TEST);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_test, int, (MPI_Win win, int *flag), MPI_Win_test)

int DARSHAN_DECL(MPI_Win_lock)(int lock_type, int rank, int assert, MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Win_lock);
    TIME(__real_PMPI_Win_lock(lock_type, rank, assert, win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_LOCK);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_lock, int, (int lock_type, int rank, int assert, MPI_Win win), MPI_Win_lock)

int DARSHAN_DECL(MPI_Win_unlock)(int rank, MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Win_unlock);
    TIME(__real_PMPI_Win_unlock(rank, win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_UNLOCK);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_unlock, int, (int rank, MPI_Win win), MPI_Win_unlock)

int DARSHAN_DECL(MPI_Win_unlock_all)(MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Win_unlock_all);
    TIME(__real_PMPI_Win_unlock_all(win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_UNLOCK_ALL);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_unlock_all, int, (MPI_Win win), MPI_Win_unlock_all)

int DARSHAN_DECL(MPI_Win_flush)(int rank, MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Win_flush);
    TIME(__real_PMPI_Win_flush(rank, win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_FLUSH);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_flush, int, (int rank, MPI_Win win), MPI_Win_flush)

int DARSHAN_DECL(MPI_Win_flush_all)(MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Win_flush_all);
    TIME(__real_PMPI_Win_flush_all(win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_FLUSH_ALL);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_flush_all, int, (MPI_Win win), MPI_Win_flush_all)

int DARSHAN_DECL(MPI_Win_flush_local)(int rank, MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Win_flush_local);
    TIME(__real_PMPI_Win_flush_local(rank, win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_FLUSH_LOCAL);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_flush_local, int, (int rank, MPI_Win win), MPI_Win_flush_local)

int DARSHAN_DECL(MPI_Win_flush_local_all)(MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Win_flush_local_all);
    TIME(__real_PMPI_Win_flush_local_all(win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_FLUSH_LOCAL_ALL);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_flush_local_all, int, (MPI_Win win), MPI_Win_flush_local_all)

int DARSHAN_DECL(MPI_Win_sync)(MPI_Win win)
{
    MAP_OR_FAIL(PMPI_Win_sync);
    TIME(__real_PMPI_Win_sync(win));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WIN_SYNC);
    APMPI_POST_RECORD();
    
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Win_sync, int, (MPI_Win win), MPI_Win_sync)

1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
int DARSHAN_DECL(MPI_Probe)(int source, int tag, MPI_Comm comm, MPI_Status * status)
{
    MAP_OR_FAIL(PMPI_Probe);
    TIME(__real_PMPI_Probe(source, tag, comm, status));

    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_PROBE);
    APMPI_POST_RECORD();

    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Probe, int,  (int source, int tag, MPI_Comm comm, MPI_Status * status), MPI_Probe)

int DARSHAN_DECL(MPI_Iprobe)(int source, int tag, MPI_Comm comm, int *flag, MPI_Status * status)
{
    MAP_OR_FAIL(PMPI_Iprobe);
    TIME(__real_PMPI_Iprobe(source, tag, comm, flag, status));

    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_IPROBE);
    APMPI_POST_RECORD();

    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Iprobe, int,  (int source, int tag, MPI_Comm comm, int *flag, MPI_Status * status), MPI_Iprobe)

int DARSHAN_DECL(MPI_Test)(MPI_Request *request, int *flag, MPI_Status *status)
{
    MAP_OR_FAIL(PMPI_Test);
    TIME(__real_PMPI_Test(request, flag, status));

    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_TEST);
    APMPI_POST_RECORD();

    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Test, int,  (MPI_Request *request, int *flag, MPI_Status *status), MPI_Test)

int DARSHAN_DECL(MPI_Testany)(int count, MPI_Request array_of_requests[], int *indx,
               int *flag, MPI_Status *status)
{
    MAP_OR_FAIL(PMPI_Testany);
1252
    TIME(__real_PMPI_Testany(count, array_of_requests, indx, flag, status));
1253 1254