darshan-apmpi.c 77.4 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
20
/*
 * 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 <papi.h>

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

#include "darshan-apmpi-utils.h"
Sudheer Chunduri's avatar
Sudheer Chunduri committed
24
25

typedef long long ap_bytes_t;
26
#define MAX(x,y) ((x>y)?x:y)
27
#define MIN(x,y) ((x==0.0)?y:((x<y)?x:y))
Sudheer Chunduri's avatar
Sudheer Chunduri committed
28

29
30
#ifdef __APMPI_COLL_SYNC

31
32
33
34
35
36
37
38
39
40
#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
41
#else
42

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

#endif
53
54
55
56
57
58
59
60
#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
61
62
63
64
65
66
67
68
69
70
#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

71
72


Sudheer Chunduri's avatar
Sudheer Chunduri committed
73
74
75
/* increment histogram bucket depending on the given __value
 *
 * NOTE: This macro can be used to build a histogram of access
76
 * sizes, offsets, etc. It assumes a 6-bucket histogram, with
Sudheer Chunduri's avatar
Sudheer Chunduri committed
77
78
79
80
81
 * __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
82
 *      * 1 KiB - 8 KiB
Sudheer Chunduri's avatar
Sudheer Chunduri committed
83
84
 *      * 32 KiB - 256 KiB
 *      * 256 KiB - 1 MiB
85
 *      * 1 MiB +
Sudheer Chunduri's avatar
Sudheer Chunduri committed
86
87
88
89
90
91
 */
#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; \
92
    else if(__value < 8193) \
Sudheer Chunduri's avatar
Sudheer Chunduri committed
93
94
95
96
97
98
        *(__bucket_base_p + 2) += 1; \
    else if(__value < 262145) \
        *(__bucket_base_p + 3) += 1; \
    else if(__value < 1048577) \
        *(__bucket_base_p + 4) += 1; \
    else \
99
        *(__bucket_base_p + 5) += 1; \
Sudheer Chunduri's avatar
Sudheer Chunduri committed
100
101
102
} while(0)


Sudheer Chunduri's avatar
Sudheer Chunduri committed
103
DARSHAN_FORWARD_DECL(PMPI_Send, int, (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm));
104
105
106
107
108
109
110
111
112
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));
113
114
115
116
117
118
119
120
121
122
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));
*/
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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[]));
138
139
140
141
142
143
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
144
145
146
147
148
149
150
151
152
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));
153
154
155
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
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));
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
209
210
211
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
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
256
257
258
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
259
260
261
/*
 * Global runtime struct for tracking data needed at runtime
 */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
262
struct apmpi_runtime
Sudheer Chunduri's avatar
Sudheer Chunduri committed
263
{
Sudheer Chunduri's avatar
Sudheer Chunduri committed
264
    struct darshan_apmpi_perf_record *perf_record;
265
    struct darshan_apmpi_header_record *header_record;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
266
    darshan_record_id rec_id;
267
    darshan_record_id header_id;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
268
269
};

Sudheer Chunduri's avatar
Sudheer Chunduri committed
270
271
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
272
273
274
275

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

Sudheer Chunduri's avatar
Sudheer Chunduri committed
276
277
/* internal helper functions for the apmpi module */
void apmpi_runtime_initialize(void);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
278
279
280

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

Sudheer Chunduri's avatar
Sudheer Chunduri committed
291
292
293
/* 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
294
295

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

static void finalize_counters (void)
{

    return;
}

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

    return;
}

Sudheer Chunduri's avatar
Sudheer Chunduri committed
341
void apmpi_runtime_initialize()
Sudheer Chunduri's avatar
Sudheer Chunduri committed
342
{
Sudheer Chunduri's avatar
Sudheer Chunduri committed
343
344
    int apmpi_buf_size;
    char rec_name[128];
Sudheer Chunduri's avatar
Sudheer Chunduri committed
345
346
347

    darshan_module_funcs mod_funcs = {
#ifdef HAVE_MPI
Sudheer Chunduri's avatar
Sudheer Chunduri committed
348
        .mod_redux_func = &apmpi_mpi_redux,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
349
#endif
Sudheer Chunduri's avatar
Sudheer Chunduri committed
350
        .mod_shutdown_func = &apmpi_shutdown
Sudheer Chunduri's avatar
Sudheer Chunduri committed
351
352
        };

Sudheer Chunduri's avatar
Sudheer Chunduri committed
353
    APMPI_LOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
354
355

    /* don't do anything if already initialized */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
