darshan.h 5.77 KB
Newer Older
1
/*
Shane Snyder's avatar
Shane Snyder committed
2
3
4
 * Copyright (C) 2015 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
5
6
 */

7
8
9
10
11
12
13
#ifndef __DARSHAN_H
#define __DARSHAN_H

#include <unistd.h>
#include <sys/types.h>
#include <stdint.h>
#include <mpi.h>
14

15
16
#include "darshan-log-format.h"

17
18
19
20
21
22
23
24
25
26
27
28
/* Environment variable to override CP_JOBID */
#define CP_JOBID_OVERRIDE "DARSHAN_JOBID"

/* Environment variable to override __CP_LOG_PATH */
#define CP_LOG_PATH_OVERRIDE "DARSHAN_LOGPATH"

/* Environment variable to override __CP_LOG_PATH */
#define CP_LOG_HINTS_OVERRIDE "DARSHAN_LOGHINTS"

/* Environment variable to override __CP_MEM_ALIGNMENT */
#define CP_MEM_ALIGNMENT_OVERRIDE "DARSHAN_MEMALIGN"

29
30
31
32
/* macros for declaring wrapper functions and calling MPI routines
 * consistently regardless of whether static or dynamic linking is used
 */
#ifdef DARSHAN_PRELOAD
Shane Snyder's avatar
Shane Snyder committed
33

34
35
36
37
#include <dlfcn.h>
#include <stdlib.h>

#define DARSHAN_FORWARD_DECL(name,ret,args) \
Shane Snyder's avatar
Shane Snyder committed
38
  ret (*__real_ ## name)args = NULL
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

#define DARSHAN_DECL(__name) __name

#define DARSHAN_MPI_CALL(func) __real_ ## func

#define MAP_OR_FAIL(func) \
    if (!(__real_ ## func)) \
    { \
        __real_ ## func = dlsym(RTLD_NEXT, #func); \
        if(!(__real_ ## func)) { \
           fprintf(stderr, "Darshan failed to map symbol: %s\n", #func); \
           exit(1); \
       } \
    }

#else

#define DARSHAN_FORWARD_DECL(name,ret,args) \
  extern ret __real_ ## name args;

#define DARSHAN_DECL(__name) __wrap_ ## __name

#define DARSHAN_MPI_CALL(func) func

#define MAP_OR_FAIL(func)

#endif

/* macros for manipulating module's counter variables */
/* NOTE: */
69
70
71
72
73
74
75
76
77
#define DARSHAN_COUNTER_SET(__rec_p, __counter, __value) do{ \
    (__rec_p)->counters[__counter] = __value; \
} while(0)

#define DARSHAN_COUNTER_F_SET(__rec_p, __counter, __value) do{ \
    (__rec_p)->fcounters[__counter] = __value; \
} while(0)

#define DARSHAN_COUNTER_INC(__rec_p, __counter, __value) do{ \
78
    (__rec_p)->counters[__counter] += __value; \
79
80
81
} while(0)

#define DARSHAN_COUNTER_F_INC(__rec_p, __counter, __value) do{ \
82
    (__rec_p)->fcounters[__counter] += __value; \
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
} while(0)

#define DARSHAN_COUNTER_F_INC_NO_OVERLAP(__rec_p, __tm1, __tm2, __last, __counter) do{ \
    if(__tm1 > __last) \
        DARSHAN_COUNTER_F_INC(__rec_p, __counter, (__tm2 - __tm1)); \
    else \
        DARSHAN_COUNTER_F_INC(__rec_p, __counter, (__tm2 - __last)); \
    if(__tm2 > __last) \
        __last = __tm2; \
} while(0)

#define DARSHAN_COUNTER_VALUE(__rec_p, __counter) \
    ((__rec_p)->counters[__counter])

#define DARSHAN_COUNTER_F_VALUE(__rec_p, __counter) \
    ((__rec_p)->fcounters[__counter])

