darshan.h 4.88 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

Shane Snyder's avatar
Shane Snyder committed
105
/* module developers provide the following functions to darshan-core */
106
struct darshan_module_funcs
107
{
108
    /* disable futher instrumentation within a module */
Shane Snyder's avatar
Shane Snyder committed
109
    void (*disable_instrumentation)(void);
Shane Snyder's avatar
Shane Snyder committed
110
    /* perform any necessary steps prior to reducing */
111
    void (*prepare_for_reduction)(
Shane Snyder's avatar
Shane Snyder committed
112
        darshan_record_id *shared_recs, /* input list of shared records */
113
        int *shared_rec_count, /* in/out shared record count */
Shane Snyder's avatar
Shane Snyder committed
114 115 116
        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 */
117
    );
Shane Snyder's avatar
Shane Snyder committed
118
    /* reduce records which are shared globally across this module */
119
    void (*record_reduction_op)(
120 121 122 123 124 125
        void* infile_v,
        void* inoutfile_v,
        int *len,
        MPI_Datatype *datatype
    );
    /* retrieve module data to write to log file */
126 127 128 129
    void (*get_output_data)(
        void** buf, /* output parameter to save module buffer address */
        int* size /* output parameter to save module buffer size */
    );
130
    /* shutdown module data structures */
131
    void (*shutdown)(void);
132 133
};

134 135 136
/* paths that darshan will not trace */
extern char* darshan_path_exclusions[]; /* defined in lib/darshan-core.c */

137 138 139
/*****************************************************
* darshan-core functions exported to darshan modules *
*****************************************************/
140

141
void darshan_core_register_module(
142
    darshan_module_id mod_id,
143
    struct darshan_module_funcs *funcs,
144 145
    int *mod_mem_limit,
    int *sys_mem_alignment);
146

147 148 149
void darshan_core_unregister_module(
    darshan_module_id mod_id);

Shane Snyder's avatar
Shane Snyder committed
150
void darshan_core_register_record(
151 152 153
    void *name,
    int len,
    int printable_flag,
154
    darshan_module_id mod_id,
155 156
    darshan_record_id *rec_id,
    int *file_alignment);
157

Shane Snyder's avatar
Shane Snyder committed
158 159 160 161
void darshan_core_unregister_record(
    darshan_record_id rec_id,
    darshan_module_id mod_id);

162
double darshan_core_wtime(void);
163

164 165 166 167 168 169
/***********************************************
* darshan-common functions for darshan modules *
***********************************************/

char* darshan_clean_file_path(const char* path);

170
#endif /* __DARSHAN_H */