356
    if(apmpi_runtime)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
357
    {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
358
        APMPI_UNLOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
359
360
361
        return;
    }

362
363
    apmpi_buf_size = sizeof(struct darshan_apmpi_header_record) +
                     sizeof(struct darshan_apmpi_perf_record);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
364

Sudheer Chunduri's avatar
Sudheer Chunduri committed
365
    /* register the apmpi module with the darshan-core component */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
366
    darshan_core_register_module(
Sudheer Chunduri's avatar
Sudheer Chunduri committed
367
        APMPI_MOD,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
368
        mod_funcs,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
369
        &apmpi_buf_size,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
370
371
372
        &my_rank,
        NULL);

Sudheer Chunduri's avatar
Sudheer Chunduri committed
373
    /* not enough memory to fit apmpi module record */
374
    if(apmpi_buf_size < sizeof(struct darshan_apmpi_header_record) + sizeof(struct darshan_apmpi_perf_record))
Sudheer Chunduri's avatar
Sudheer Chunduri committed
375
    {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
376
        darshan_core_unregister_module(APMPI_MOD);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
377
        APMPI_UNLOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
378
379
380
381
        return;
    }

    /* initialize module's global state */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
382
383
    apmpi_runtime = malloc(sizeof(*apmpi_runtime));
    if(!apmpi_runtime)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
384
    {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
385
        darshan_core_unregister_module(APMPI_MOD);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
386
        APMPI_UNLOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
387
388
        return;
    }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
389
    memset(apmpi_runtime, 0, sizeof(*apmpi_runtime));
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413

    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",
            APMPI_MOD,
            sizeof(struct darshan_apmpi_header_record),
            NULL);
        if(!(apmpi_runtime->header_record))
        {   
            darshan_core_unregister_module(APMPI_MOD);
            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;
414
415
416
417
418
#ifdef __APMPI_COLL_SYNC
        apmpi_runtime->header_record->sync_flag = 1;
#else
        apmpi_runtime->header_record->sync_flag = 0;
#endif
419
        apmpi_runtime->header_record->version = APMPI_VER;
420
421
    }

422
    apmpi_runtime->rec_id = darshan_core_gen_record_id("APMPI"); //record name
Sudheer Chunduri's avatar
Sudheer Chunduri committed
423
424
425
426

    apmpi_runtime->perf_record = darshan_core_register_record(
        apmpi_runtime->rec_id,
        "APMPI",
Sudheer Chunduri's avatar
Sudheer Chunduri committed
427
        APMPI_MOD,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
428
        sizeof(struct darshan_apmpi_perf_record),
Sudheer Chunduri's avatar
Sudheer Chunduri committed
429
        NULL);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
430
    if(!(apmpi_runtime->perf_record))
Sudheer Chunduri's avatar
Sudheer Chunduri committed
431
    {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
432
        darshan_core_unregister_module(APMPI_MOD);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
433
434
435
        free(apmpi_runtime);
        apmpi_runtime = NULL;
        APMPI_UNLOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
436
437
438
439
        return;
    }

    initialize_counters();
440
441
    /* collect perf counters */
    capture(apmpi_runtime->perf_record, apmpi_runtime->rec_id);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
442

Sudheer Chunduri's avatar
Sudheer Chunduri committed
443
    APMPI_UNLOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
444
445
446

    return;
}
Sudheer Chunduri's avatar
Sudheer Chunduri committed
447
#if 0
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
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
464
static void apmpi_shared_record_variance(MPI_Comm mod_comm)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
465
466
467
468
469
470
471
472
473
474
475
476
477
{
    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);

478
    var_send_buf = malloc(sizeof(struct darshan_variance_dt));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
479
480
481
482
483
    if(!var_send_buf)
        return;

    if(my_rank == 0)
    {   
484
        var_recv_buf = malloc(sizeof(struct darshan_variance_dt));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
485
486
487
488
489

        if(!var_recv_buf)
            return;
    }   

