forked from jmrosinski/GPTL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
f_wrappers.c
487 lines (409 loc) · 11.7 KB
/
f_wrappers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/*
** f_wrappers.c
**
** Author: Jim Rosinski
**
** Fortran wrappers for timing library routines
*/
#ifdef HAVE_MPI
#include <mpi.h>
#endif
#include <string.h>
#include <stdlib.h>
#include "private.h" /* MAX_CHARS, bool */
#include "gptl.h" /* function prototypes */
#if ( defined FORTRANUNDERSCORE )
#define gptlinitialize gptlinitialize_
#define gptlfinalize gptlfinalize_
#define gptlpr gptlpr_
#define gptlpr_file gptlpr_file_
#define gptlpr_summary gptlpr_summary_
#define gptlpr_summary_file gptlpr_summary_file_
#define gptlbarrier gptlbarrier_
#define gptlreset gptlreset_
#define gptlstamp gptlstamp_
#define gptlstart gptlstart_
#define gptlinit_handle gptlinit_handle_
#define gptlstart_handle gptlstart_handle_
#define gptlstop gptlstop_
#define gptlstop_handle gptlstop_handle_
#define gptlsetoption gptlsetoption_
#define gptlenable gptlenable_
#define gptldisable gptldisable_
#define gptlsetutr gptlsetutr_
#define gptlquery gptlquery_
#define gptlquerycounters gptlquerycounters_
#define gptlget_wallclock gptlget_wallclock_
#define gptlget_eventvalue gptlget_eventvalue_
#define gptlget_nregions gptlget_nregions_
#define gptlget_regionname gptlget_regionname_
#define gptlget_memusage gptlget_memusage_
#define gptlprint_memusage gptlprint_memusage_
#define gptlprint_rusage gptlprint_rusage_
#define gptlnum_errors gptlnum_errors_
#define gptlnum_warn gptlnum_warn_
#define gptlget_count gptlget_count_
#define gptl_papilibraryinit gptl_papilibraryinit_
#define gptlevent_name_to_code gptlevent_name_to_code_
#define gptlevent_code_to_name gptlevent_code_to_name_
#elif ( defined FORTRANDOUBLEUNDERSCORE )
#define gptlinitialize gptlinitialize_
#define gptlfinalize gptlfinalize_
#define gptlpr gptlpr_
#define gptlpr_file gptlpr_file__
#define gptlpr_summary gptlpr_summary__
#define gptlpr_summary_file gptlpr_summary_file__
#define gptlbarrier gptlbarrier_
#define gptlreset gptlreset_
#define gptlstamp gptlstamp_
#define gptlstart gptlstart_
#define gptlinit_handle gptlinit_handle__
#define gptlstart_handle gptlstart_handle__
#define gptlstop gptlstop_
#define gptlstop_handle gptlstop_handle__
#define gptlsetoption gptlsetoption_
#define gptlenable gptlenable_
#define gptldisable gptldisable_
#define gptlsetutr gptlsetutr_
#define gptlquery gptlquery_
#define gptlquerycounters gptlquerycounters_
#define gptlget_wallclock gptlget_wallclock__
#define gptlget_eventvalue gptlget_eventvalue__
#define gptlget_nregions gptlget_nregions__
#define gptlget_regionname gptlget_regionname__
#define gptlget_memusage gptlget_memusage__
#define gptlprint_memusage gptlprint_memusage__
#define gptlprint_rusage gptlprint_rusage__
#define gptlnum_errors gptlnum_errors__
#define gptlnum_warn gptlnum_warn__
#define gptlget_count gptlget_count__
#define gptl_papilibraryinit gptl_papilibraryinit__
#define gptlevent_name_to_code gptlevent_name_to_code__
#define gptlevent_code_to_name gptlevent_code_to_name__
#endif
/* Local function prototypes */
int gptlinitialize (void);
int gptlfinalize (void);
int gptlpr (int *procid);
int gptlpr_file (char *file, int nc1);
#ifdef HAVE_MPI
int gptlpr_summary (int *fcomm);
int gptlpr_summary_file (int *fcomm, char *name, int nc1);
int gptlbarrier (int *fcomm, char *name, int nc1);
#else
int gptlpr_summary (void);
int gptlpr_summary_file (char *name, int nc1);
int gptlbarrier (void);
#endif
int gptlreset (void);
int gptlstamp (double *wall, double *usr, double *sys);
int gptlstart (char *name, int nc1);
int gptlinit_handle (char *name, int *, int nc1);
int gptlstart_handle (char *name, int *, int nc1);
int gptlstop (char *name, int nc1);
int gptlstop_handle (char *name, int *, int nc1);
int gptlsetoption (int *option, int *val);
int gptlenable (void);
int gptldisable (void);
int gptlsetutr (int *option);
int gptlquery (const char *name, int *t, int *count, int *onflg, double *wallclock,
double *usr, double *sys, long long *papicounters_out, int *maxcounters,
int nc);
int gptlquerycounters (const char *name, int *t, long long *papicounters_out, int nc);
int gptlget_wallclock (const char *name, int *t, double *value, int nc);
int gptlget_eventvalue (const char *timername, const char *eventname, int *t, double *value,
int nc1, int nc2);
int gptlget_nregions (int *t, int *nregions);
int gptlget_regionname (int *t, int *region, char *name, int nc);
int gptlget_memusage (int *size, int *rss, int *share, int *text, int *datastack);
int gptlprint_memusage (const char *str, int nc);
int gptlprint_rusage (const char *str, int nc);
int gptlnum_errors (void);
int gptlnum_warn (void);
int gptlget_count (char *, int *, int *, int);
#ifdef HAVE_PAPI
int gptl_papilibraryinit (void);
int gptlevent_name_to_code (const char *str, int *code, int nc);
int gptlevent_code_to_name (int *code, char *str, int nc);
#endif
/* Fortran wrapper functions start here */
int gptlinitialize (void)
{
return GPTLinitialize ();
}
int gptlfinalize (void)
{
return GPTLfinalize ();
}
int gptlpr (int *procid)
{
return GPTLpr (*procid);
}
int gptlpr_file (char *file, int nc1)
{
char *locfile;
int ret;
if ( ! (locfile = (char *) malloc (nc1+1)))
return GPTLerror ("gptlpr_file: malloc error\n");
snprintf (locfile, nc1+1, "%s", file);
ret = GPTLpr_file (locfile);
free (locfile);
return ret;
}
#ifdef HAVE_MPI
int gptlpr_summary (int *fcomm)
{
MPI_Comm ccomm;
#ifdef HAVE_COMM_F2C
ccomm = MPI_Comm_f2c (*fcomm);
#else
/* Punt and try just casting the Fortran communicator */
ccomm = (MPI_Comm) *fcomm;
#endif
return GPTLpr_summary (ccomm);
}
int gptlpr_summary_file (int *fcomm, char *outfile, int nc1)
{
MPI_Comm ccomm;
char cname[MAX_CHARS+1];
int numchars;
numchars = MIN (nc1, MAX_CHARS);
strncpy (cname, outfile, numchars);
cname[numchars] = '\0';
#ifdef HAVE_COMM_F2C
ccomm = MPI_Comm_f2c (*fcomm);
#else
/* Punt and try just casting the Fortran communicator */
ccomm = (MPI_Comm) *fcomm;
#endif
return GPTLpr_summary_file (ccomm, cname);
}
int gptlbarrier (int *fcomm, char *name, int nc1)
{
MPI_Comm ccomm;
char cname[MAX_CHARS+1];
int numchars;
numchars = MIN (nc1, MAX_CHARS);
strncpy (cname, name, numchars);
cname[numchars] = '\0';
#ifdef HAVE_COMM_F2C
ccomm = MPI_Comm_f2c (*fcomm);
#else
/* Punt and try just casting the Fortran communicator */
ccomm = (MPI_Comm) *fcomm;
#endif
return GPTLbarrier (ccomm, cname);
}
#else
int gptlpr_summary (void)
{
return GPTLpr_summary ();
}
int gptlpr_summary_file (char *outfile, int nc1)
{
char cname[MAX_CHARS+1];
int numchars;
numchars = MIN (nc1, MAX_CHARS);
strncpy (cname, outfile, numchars);
cname[numchars] = '\0';
return GPTLpr_summary_file (cname);
}
int gptlbarrier (void)
{
return GPTLerror ("gptlbarrier: Need to build GPTL with #define HAVE_MPI to enable this routine\n");
}
#endif
int gptlreset (void)
{
return GPTLreset ();
}
int gptlstamp (double *wall, double *usr, double *sys)
{
return GPTLstamp (wall, usr, sys);
}
int gptlstart (char *name, int nc1)
{
char cname[MAX_CHARS+1];
int numchars;
numchars = MIN (nc1, MAX_CHARS);
strncpy (cname, name, numchars);
cname[numchars] = '\0';
return GPTLstart (cname);
}
int gptlinit_handle (char *name, int *handle, int nc1)
{
char cname[MAX_CHARS+1];
int numchars;
numchars = MIN (nc1, MAX_CHARS);
strncpy (cname, name, numchars);
cname[numchars] = '\0';
return GPTLinit_handle (cname, handle);
}
int gptlstart_handle (char *name, int *handle, int nc1)
{
char cname[MAX_CHARS+1];
int numchars;
numchars = MIN (nc1, MAX_CHARS);
strncpy (cname, name, numchars);
cname[numchars] = '\0';
return GPTLstart_handle (cname, handle);
}
int gptlstop (char *name, int nc1)
{
char cname[MAX_CHARS+1];
int numchars;
numchars = MIN (nc1, MAX_CHARS);
strncpy (cname, name, numchars);
cname[numchars] = '\0';
return GPTLstop (cname);
}
int gptlstop_handle (char *name, int *handle, int nc1)
{
char cname[MAX_CHARS+1];
int numchars;
numchars = MIN (nc1, MAX_CHARS);
strncpy (cname, name, numchars);
cname[numchars] = '\0';
return GPTLstop_handle (cname, handle);
}
int gptlsetoption (int *option, int *val)
{
return GPTLsetoption (*option, *val);
}
int gptlenable (void)
{
return GPTLenable ();
}
int gptldisable (void)
{
return GPTLdisable ();
}
int gptlsetutr (int *option)
{
return GPTLsetutr (*option);
}
int gptlquery (const char *name, int *t, int *count, int *onflg, double *wallclock,
double *usr, double *sys, long long *papicounters_out, int *maxcounters,
int nc)
{
char cname[MAX_CHARS+1];
int numchars;
numchars = MIN (nc, MAX_CHARS);
strncpy (cname, name, numchars);
cname[numchars] = '\0';
return GPTLquery (cname, *t, count, onflg, wallclock, usr, sys, papicounters_out, *maxcounters);
}
int gptlquerycounters (const char *name, int *t, long long *papicounters_out, int nc)
{
char cname[MAX_CHARS+1];
int numchars;
numchars = MIN (nc, MAX_CHARS);
strncpy (cname, name, numchars);
cname[numchars] = '\0';
return GPTLquerycounters (cname, *t, papicounters_out);
}
int gptlget_wallclock (const char *name, int *t, double *value, int nc)
{
char cname[MAX_CHARS+1];
int numchars;
numchars = MIN (nc, MAX_CHARS);
strncpy (cname, name, numchars);
cname[numchars] = '\0';
return GPTLget_wallclock (cname, *t, value);
}
int gptlget_eventvalue (const char *timername, const char *eventname, int *t, double *value,
int nc1, int nc2)
{
char ctimername[MAX_CHARS+1];
char ceventname[MAX_CHARS+1];
int numchars;
numchars = MIN (nc1, MAX_CHARS);
strncpy (ctimername, timername, numchars);
ctimername[numchars] = '\0';
numchars = MIN (nc2, MAX_CHARS);
strncpy (ceventname, eventname, numchars);
ceventname[numchars] = '\0';
return GPTLget_eventvalue (ctimername, ceventname, *t, value);
}
int gptlget_nregions (int *t, int *nregions)
{
return GPTLget_nregions (*t, nregions);
}
int gptlget_regionname (int *t, int *region, char *name, int nc)
{
int n;
int ret;
ret = GPTLget_regionname (*t, *region, name, nc);
/* Turn nulls into spaces for fortran */
for (n = 0; n < nc; ++n)
if (name[n] == '\0')
name[n] = ' ';
return ret;
}
int gptlget_memusage (int *size, int *rss, int *share, int *text, int *datastack)
{
return GPTLget_memusage (size, rss, share, text, datastack);
}
int gptlprint_memusage (const char *str, int nc)
{
char cname[128+1];
int numchars = MIN (nc, 128);
strncpy (cname, str, numchars);
cname[numchars] = '\0';
return GPTLprint_memusage (cname);
}
int gptlprint_rusage (const char *str, int nc)
{
char cname[128+1];
int numchars = MIN (nc, 128);
strncpy (cname, str, numchars);
cname[numchars] = '\0';
return GPTLprint_rusage (cname);
}
int gptlnum_errors (void)
{
return GPTLnum_errors ();
}
int gptlnum_warn (void)
{
return GPTLnum_warn ();
}
int gptlget_count (char *name, int *t, int *count, int nc)
{
char cname[MAX_CHARS+1];
int numchars;
numchars = MIN (nc, MAX_CHARS);
strncpy (cname, name, numchars);
cname[numchars] = '\0';
return GPTLget_count (cname, *t, count);
}
#ifdef HAVE_PAPI
#include <papi.h>
int gptl_papilibraryinit (void)
{
return GPTL_PAPIlibraryinit ();;
}
int gptlevent_name_to_code (const char *str, int *code, int nc)
{
char cname[PAPI_MAX_STR_LEN+1];
int numchars = MIN (nc, PAPI_MAX_STR_LEN);
strncpy (cname, str, numchars);
cname[numchars] = '\0';
/* "code" is an int* and is an output variable */
return GPTLevent_name_to_code (cname, code);
}
int gptlevent_code_to_name (int *code, char *str, int nc)
{
int i;
if (nc < PAPI_MAX_STR_LEN)
return GPTLerror ("gptl_event_code_to_name: output name must hold at least %d characters\n",
PAPI_MAX_STR_LEN);
if (GPTLevent_code_to_name (*code, str) == 0) {
for (i = strlen(str); i < nc; ++i)
str[i] = ' ';
} else {
return GPTLerror ("");
}
return 0;
}
#endif