OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

vt_thrd.h
1 /**
2 * VampirTrace
3 * http://www.tu-dresden.de/zih/vampirtrace
4 *
5 * Copyright (c) 2005-2012, ZIH, TU Dresden, Federal Republic of Germany
6 *
7 * Copyright (c) 1998-2005, Forschungszentrum Juelich, Juelich Supercomputing
8 * Centre, Federal Republic of Germany
9 *
10 * See the file COPYING in the package base directory for details
11 **/
12
13 #ifndef _VT_THRD_H
14 #define _VT_THRD_H
15
16 #ifdef __cplusplus
17 # define EXTERN extern "C"
18 #else
19 # define EXTERN extern
20 #endif
21
22 #include "config.h"
23
24 #include "vt_defs.h"
25 #include "vt_error.h"
26 #include "vt_inttypes.h"
27 #include "vt_otf_gen.h"
28
29 #if defined(VT_JAVA)
30 # include "vt_java.h"
31 #endif /* VT_JAVA */
32
33 #if defined(VT_RUSAGE)
34 # include "vt_rusage.h"
35 #endif /* VT_RUSAGE */
36
37
38 #include "rfg.h"
39
40 #if (defined(VT_MT) || defined(VT_HYB))
41 # define VT_MY_THREAD_IS_ALIVE VTThrd_isAlive()
42 # define VT_MY_THREAD VTThrd_getThreadId()
43 # define VT_CHECK_THREAD VTThrd_registerThread(0)
44 #elif defined(VT_JAVA)
45 # define VT_MY_THREAD_IS_ALIVE VTThrd_isAlive()
46 # define VT_MY_THREAD VTThrd_getThreadId()
47 # define VT_CHECK_THREAD
48 #else
49 # define VT_MY_THREAD_IS_ALIVE 1
50 # define VT_MY_THREAD 0
51 # define VT_CHECK_THREAD
52 #endif
53
54
55
56 /** Maximum number of threads to be created */
57 EXTERN uint32_t VTThrdMaxNum;
58
59 /** VTThrd struct holds all thread-specific data:
60 * - Trace buffer and file including file name
61 * - Event sets and value vector
62 * - ...
63 *-----------------------------------------------------------------------------
64 */
65 typedef struct
66 {
67 VTGen* gen; /**< trace file and buffer */
68
69 char name[512]; /**< thread name */
70 char name_suffix[128]; /**< suffix of thread name */
71
72 int stack_level; /**< current call stack level */
73 int stack_level_at_off; /**< call stack level at trace off */
74 int stack_level_at_rewind_mark; /**< call stack level at rewind mark */
75
76 int8_t trace_status; /**< trace status:
77 VT_TRACE_ON,
78 VT_TRACE_OFF, or
79 VT_TRACE_OFF_PERMANENT */
80
81 uint32_t parent_tid; /**< parent thread id */
82 uint32_t child_num; /**< number of child threads */
83
84 uint8_t is_virtual; /**< flag: is virtual thread? (e.g. GPU) */
85
86 #if !defined(VT_DISABLE_RFG)
87
88 RFG_Regions* rfg_regions; /**< RFG regions object */
89
90 #endif /* VT_DISABLE_RFG */
91
92 #if (defined (VT_MPI) || defined (VT_HYB))
93
94 uint64_t mpicoll_next_matchingid; /**< matching id counter for MPI collective
95 operations. */
96
97 #endif /* VT_MPI || VT_HYB */
98
99 #if defined(VT_IOWRAP)
100
101 uint8_t io_tracing_state; /**< save value of enabled flag during
102 suspend */
103 uint8_t io_tracing_suspend_cnt; /**< save how often suspend was called */
104 uint8_t io_tracing_enabled; /**< actual mode of I/O tracing operation */
105
106 #endif /* VT_IOWRAP */
107
108 #if (defined (VT_IOWRAP) || (defined(HAVE_MPI2_IO) && HAVE_MPI2_IO))
109
110 uint64_t io_next_matchingid;
111 uint64_t io_next_handle;
112
113 #endif
114
115 #if defined(VT_GETCPU)
116
117 uint32_t cpuid_val; /**< cpu id counter value */
118
119 #endif /* VT_GETCPU */
120
121 #if defined(VT_RUSAGE)
122
123 uint64_t ru_next_read; /**< next timestamp for reading rusage
124 counters */
125 uint64_t* ru_valv; /**< vector of rusage values */
126 struct vt_rusage* ru_obj; /**< rusage object */
127
128 #endif /* VT_RUSAGE */
129
130 #if defined(VT_METR)
131
132 uint64_t* offv; /**< vector of counter offsets */
133 uint64_t* valv; /**< vector of counter values */
134 struct vt_metv* metv; /**< vector of metric objects
135 (i.e.the event sets) */
136
137 #endif /* VT_METR */
138
139
140 #if defined(VT_PLUGIN_CNTR)
141
142 void* plugin_cntr_defines; /**< plugin cntr handle */
143
144 #endif /* VT_PLUGIN_CNTR || VT_CUDARTWRAP */
145
146 } VTThrd;
147
148 /* Accessor macros */
149
150 #define VTTHRD_MY_VTTHRD (VTThrdv[VT_MY_THREAD])
151
152 /* flag: is tracing enabled? */
153 #define VTTHRD_TRACE_STATUS(thrd) (thrd->trace_status)
154
155 /* trace file and buffer */
156 #define VTTHRD_GEN(thrd) (thrd->gen)
157
158 /* prefix of thread's name */
159 #define VTTHRD_NAME_PREFIX(thrd) (thrd->name_prefix)
160
161 /* suffix of thread's name */
162 #define VTTHRD_NAME_SUFFIX(thrd) (thrd->name_suffix)
163
164 /* external name of thread */
165 #define VTTHRD_NAME_EXTERNAL(thrd) (thrd->name_extern)
166
167 /* parent thread id */
168 #define VTTHRD_PARENT_TID(thrd) (thrd->parent_tid);
169
170 /* number of child threads */
171 #define VTTHRD_CHILD_NUM(thrd) (thrd->child_num);
172
173 /* current call stack level */
174 #define VTTHRD_STACK_LEVEL(thrd) (thrd->stack_level)
175
176 /* call stack level at trace off */
177 #define VTTHRD_STACK_LEVEL_AT_OFF(thrd) \
178 (thrd->stack_level_at_off)
179
180 /* call stack level at rewind mark */
181 #define VTTHRD_STACK_LEVEL_AT_REWIND_MARK(thrd) \
182 (thrd->stack_level_at_rewind_mark)
183
184 /* push the call stack */
185 #define VTTHRD_STACK_PUSH(thrd) (thrd->stack_level)++
186
187 /* pop the call stack */
188 #define VTTHRD_STACK_POP(thrd) if(--(thrd->stack_level) < 0) \
189 vt_error_msg("Stack underflow");
190
191 /* RFG regions object */
192 #define VTTHRD_RFGREGIONS(thrd) (thrd->rfg_regions)
193
194 /* flag: is virtual thread? */
195 #define VTTHRD_IS_VIRTUAL(thrd) (thrd->is_virtual)
196
197 #if (defined (VT_MPI) || defined (VT_HYB))
198 /* matching id counter for MPI coll. ops. */
199 #define VTTHRD_MPICOLLOP_NEXT_MATCHINGID(thrd) \
200 (thrd->mpicoll_next_matchingid++)
201 #endif /* VT_MPI || VT_HYB */
202
203 #if (defined (VT_IOWRAP))
204
205 /* save enabled/disabled state of I/O tracing when switching off temporarily */
206 #define VTTHRD_IO_TRACING_STATE(thrd) \
207 (thrd->io_tracing_state)
208 #define VTTHRD_IO_TRACING_SUSPEND_CNT(thrd) \
209 (thrd->io_tracing_suspend_cnt)
210
211 /* flag: is I/O tracing enabled? */
212 #define VTTHRD_IO_TRACING_ENABLED(thrd) \
213 (thrd->io_tracing_enabled)
214
215 #endif /* VT_IOWRAP */
216
217 #if (defined (VT_IOWRAP) || (defined(HAVE_MPI2_IO) && HAVE_MPI2_IO))
218 #define VTTHRD_IO_NEXT_MATCHINGID(thrd) \
219 (thrd->io_next_matchingid++)
220 #define VTTHRD_IO_NEXT_HANDLE(thrd) \
221 (thrd->io_next_handle++)
222 #endif /* VT_IOWRAP || (HAVE_MPI2_IO && HAVE_MPI2_IO) */
223
224 #if (defined (VT_GETCPU))
225
226 /* cpu id counter value */
227 #define VTTHRD_CPUID_VAL(thrd) (thrd->cpuid_val)
228
229 #endif /* VT_GETCPU */
230
231 #if (defined (VT_RUSAGE))
232
233 /* next timestamp for reading rusage counters */
234 #define VTTHRD_RU_NEXT_READ(thrd) (thrd->ru_next_read)
235
236 /* rusage values */
237 #define VTTHRD_RU_VALV(thrd) (thrd->ru_valv)
238
239 /* rusage object */
240 #define VTTHRD_RU_OBJ(thrd) (thrd->ru_obj)
241
242 #endif /* VT_RUSAGE */
243
244 #if (defined (VT_METR))
245
246 /* vector of metric offsets */
247 #define VTTHRD_OFFV(thrd) (thrd->offv)
248
249 /* vector of metric values */
250 #define VTTHRD_VALV(thrd) (thrd->valv)
251
252 /* vector of metric objects (i.e., event sets) */
253 #define VTTHRD_METV(thrd) (thrd->metv)
254
255 #endif /* VT_METR */
256
257 #if defined(VT_PLUGIN_CNTR)
258
259 /* plugin cntr handle */
260 #define VTTHRD_PLUGIN_CNTR_DEFINES(thrd) \
261 (thrd->plugin_cntr_defines)
262
263 #endif /* VT_PLUGIN_CNTR */
264
265
266 /**
267 * Initialize thread object management.
268 */
269 EXTERN void VTThrd_init( void );
270
271 /**
272 * Finalize thread object management.
273 */
274 EXTERN void VTThrd_finalize( void );
275
276 /**
277 * Creates a new thread object.
278 *
279 * @param tname thread name (optional)
280 * @param ptid the ID of the parent thread/process
281 * @param is_virtual flag: is the thread a virtual thread? (e.g. GPU)
282 *
283 * @return thread ID associated with the new thread object
284 */
285 EXTERN uint32_t VTThrd_create(const char* tname, uint32_t ptid,
286 uint8_t is_virtual);
287
288 /**
289 * Free thread object.
290 *
291 * @param thrd thread object
292 * @param tid thread ID
293 */
294 EXTERN void VTThrd_delete(VTThrd* thrd, uint32_t tid);
295
296 /**
297 * Destroy thread object.
298 *
299 * @param thrd thread object
300 * @param tid thread ID
301 */
302 EXTERN void VTThrd_destroy(VTThrd* thrd, uint32_t tid);
303
304 /**
305 * Open associated trace file.
306 *
307 * @param tid thread ID
308 */
309 EXTERN void VTThrd_open(uint32_t tid);
310
311 /**
312 * Close associated trace file.
313 *
314 * @param thrd pointer to the thread structure
315 */
316 EXTERN void VTThrd_close(VTThrd* thrd);
317
318 #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA))
319
320 /* macros for (un)locking predefined mutexes */
321 #define VTTHRD_LOCK_ENV() VTThrd_lock(&VTThrdMutexEnv)
322 #define VTTHRD_UNLOCK_ENV() VTThrd_unlock(&VTThrdMutexEnv)
323 #define VTTHRD_LOCK_IDS() VTThrd_lock(&VTThrdMutexIds)
324 #define VTTHRD_UNLOCK_IDS() VTThrd_unlock(&VTThrdMutexIds)
325
326 typedef struct VTThrdMutex_struct VTThrdMutex;
327
328 #if !defined(VT_JAVA)
329 # if defined(VT_THRD_PTHREAD)
330 EXTERN void VTThrd_initPthread(void);
331 # elif defined(VT_THRD_OMP)
332 EXTERN void VTThrd_initOmp(void);
333 # endif /* VT_THRD_[PTHREAD|OMP] */
334 EXTERN void VTThrd_registerThread( uint32_t ptid );
335 #else /* VT_JAVA */
336 EXTERN void VTThrd_initJava(void);
337 EXTERN void VTThrd_registerThread(jthread thread, const char* tname);
338 #endif /* VT_JAVA */
339
340 /**
341 * Check whether current thread is alive.
342 *
343 * @return 1 if alive, otherwise 0
344 */
345 EXTERN uint8_t VTThrd_isAlive(void);
346
347 /**
348 * Get ID of current thread.
349 *
350 * @return thread ID
351 */
352 EXTERN uint32_t VTThrd_getThreadId(void);
353
354 /**
355 * Create a mutex for locking (*mutex must be NULL).
356 *
357 * @param mutex the generic VampirTrace thread mutex
358 */
359 EXTERN void VTThrd_createMutex(VTThrdMutex** mutex);
360
361 /**
362 * Delete a mutex for locking.
363 *
364 * @param mutex the generic VampirTrace thread mutex
365 */
366 EXTERN void VTThrd_deleteMutex(VTThrdMutex** mutex);
367
368 /**
369 * Lock a mutex (*mutex will be initialized, if NULL).
370 *
371 * @param mutex the generic VampirTrace thread mutex
372 */
373 EXTERN void VTThrd_lock(VTThrdMutex** mutex);
374
375 /**
376 * Unlock a mutex.
377 *
378 * @param mutex the generic VampirTrace thread mutex
379 */
380 EXTERN void VTThrd_unlock(VTThrdMutex** mutex);
381
382 /* predefined mutexes for locking ... */
383 EXTERN VTThrdMutex* VTThrdMutexEnv; /* ... VT Thread environment */
384 EXTERN VTThrdMutex* VTThrdMutexIds; /* ... VT IDs */
385
386 #endif /* VT_MT || VT_HYB || VT_JAVA */
387
388 /** vector of the thread objects */
389 EXTERN VTThrd** VTThrdv;
390
391 /** number of thread objects */
392 EXTERN uint32_t VTThrdn;
393
394 #endif /* _VT_THRD_H */
VTThrd::stack_level_at_rewind_mark
int stack_level_at_rewind_mark
call stack level at rewind mark
Definition: vt_thrd.h:74
VTThrd
VTThrd struct holds all thread-specific data:
Definition: vt_thrd.h:65
RFG_Regions_struct
Definition: rfg_regions.c:37
VTThrd::trace_status
int8_t trace_status
trace status: VT_TRACE_ON, VT_TRACE_OFF, or VT_TRACE_OFF_PERMANENT
Definition: vt_thrd.h:76
VTThrd::child_num
uint32_t child_num
number of child threads
Definition: vt_thrd.h:82
VTThrdMutex_struct
VampirTrace http://www.tu-dresden.de/zih/vampirtrace.
Definition: vt_thrd_java.c:23
vt_rusage
Definition: vt_rusage.c:89
VTThrd::gen
VTGen * gen
trace file and buffer
Definition: vt_thrd.h:67
VTThrd::rfg_regions
RFG_Regions * rfg_regions
RFG regions object.
Definition: vt_thrd.h:88
VTThrd::stack_level_at_off
int stack_level_at_off
call stack level at trace off
Definition: vt_thrd.h:73
vt_metv
Definition: vt_metric_cpc.c:36
VTThrd::is_virtual
uint8_t is_virtual
flag: is virtual thread? (e.g.
Definition: vt_thrd.h:84
VTThrd::parent_tid
uint32_t parent_tid
parent thread id
Definition: vt_thrd.h:81
VTThrd::stack_level
int stack_level
current call stack level
Definition: vt_thrd.h:72
VTGen_struct
Definition: vt_otf_gen.c:90