490
    /* get total mpi time variances across the ranks */
491
492
    var_send_buf->n = 1;
    var_send_buf->S = 0;
493
    var_send_buf->T = apmpi_runtime->perf_record->fglobalcounters[RANK_TOTAL_MPITIME];
Sudheer Chunduri's avatar
Sudheer Chunduri committed
494

495
    PMPI_Reduce(var_send_buf, var_recv_buf, 1,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
496
497
498
499
        var_dt, var_op, 0, mod_comm);

    if(my_rank == 0)
    {   
500
       apmpi_runtime->header_record->apmpi_f_variance_total_mpitime =
501
                (var_recv_buf->S / var_recv_buf->n);
502
    }
503
504
505
506
507
508
509
510
511
512
513
514
515
    /* 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
516
517
518
519
520
521
522
523
    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
524
525
526
527
528

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

Sudheer Chunduri's avatar
Sudheer Chunduri committed
529
/* Pass data for the apmpi module back to darshan-core to log to file. */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
530
//#ifdef HAVE_MPI
Sudheer Chunduri's avatar
Sudheer Chunduri committed
531
532
static void apmpi_mpi_redux(
    void *apmpi_buf,
Sudheer Chunduri's avatar
Sudheer Chunduri committed
533
534
535
536
537
    MPI_Comm mod_comm,
    darshan_record_id *shared_recs,
    int shared_rec_count)
{
    int i;
538
#if 0
Sudheer Chunduri's avatar
Sudheer Chunduri committed
539
540
    struct darshan_apmpi_perf_record *red_send_buf = NULL;
    struct darshan_apmpi_perf_record *red_recv_buf = NULL;
541
    struct darshan_apmpi_perf_record *apmpi_rec_buf = (struct darshan_apmpi_perf_record *)apmpi_buf;
542
#endif
Sudheer Chunduri's avatar
Sudheer Chunduri committed
543
    MPI_Datatype red_type;
544
    //MPI_Op red_op;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
545

Sudheer Chunduri's avatar
Sudheer Chunduri committed
546
547
548
    APMPI_LOCK();

    if (!apmpi_runtime)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
549
    {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
550
        APMPI_UNLOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
551
552
        return;
    }
553
    double mpisync_time = 0.0;
554
    /* Compute Total MPI time per rank: RANK_TOTAL_MPITIME */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
555
    for (i=MPI_SEND_TOTAL_TIME; i<APMPI_F_MPIOP_TOTALTIME_NUM_INDICES; i+=3){
556
        apmpi_runtime->perf_record->fglobalcounters[RANK_TOTAL_MPITIME] += apmpi_runtime->perf_record->fcounters[i];
557
    }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
558
    for (i=MPI_BARRIER_TOTAL_SYNC_TIME; i<APMPI_F_MPIOP_SYNCTIME_NUM_INDICES; i++){
559
        mpisync_time += apmpi_runtime->perf_record->fsynccounters[i];
560
    }
561
562
    apmpi_runtime->perf_record->fglobalcounters[RANK_TOTAL_MPITIME] += mpisync_time;
    apmpi_runtime->perf_record->fglobalcounters[RANK_TOTAL_MPISYNCTIME] = mpisync_time;
563
564
#if 0
    red_send_buf = apmpi_runtime->perf_record;
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588

    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 */
589
590
     apmpi_shared_record_variance(mod_comm);
#if 0
591
592
593
594
595
    /* clean up reduction state */
    if(my_rank == 0)
    {   
        free(red_recv_buf);
    }   
596
#endif    
597
598
599
    //PMPI_Type_free(&red_type);
    //PMPI_Op_free(&red_op);

Sudheer Chunduri's avatar
Sudheer Chunduri committed
600
    APMPI_UNLOCK();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
601

Sudheer Chunduri's avatar
Sudheer Chunduri committed
602
603
    return;
}
Sudheer Chunduri's avatar
Sudheer Chunduri committed
604