#define DARSHAN_COUNTER_MAX(__rec_p, __counter, __value) do{ \
    if((__rec_p)->counters[__counter] < __value) \
        (__rec_p)->counters[__counter] = __value; \
} while(0)
104

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#define DARSHAN_BUCKET_INC(__rec_p, __counter_base, __value) do {\
    if(__value < 101) \
        (__rec_p)->counters[__counter_base] += 1; \
    else if(__value < 1025) \
        (__rec_p)->counters[__counter_base+1] += 1; \
    else if(__value < 10241) \
        (__rec_p)->counters[__counter_base+2] += 1; \
    else if(__value < 102401) \
        (__rec_p)->counters[__counter_base+3] += 1; \
    else if(__value < 1048577) \
        (__rec_p)->counters[__counter_base+4] += 1; \
    else if(__value < 4194305) \
        (__rec_p)->counters[__counter_base+5] += 1; \
    else if(__value < 10485761) \
        (__rec_p)->counters[__counter_base+6] += 1; \
    else if(__value < 104857601) \
        (__rec_p)->counters[__counter_base+7] += 1; \
    else if(__value < 1073741825) \
        (__rec_p)->counters[__counter_base+8] += 1; \
    else \
        (__rec_p)->counters[__counter_base+9] += 1; \
} while(0)

Shane Snyder's avatar
Shane Snyder committed
128
/* module developers provide the following functions to darshan-core */
129
struct darshan_module_funcs
130
{
131
    /* disable futher instrumentation within a module */
Shane Snyder's avatar
Shane Snyder committed
132
    void (*disable_instrumentation)(void);
Shane Snyder's avatar
Shane Snyder committed
133
    /* perform any necessary steps prior to reducing */
134
    void (*prepare_for_reduction)(
Shane Snyder's avatar
Shane Snyder committed
135
        darshan_record_id *shared_recs, /* input list of shared records */
136
        int *shared_rec_count, /* in/out shared record count */
Shane Snyder's avatar
Shane Snyder committed
137
138
139
        void **send_buf, /* send buffer for shared file reduction */
        void **recv_buf, /* recv buffer for shared file reduction (root only) */
        int *rec_size /* size of records being stored for this module */
140
    );
Shane Snyder's avatar
Shane Snyder committed
141
    /* reduce records which are shared globally across this module */
142
    void (*record_reduction_op)(
143
144
145
146
147
148
        void* infile_v,
        void* inoutfile_v,
        int *len,
        MPI_Datatype *datatype
    );
    /* retrieve module data to write to log file */
149
150
151
152
    void (*get_output_data)(
        void** buf, /* output parameter to save module buffer address */
        int* size /* output parameter to save module buffer size */
    );
153
    /* shutdown module data structures */
154
    void (*shutdown)(void);
155
156
};

157
158
159
/* paths that darshan will not trace */
extern char* darshan_path_exclusions[]; /* defined in lib/darshan-core.c */

160
161
162
/*****************************************************
* darshan-core functions exported to darshan modules *
*****************************************************/
163

164
void darshan_core_register_module(
165
    darshan_module_id mod_id,
166
    struct darshan_module_funcs *funcs,
167
168
    int *mod_mem_limit,
    int *sys_mem_alignment);
169

170
171
172
void darshan_core_unregister_module(
    darshan_module_id mod_id);

Shane Snyder's avatar
Shane Snyder committed
173
void darshan_core_register_record(
174
175
176
    void *name,
    int len,
    int printable_flag,
177
    darshan_module_id mod_id,
178
179
    darshan_record_id *rec_id,
    int *file_alignment);
180

Shane Snyder's avatar
Shane Snyder committed
181
182
183
184
void darshan_core_unregister_record(
    darshan_record_id rec_id,
    darshan_module_id mod_id);

185
double darshan_core_wtime(void);
186

187
188
189
190
191
192
/***********************************************
* darshan-common functions for darshan modules *
***********************************************/

char* darshan_clean_file_path(const char* path);

193
#endif /* __DARSHAN_H */