Sudheer Chunduri's avatar
Sudheer Chunduri committed
605
606
607
608
609
610
//#endif
static void apmpi_shutdown(
    void **apmpi_buf,
    int *apmpi_buf_sz)
{
    int apmpi_rec_count;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
611

Sudheer Chunduri's avatar
Sudheer Chunduri committed
612
613
    APMPI_LOCK();
    assert(apmpi_runtime);
614
615
616
617
618
619
    *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
620
621
622
    finalize_counters();
    free(apmpi_runtime);
    apmpi_runtime = NULL;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
623

Sudheer Chunduri's avatar
Sudheer Chunduri committed
624
625
626
    APMPI_UNLOCK();
    return;
}
Sudheer Chunduri's avatar
Sudheer Chunduri committed
627

Sudheer Chunduri's avatar
Sudheer Chunduri committed
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
#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)

644
#define APMPI_RECORD_UPDATE(MPI_OP) do { \
645
    if(ret != MPI_SUCCESS) break; \
646
647
648
649
650
651
652
653
654
    apmpi_runtime->perf_record->counters[Y(MPI_OP ## _CALL_COUNT)]++; \
    apmpi_runtime->perf_record->counters[Y(MPI_OP ## _TOTAL_BYTES)] += bytes; \
    DARSHAN_MSG_BUCKET_INC(&(apmpi_runtime->perf_record->counters[Y(MPI_OP ## _MSG_SIZE_AGG_0_256)]), bytes); \
    apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _TOTAL_TIME)] += tdiff; \
    apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MAX_TIME)] = MAX(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MAX_TIME)], tdiff); \
    apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MIN_TIME)] = MIN(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MIN_TIME)], tdiff); \
    } while(0)

#define APMPI_RECORD_UPDATE_NOMSG(MPI_OP) do { \
655
    if(ret != MPI_SUCCESS) break; \
656
657
658
659
660
661
662
    apmpi_runtime->perf_record->counters[Y(MPI_OP ## _CALL_COUNT)]++; \
    apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _TOTAL_TIME)] += tdiff; \
    apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MAX_TIME)] = MAX(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MAX_TIME)], tdiff); \
    apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MIN_TIME)] = MIN(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MIN_TIME)], tdiff); \
    } while(0)

#define APMPI_RECORD_UPDATE_SYNC(MPI_OP) do { \
663
    if(ret != MPI_SUCCESS) break; \
664
665
666
667
668
669
670
671
672
673
    apmpi_runtime->perf_record->counters[Y(MPI_OP ## _CALL_COUNT)]++; \
    apmpi_runtime->perf_record->counters[Y(MPI_OP ## _TOTAL_BYTES)] += bytes; \
    DARSHAN_MSG_BUCKET_INC(&(apmpi_runtime->perf_record->counters[Y(MPI_OP ## _MSG_SIZE_AGG_0_256)]), bytes); \
    apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _TOTAL_TIME)] += tdiff; \
    apmpi_runtime->perf_record->fsynccounters[Y(MPI_OP ## _TOTAL_SYNC_TIME)] += tsync; \
    apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MAX_TIME)] = MAX(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MAX_TIME)], tdiff); \
    apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MIN_TIME)] = MIN(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MIN_TIME)], tdiff); \
    } while(0)

#define APMPI_RECORD_UPDATE_SYNC_NOMSG(MPI_OP) do { \
674
    if(ret != MPI_SUCCESS) break; \
675
676
677
678
679
680
681
682
    apmpi_runtime->perf_record->counters[Y(MPI_OP ## _CALL_COUNT)]++; \
    apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _TOTAL_TIME)] += tdiff; \
    apmpi_runtime->perf_record->fsynccounters[Y(MPI_OP ## _TOTAL_SYNC_TIME)] += tsync; \
    apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MAX_TIME)] = MAX(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MAX_TIME)], tdiff); \
    apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MIN_TIME)] = MIN(apmpi_runtime->perf_record->fcounters[Y(MPI_OP ## _MIN_TIME)], tdiff); \
    } while(0)
#define Y(a) a

Sudheer Chunduri's avatar
Sudheer Chunduri committed
683
684
685
686
/**********************************************************
 *        Wrappers for MPI functions of interest       * 
 **********************************************************/

687
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
688
689
{
    MAP_OR_FAIL(PMPI_Send);
690
691
    TIME(__real_PMPI_Send(buf, count, datatype, dest, tag, comm));
    BYTECOUNT(datatype, count);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
692
    APMPI_PRE_RECORD();
693
    // Potential optimization: Lock around the count - lock only if MPI_THREAD_MULTIPLE is used ... locking mutex
694
695
    APMPI_RECORD_UPDATE(MPI_SEND);
    APMPI_POST_RECORD();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
696
697
698
    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
699

700
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
701
{
702
703
704
705
706
707
708
709
710
    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
711

712
713
714
715
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
716
    BYTECOUNT(datatype, count);
717
    APMPI_PRE_RECORD();
718
    APMPI_RECORD_UPDATE(MPI_RSEND);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
719
720
721
    APMPI_POST_RECORD();
    return ret;
}
722
723
724
725
726
727
728
729
730
731
732
733
734
735
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
736
737
738
739
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);
740
741
    TIME(__real_PMPI_Isend(buf, count, datatype, dest, tag, comm, request));
    BYTECOUNT(datatype, count);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
742
    APMPI_PRE_RECORD();
743
    APMPI_RECORD_UPDATE(MPI_ISEND);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
744
745
    APMPI_POST_RECORD();
    return ret;
Sudheer Chunduri's avatar
Sudheer Chunduri committed
746
}
Sudheer Chunduri's avatar
Sudheer Chunduri committed
747
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
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
785
786
787
788
789
790
791
792
793
794
795
796
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;
797
        //src = status->MPI_SOURCE;
798
799
800
    } 
    else {
        count_received = count;
801
        //src = source;
802
803
804
805
806
807
808
809
810
811
    }

    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
812
813
814
815
816
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);

817
818
    TIME(__real_PMPI_Irecv(buf, count, datatype, source, tag, comm, request));
    BYTECOUNT(datatype, count);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
819
    APMPI_PRE_RECORD();
820
    APMPI_RECORD_UPDATE(MPI_IRECV);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
821
822
823
824
825
    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)

826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
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
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
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;
}
880
881
882
883
/*
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)
884
{
885
    MAP_OR_FAIL(PMPI_Isendrecv);
886
    
887
    TIME(__real_PMPI_Isendrecv(sendbuf, sendcount, sendtype, dest, sendtag, recvbuf, recvcount, recvtype, source, recvtag, comm, request));
888
    
889
    BYTECOUNT(sendtype, sendcount + recvcount);
890
891
    
    APMPI_PRE_RECORD();
892
    APMPI_RECORD_UPDATE(MPI_ISENDRECV);
893
894
895
    APMPI_POST_RECORD();
    return ret;
}
896
897
898
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)
899

900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
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)
*/
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
942
943
944
945
946
947
948
949
950
951
952
953
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)

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
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220

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)

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
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
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);
1264
    TIME(__real_PMPI_Testany(count, array_of_requests, indx, flag, status));
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312

    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_TESTANY);
    APMPI_POST_RECORD();

    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Testany, int,  (int count, MPI_Request array_of_requests[], int *indx,
               int *flag, MPI_Status *status), MPI_Testany)

int DARSHAN_DECL(MPI_Testall)(int count, MPI_Request array_of_requests[], 
               int *flag, MPI_Status array_of_statuses[])
{
    MAP_OR_FAIL(PMPI_Testall);
    TIME(__real_PMPI_Testall(count, array_of_requests, flag, array_of_statuses));

    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_TESTALL);
    APMPI_POST_RECORD();

    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Testall, int,  (int count, MPI_Request array_of_requests[], 
               int *flag, MPI_Status array_of_statuses[]), MPI_Testall)

int DARSHAN_DECL(MPI_Testsome)(int incount, MPI_Request array_of_requests[], int *outcount,
                 int array_of_indices[], MPI_Status array_of_statuses[])
{
    MAP_OR_FAIL(PMPI_Testsome);
    TIME(__real_PMPI_Testsome(incount, array_of_requests, outcount, array_of_indices, array_of_statuses));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_TESTSOME);
    APMPI_POST_RECORD();

    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Testsome, int, (int incount, MPI_Request array_of_requests[], int *outcount,
                 int array_of_indices[], MPI_Status array_of_statuses[]), MPI_Testsome)

int DARSHAN_DECL(MPI_Wait)(MPI_Request * request, MPI_Status * status)
{
    MAP_OR_FAIL(PMPI_Wait);
    TIME(__real_PMPI_Wait(request, status));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WAIT);
    APMPI_POST_RECORD();
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1313

1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Wait, int, (MPI_Request * request, MPI_Status * status), MPI_Wait)

int DARSHAN_DECL(MPI_Waitany)(int count, MPI_Request array_of_requests[], int *indx, MPI_Status * status)
{
    MAP_OR_FAIL(PMPI_Waitany);
    TIME(__real_PMPI_Waitany(count, array_of_requests, indx, status));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WAITANY);
    APMPI_POST_RECORD();

    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Waitany, int, (int count, MPI_Request array_of_requests[], int *indx, MPI_Status * status), MPI_Waitany)

int DARSHAN_DECL(MPI_Waitall)(int count, MPI_Request array_of_requests[], 
               MPI_Status array_of_statuses[])
{
    MAP_OR_FAIL(PMPI_Waitall);
    TIME(__real_PMPI_Waitall(count, array_of_requests, array_of_statuses));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WAITALL);
    APMPI_POST_RECORD();

    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Waitall, int, (int count, MPI_Request array_of_requests[], 
               MPI_Status array_of_statuses[]), MPI_Waitall)

int DARSHAN_DECL(MPI_Waitsome)(int incount, MPI_Request array_of_requests[],
                 int *outcount, int array_of_indices[], MPI_Status array_of_statuses[])
{
    MAP_OR_FAIL(PMPI_Waitsome);
    TIME(__real_PMPI_Waitsome(incount, array_of_requests, outcount, array_of_indices, array_of_statuses));
    
    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_NOMSG(MPI_WAITSOME);
    APMPI_POST_RECORD();

    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Waitsome, int, (int incount, MPI_Request array_of_requests[],
                 int *outcount, int array_of_indices[], MPI_Status array_of_statuses[]), MPI_Waitsome)
1360

Sudheer Chunduri's avatar
Sudheer Chunduri committed
1361
int DARSHAN_DECL(MPI_Barrier)(MPI_Comm comm)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1362
{
1363
    MAP_OR_FAIL(PMPI_Barrier);
1364
    TIME_SYNC(__real_PMPI_Barrier(comm));
1365
  
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1366
    APMPI_PRE_RECORD();
1367
    APMPI_RECORD_UPDATE_SYNC_NOMSG(MPI_BARRIER);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1368
    APMPI_POST_RECORD();
1369

Sudheer Chunduri's avatar
Sudheer Chunduri committed
1370
1371
1372
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Barrier, int,  (MPI_Comm comm), MPI_Barrier)
1373

Sudheer Chunduri's avatar
Sudheer Chunduri committed
1374
1375
1376
int DARSHAN_DECL(MPI_Bcast)(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
{
    MAP_OR_FAIL(PMPI_Bcast);
1377
1378
1379
1380
1381
1382
1383
1384
    
    TIME_SYNC(__real_PMPI_Bcast(buffer, count, datatype, root, comm));

    ap_bytes_t bytes = 0;
    if (root != MPI_PROC_NULL) {
        BYTECOUNTND(datatype, count);
    }

Sudheer Chunduri's avatar
Sudheer Chunduri committed
1385
    APMPI_PRE_RECORD();
1386
    APMPI_RECORD_UPDATE_SYNC(MPI_BCAST);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
    APMPI_POST_RECORD();
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Bcast, int, (void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm), MPI_Bcast)

int DARSHAN_DECL(MPI_Reduce)(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root,
             MPI_Comm comm)
{
    MAP_OR_FAIL(PMPI_Reduce);
  
1397
1398
1399
1400
1401
1402
1403
    TIME_SYNC(__real_PMPI_Reduce(sendbuf, recvbuf, count, datatype, op, root, comm));

    ap_bytes_t bytes = 0;
    if (root != MPI_PROC_NULL) {
        BYTECOUNTND(datatype, count);
    }

Sudheer Chunduri's avatar
Sudheer Chunduri committed
1404
    APMPI_PRE_RECORD();
1405
    APMPI_RECORD_UPDATE_SYNC(MPI_REDUCE);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1406
1407
1408
1409
    APMPI_POST_RECORD();
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Reduce, int,  (const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm), MPI_Reduce)
1410

Sudheer Chunduri's avatar
Sudheer Chunduri committed
1411
1412
1413
1414
int DARSHAN_DECL(MPI_Allreduce)(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op,
             MPI_Comm comm)
{
    MAP_OR_FAIL(PMPI_Allreduce);
1415

1416
    TIME_SYNC(__real_PMPI_Allreduce(sendbuf, recvbuf, count, datatype, op, comm));
1417

Sudheer Chunduri's avatar
Sudheer Chunduri committed
1418
    BYTECOUNT(datatype, count);
1419
1420
1421

    APMPI_PRE_RECORD();
    APMPI_RECORD_UPDATE_SYNC(MPI_ALLREDUCE);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1422
    APMPI_POST_RECORD();
1423

Sudheer Chunduri's avatar
Sudheer Chunduri committed
1424
1425
1426
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Allreduce, int,  (const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm), MPI_Allreduce)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1427

Sudheer Chunduri's avatar
Sudheer Chunduri committed
1428
1429
1430
1431
1432
1433
int DARSHAN_DECL(MPI_Alltoall)(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
                 void *recvbuf, int recvcount, MPI_Datatype recvtype,
                 MPI_Comm comm)
{
    MAP_OR_FAIL(PMPI_Alltoall);
  
1434
1435
1436
1437
1438
1439
1440
    TIME_SYNC(__real_PMPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm));

    BYTECOUNT(recvtype, recvcount);
    int tasks;
    PMPI_Comm_size(comm, &tasks);
    bytes = bytes*tasks;

Sudheer Chunduri's avatar
Sudheer Chunduri committed
1441
    APMPI_PRE_RECORD();
1442
    APMPI_RECORD_UPDATE_SYNC(MPI_ALLTOALL);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1443
1444
1445
1446
1447
1448
    APMPI_POST_RECORD();
    return ret;
}
DARSHAN_WRAPPER_MAP(PMPI_Alltoall, int, (const void *sendbuf, int sendcount, MPI_Datatype sendtype,
                 void *recvbuf, int recvcount, MPI_Datatype recvtype,
                 MPI_Comm comm), MPI_Alltoall)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1449

Sudheer Chunduri's avatar
Sudheer Chunduri committed
1450
1451
1452
1453
1454
1455
int DARSHAN_DECL(MPI_Alltoallv)(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)
{
    MAP_OR_FAIL(PMPI_Alltoallv);
  
1456
1457
1458
1459
1460
1461
1462
1463
1464
    TIME_SYNC(__real_PMPI_Alltoallv(sendbuf, sendcounts, sdispls, sendtype, recvbuf, recvcounts, rdispls, recvtype, comm));

    int tsize;
    PMPI_Type_size(recvtype, &tsize);
    int i, tasks, count = 0;
    PMPI_Comm_size(comm, &tasks);
    for (i=0; i<tasks; i++) count += recvcounts[i];
    ap_bytes_t bytes = (ap_bytes_t) (count * tsize);

Sudheer Chunduri's avatar
Sudheer Chunduri committed
1465
    APMPI_PRE_RECORD();
1466
    APMPI_RECORD_UPDATE_SYNC(MPI_ALLTOALLV);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1467
1468
1469
1470
1471
1472
1473
    APMPI_POST_RECORD();
    return ret;
}
DARSHAN_WRAPPER_MAP(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), MPI_Alltoallv)

1474
1475
1476
int DARSHAN_DECL(MPI_Alltoallw)(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
1477
{
1478
1479
1480
    MAP_OR_FAIL(PMPI_Alltoallw);
  
    TIME_SYNC(__real_PMPI_Alltoallw(sendbuf, sendcounts, sdispls, sendtypes, recvbuf, recvcounts, rdispls, recvtypes, comm));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1481

1482
1483
1484
1485
1486
1487
1488
    ap_bytes_t bytes = 0;
    int i, tasks, tsize;
    PMPI_Comm_size(comm, &tasks);
    for (i=0; i<tasks; i++) {
      PMPI_Type_size(recvtypes[i],