~ubuntu-branches/ubuntu/vivid/mpich/vivid-proposed

« back to all changes in this revision

Viewing changes to test/mpi/mpi_t/mpit_vars.c

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2014-04-01 20:24:20 UTC
  • mfrom: (5.2.4 sid)
  • Revision ID: package-import@ubuntu.com-20140401202420-t5ey1ia2klt5dkq3
Tags: 3.1-4
* [c3e3398] Disable test_primitives, which is unreliable on some platforms.
            (Closes: #743047)
* [265a699] Add minimal autotest.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
 
2
/*
 
3
 *  (C) 2013 by Argonne National Laboratory.
 
4
 *      See COPYRIGHT in top-level directory.
 
5
 */
 
6
 
 
7
/* To print out all MPI_T control variables, performance variables and their
 
8
   categories in the MPI implementation. But whether they function well as
 
9
   expected, is not tested.
 
10
 */
 
11
 
 
12
#include <stdio.h>
 
13
#include <strings.h>
 
14
#include <string.h>     /* For strncpy */
 
15
#include <stdlib.h>
 
16
#include "mpi.h"
 
17
 
 
18
char *mpit_scopeToStr(int scope);
 
19
char *mpit_bindingToStr(int binding);
 
20
char *mpit_validDtypeStr(MPI_Datatype datatype);
 
21
char *mpit_varclassToStr(int varClass);
 
22
char *mpit_verbosityToStr(int verbosity);
 
23
int perfvarReadInt(int pvarIndex, int isContinuous, int *found);
 
24
unsigned int perfvarReadUint(int pvarIndex, int isContinuous, int *found);
 
25
double perfvarReadDouble(int pvarIndex, int isContinuous, int *found);
 
26
int PrintControlVars(FILE * fp);
 
27
int PrintPerfVars(FILE * fp);
 
28
int PrintCategories(FILE * fp);
 
29
 
 
30
static int verbose = 0;
 
31
 
 
32
int main(int argc, char *argv[])
 
33
{
 
34
    int required, provided;
 
35
    required = MPI_THREAD_SINGLE;
 
36
 
 
37
    MPI_T_init_thread(required, &provided);
 
38
    MPI_Init_thread(&argc, &argv, required, &provided);
 
39
 
 
40
    if (getenv("MPITEST_VERBOSE"))
 
41
        verbose = 1;
 
42
 
 
43
    PrintControlVars(stdout);
 
44
    if (verbose)
 
45
        fprintf(stdout, "\n");
 
46
 
 
47
    PrintPerfVars(stdout);
 
48
    if (verbose)
 
49
        fprintf(stdout, "\n");
 
50
 
 
51
    PrintCategories(stdout);
 
52
 
 
53
    /* Put MPI_T_finalize() after MPI_Finalize() will cause mpich memory
 
54
     * tracing facility falsely reports memory leaks, though these memories
 
55
     * are freed in MPI_T_finalize().
 
56
     */
 
57
    MPI_T_finalize();
 
58
    MPI_Finalize();
 
59
 
 
60
    fprintf(stdout, " No Errors\n");
 
61
 
 
62
    return 0;
 
63
}
 
64
 
 
65
int PrintControlVars(FILE * fp)
 
66
{
 
67
    int i, num_cvar, nameLen, verbosity, descLen, binding, scope;
 
68
    int ival, hasValue;
 
69
    char name[128], desc[1024];
 
70
    MPI_T_enum enumtype = MPI_T_ENUM_NULL;
 
71
    MPI_Datatype datatype;
 
72
 
 
73
    MPI_T_cvar_get_num(&num_cvar);
 
74
    if (verbose)
 
75
        fprintf(fp, "%d MPI Control Variables\n", num_cvar);
 
76
    for (i = 0; i < num_cvar; i++) {
 
77
        hasValue = 0;
 
78
        nameLen = sizeof(name);
 
79
        descLen = sizeof(desc);
 
80
        MPI_T_cvar_get_info(i, name, &nameLen, &verbosity, &datatype,
 
81
                            &enumtype, desc, &descLen, &binding, &scope);
 
82
        if (datatype == MPI_INT && enumtype != MPI_T_ENUM_NULL) {
 
83
            int enameLen, enumber;
 
84
            char ename[128];
 
85
            enameLen = sizeof(ename);
 
86
            /* TODO: Extract a useful string to show for an enum */
 
87
            MPI_T_enum_get_info(enumtype, &enumber, ename, &enameLen);
 
88
        }
 
89
        if (datatype == MPI_INT && binding == MPI_T_BIND_NO_OBJECT) {
 
90
            int count;
 
91
            MPI_T_cvar_handle chandle;
 
92
            MPI_T_cvar_handle_alloc(i, NULL, &chandle, &count);
 
93
            if (count == 1) {
 
94
                MPI_T_cvar_read(chandle, &ival);
 
95
                hasValue = 1;
 
96
            }
 
97
            MPI_T_cvar_handle_free(&chandle);
 
98
        }
 
99
 
 
100
        if (hasValue && verbose) {
 
101
            fprintf(fp, "\t%s=%d\t%s\t%s\t%s\t%s\t%s\n",
 
102
                    name,
 
103
                    ival,
 
104
                    mpit_scopeToStr(scope),
 
105
                    mpit_bindingToStr(binding),
 
106
                    mpit_validDtypeStr(datatype), mpit_verbosityToStr(verbosity), desc);
 
107
        }
 
108
        else if (verbose) {
 
109
            fprintf(fp, "\t%s\t%s\t%s\t%s\t%s\t%s\n",
 
110
                    name,
 
111
                    mpit_scopeToStr(scope),
 
112
                    mpit_bindingToStr(binding),
 
113
                    mpit_validDtypeStr(datatype), mpit_verbosityToStr(verbosity), desc);
 
114
        }
 
115
    }
 
116
 
 
117
    return 0;
 
118
}
 
119
 
 
120
int PrintPerfVars(FILE * fp)
 
121
{
 
122
    int i, numPvar, nameLen, descLen, verbosity, varClass;
 
123
    int binding, isReadonly, isContinuous, isAtomic;
 
124
    char name[128], desc[1024];
 
125
    MPI_T_enum enumtype;
 
126
    MPI_Datatype datatype;
 
127
 
 
128
    MPI_T_pvar_get_num(&numPvar);
 
129
    if (verbose)
 
130
        fprintf(fp, "%d MPI Performance Variables\n", numPvar);
 
131
 
 
132
    for (i = 0; i < numPvar; i++) {
 
133
        nameLen = sizeof(name);
 
134
        descLen = sizeof(desc);
 
135
        MPI_T_pvar_get_info(i, name, &nameLen, &verbosity, &varClass,
 
136
                            &datatype, &enumtype, desc, &descLen, &binding,
 
137
                            &isReadonly, &isContinuous, &isAtomic);
 
138
 
 
139
        if (verbose)
 
140
            fprintf(fp, "\t%s\t%s\t%s\t%s\t%s\tReadonly=%s\tContinuous=%s\tAtomic=%s\t%s\n",
 
141
                    name,
 
142
                    mpit_varclassToStr(varClass),
 
143
                    mpit_bindingToStr(binding),
 
144
                    mpit_validDtypeStr(datatype),
 
145
                    mpit_verbosityToStr(verbosity),
 
146
                    isReadonly ? "T" : "F", isContinuous ? "T" : "F", isAtomic ? "T" : "F", desc);
 
147
 
 
148
        if (datatype == MPI_INT) {
 
149
            int val, isFound;
 
150
            val = perfvarReadInt(i, isContinuous, &isFound);
 
151
            if (isFound && verbose)
 
152
                fprintf(fp, "\tValue = %d\n", val);
 
153
        }
 
154
        else if (datatype == MPI_UNSIGNED) {
 
155
            int isFound;
 
156
            unsigned int val;
 
157
            val = perfvarReadUint(i, isContinuous, &isFound);
 
158
            if (isFound && verbose)
 
159
                fprintf(fp, "\tValue = %u\n", val);
 
160
        }
 
161
        else if (datatype == MPI_DOUBLE) {
 
162
            int isFound;
 
163
            double val;
 
164
            val = perfvarReadDouble(i, isContinuous, &isFound);
 
165
            if (isFound && verbose)
 
166
                fprintf(fp, "\tValue = %e\n", val);
 
167
        }
 
168
    }
 
169
    return 0;
 
170
}
 
171
 
 
172
int PrintCategories(FILE * fp)
 
173
{
 
174
    int i, j, numCat, nameLen, descLen, numCvars, numPvars, numSubcat;
 
175
    char name[128], desc[1024];
 
176
 
 
177
    MPI_T_category_get_num(&numCat);
 
178
    if (verbose) {
 
179
        if (numCat > 0)
 
180
            fprintf(fp, "%d MPI_T categories\n", numCat);
 
181
        else
 
182
            fprintf(fp, "No categories defined\n");
 
183
    }
 
184
 
 
185
    for (i = 0; i < numCat; i++) {
 
186
        nameLen = sizeof(name);
 
187
        descLen = sizeof(desc);
 
188
        MPI_T_category_get_info(i, name, &nameLen, desc, &descLen, &numCvars,
 
189
                                &numPvars, &numSubcat);
 
190
        if (verbose) {
 
191
            fprintf(fp, "Category %s has %d control variables, %d performance variables, %d subcategories\n",
 
192
                    name, numCvars, numPvars, numSubcat);
 
193
            fprintf(fp, "\tDescription: %s\n", desc);
 
194
        }
 
195
 
 
196
        if (numCvars > 0) {
 
197
            if (verbose)
 
198
                fprintf(fp, "\tControl variables include: ");
 
199
            int *cvarIndex = (int *) malloc(numCvars * sizeof(int));
 
200
            MPI_T_category_get_cvars(i, numCvars, cvarIndex);
 
201
            for (j = 0; j < numCvars; j++) {
 
202
                /* Get just the variable name */
 
203
                int varnameLen, verb, binding, scope;
 
204
                MPI_Datatype datatype;
 
205
                char varname[128];
 
206
                varnameLen = sizeof(varname);
 
207
                MPI_T_cvar_get_info(cvarIndex[j], varname, &varnameLen,
 
208
                                    &verb, &datatype, NULL, NULL, NULL, &binding, &scope);
 
209
                if (verbose)
 
210
                    fprintf(fp, "%s, ", varname);
 
211
            }
 
212
            free(cvarIndex);
 
213
            if (verbose)
 
214
                fprintf(fp, "\n");
 
215
        }
 
216
 
 
217
        if (numPvars > 0) {
 
218
            if (verbose)
 
219
                fprintf(fp, "\tPerformance variables include: ");
 
220
 
 
221
            int *pvarIndex = (int *) malloc(numPvars * sizeof(int));
 
222
            MPI_T_category_get_pvars(i, numPvars, pvarIndex);
 
223
            for (j = 0; j < numPvars; j++) {
 
224
                int varnameLen, verb, varclass, binding;
 
225
                int isReadonly, isContinuous, isAtomic;
 
226
                MPI_Datatype datatype;
 
227
                char varname[128];
 
228
                varnameLen = sizeof(varname);
 
229
                MPI_T_pvar_get_info(pvarIndex[j], varname, &varnameLen, &verb,
 
230
                                    &varclass, &datatype, NULL, NULL, NULL, &binding,
 
231
                                    &isReadonly, &isContinuous, &isAtomic);
 
232
                if (verbose)
 
233
                    fprintf(fp, "%s, ", varname);
 
234
 
 
235
            }
 
236
            free(pvarIndex);
 
237
            if (verbose)
 
238
                fprintf(fp, "\n");
 
239
        }
 
240
 
 
241
        /* TODO: Make it possible to recursively print category information */
 
242
        if (numSubcat > 0) {
 
243
            if (verbose)
 
244
                fprintf(fp, "\tSubcategories include: ");
 
245
 
 
246
            int *subcatIndex = (int *) malloc(numSubcat * sizeof(int));
 
247
            MPI_T_category_get_categories(i, numSubcat, subcatIndex);
 
248
            for (j = 0; j < numSubcat; j++) {
 
249
                int catnameLen, ncvars, npvars, nsubcats;
 
250
                char catname[128];
 
251
                catnameLen = sizeof(catname);
 
252
                MPI_T_category_get_info(subcatIndex[j], catname, &catnameLen, NULL, NULL,
 
253
                                        &ncvars, &npvars, &nsubcats);
 
254
                if (verbose)
 
255
                    fprintf(fp, "%s, ", catname);
 
256
 
 
257
            }
 
258
            free(subcatIndex);
 
259
            if (verbose)
 
260
                fprintf(fp, "\n");
 
261
        }
 
262
    }
 
263
 
 
264
    return 0;
 
265
}
 
266
 
 
267
 
 
268
/* --- Support routines --- */
 
269
 
 
270
char *mpit_validDtypeStr(MPI_Datatype datatype)
 
271
{
 
272
    char *p = 0;
 
273
    if (datatype == MPI_INT)
 
274
        p = "MPI_INT";
 
275
    else if (datatype == MPI_UNSIGNED)
 
276
        p = "MPI_UNSIGNED";
 
277
    else if (datatype == MPI_UNSIGNED_LONG)
 
278
        p = "MPI_UNSIGNED_LONG";
 
279
    else if (datatype == MPI_UNSIGNED_LONG_LONG)
 
280
        p = "MPI_UNSIGNED_LONG_LONG";
 
281
    else if (datatype == MPI_COUNT)
 
282
        p = "MPI_COUNT";
 
283
    else if (datatype == MPI_CHAR)
 
284
        p = "MPI_CHAR";
 
285
    else if (datatype == MPI_DOUBLE)
 
286
        p = "MPI_DOUBLE";
 
287
    else {
 
288
        if (datatype == MPI_DATATYPE_NULL) {
 
289
            p = "Invalid MPI datatype:NULL";
 
290
        }
 
291
        else {
 
292
            static char typename[MPI_MAX_OBJECT_NAME + 9];
 
293
            int tlen;
 
294
            strncpy(typename, "Invalid:", MPI_MAX_OBJECT_NAME);
 
295
            MPI_Type_get_name(datatype, typename + 8, &tlen);
 
296
            /* We must check location typename[8] to see if
 
297
               MPI_Type_get_name returned a name (not all datatypes
 
298
               have names).  If it did not, then we indicate that
 
299
               with a different message */
 
300
            if (typename[8])
 
301
                p = typename;
 
302
            else
 
303
                p = "Invalid: Unknown datatype name";
 
304
        }
 
305
    }
 
306
 
 
307
    return p;
 
308
}
 
309
 
 
310
char *mpit_scopeToStr(int scope)
 
311
{
 
312
    char *p = 0;
 
313
    switch (scope) {
 
314
    case MPI_T_SCOPE_CONSTANT:
 
315
        p = "SCOPE_CONSTANT";
 
316
        break;
 
317
    case MPI_T_SCOPE_READONLY:
 
318
        p = "SCOPE_READONLY";
 
319
        break;
 
320
    case MPI_T_SCOPE_LOCAL:
 
321
        p = "SCOPE_LOCAL";
 
322
        break;
 
323
    case MPI_T_SCOPE_GROUP:
 
324
        p = "SCOPE_GROUP";
 
325
        break;
 
326
    case MPI_T_SCOPE_GROUP_EQ:
 
327
        p = "SCOPE_GROUP_EQ";
 
328
        break;
 
329
    case MPI_T_SCOPE_ALL:
 
330
        p = "SCOPE_ALL";
 
331
        break;
 
332
    case MPI_T_SCOPE_ALL_EQ:
 
333
        p = "SCOPE_ALL_EQ";
 
334
        break;
 
335
    default:
 
336
        p = "Unrecoginized scope";
 
337
        break;
 
338
    }
 
339
    return p;
 
340
}
 
341
 
 
342
char *mpit_bindingToStr(int binding)
 
343
{
 
344
    char *p;
 
345
    switch (binding) {
 
346
    case MPI_T_BIND_NO_OBJECT:
 
347
        p = "NO_OBJECT";
 
348
        break;
 
349
    case MPI_T_BIND_MPI_COMM:
 
350
        p = "MPI_COMM";
 
351
        break;
 
352
    case MPI_T_BIND_MPI_DATATYPE:
 
353
        p = "MPI_DATATYPE";
 
354
        break;
 
355
    case MPI_T_BIND_MPI_ERRHANDLER:
 
356
        p = "MPI_ERRHANDLER";
 
357
        break;
 
358
    case MPI_T_BIND_MPI_FILE:
 
359
        p = "MPI_FILE";
 
360
        break;
 
361
    case MPI_T_BIND_MPI_GROUP:
 
362
        p = "MPI_GROUP";
 
363
        break;
 
364
    case MPI_T_BIND_MPI_OP:
 
365
        p = "MPI_OP";
 
366
        break;
 
367
    case MPI_T_BIND_MPI_REQUEST:
 
368
        p = "MPI_REQUEST";
 
369
        break;
 
370
    case MPI_T_BIND_MPI_WIN:
 
371
        p = "MPI_WIN";
 
372
        break;
 
373
    case MPI_T_BIND_MPI_MESSAGE:
 
374
        p = "MPI_MESSAGE";
 
375
        break;
 
376
    case MPI_T_BIND_MPI_INFO:
 
377
        p = "MPI_INFO";
 
378
        break;
 
379
    default:
 
380
        p = "Unknown object binding";
 
381
    }
 
382
    return p;
 
383
}
 
384
 
 
385
char *mpit_varclassToStr(int varClass)
 
386
{
 
387
    char *p = 0;
 
388
    switch (varClass) {
 
389
    case MPI_T_PVAR_CLASS_STATE:
 
390
        p = "CLASS_STATE";
 
391
        break;
 
392
    case MPI_T_PVAR_CLASS_LEVEL:
 
393
        p = "CLASS_LEVEL";
 
394
        break;
 
395
    case MPI_T_PVAR_CLASS_SIZE:
 
396
        p = "CLASS_SIZE";
 
397
        break;
 
398
    case MPI_T_PVAR_CLASS_PERCENTAGE:
 
399
        p = "CLASS_PERCENTAGE";
 
400
        break;
 
401
    case MPI_T_PVAR_CLASS_HIGHWATERMARK:
 
402
        p = "CLASS_HIGHWATERMARK";
 
403
        break;
 
404
    case MPI_T_PVAR_CLASS_LOWWATERMARK:
 
405
        p = "CLASS_LOWWATERMARK";
 
406
        break;
 
407
    case MPI_T_PVAR_CLASS_COUNTER:
 
408
        p = "CLASS_COUNTER";
 
409
        break;
 
410
    case MPI_T_PVAR_CLASS_AGGREGATE:
 
411
        p = "CLASS_AGGREGATE";
 
412
        break;
 
413
    case MPI_T_PVAR_CLASS_TIMER:
 
414
        p = "CLASS_TIMER";
 
415
        break;
 
416
    case MPI_T_PVAR_CLASS_GENERIC:
 
417
        p = "CLASS_GENERIC";
 
418
        break;
 
419
    default:
 
420
        p = "Unrecognized pvar class";
 
421
        break;
 
422
    }
 
423
    return p;
 
424
}
 
425
 
 
426
char *mpit_verbosityToStr(int verbosity)
 
427
{
 
428
    char *p = 0;
 
429
    switch (verbosity) {
 
430
    case MPI_T_VERBOSITY_USER_BASIC:
 
431
        p = "VERBOSITY_USER_BASIC";
 
432
        break;
 
433
    case MPI_T_VERBOSITY_USER_DETAIL:
 
434
        p = "VERBOSITY_USER_DETAIL";
 
435
        break;
 
436
    case MPI_T_VERBOSITY_USER_ALL:
 
437
        p = "VERBOSITY_USER_ALL";
 
438
        break;
 
439
    case MPI_T_VERBOSITY_TUNER_BASIC:
 
440
        p = "VERBOSITY_TUNER_BASIC";
 
441
        break;
 
442
    case MPI_T_VERBOSITY_TUNER_DETAIL:
 
443
        p = "VERBOSITY_TUNER_DETAIL";
 
444
        break;
 
445
    case MPI_T_VERBOSITY_TUNER_ALL:
 
446
        p = "VERBOSITY_TUNER_ALL";
 
447
        break;
 
448
    case MPI_T_VERBOSITY_MPIDEV_BASIC:
 
449
        p = "VERBOSITY_MPIDEV_BASIC";
 
450
        break;
 
451
    case MPI_T_VERBOSITY_MPIDEV_DETAIL:
 
452
        p = "VERBOSITY_MPIDEV_DETAIL";
 
453
        break;
 
454
    case MPI_T_VERBOSITY_MPIDEV_ALL:
 
455
        p = "VERBOSITY_MPIDEV_ALL";
 
456
        break;
 
457
    default:
 
458
        p = "Invalid verbosity";
 
459
        break;
 
460
    }
 
461
    return p;
 
462
}
 
463
 
 
464
char *mpit_errclassToStr(int err)
 
465
{
 
466
    char *p = 0;
 
467
    switch (err) {
 
468
    case MPI_T_ERR_MEMORY:
 
469
        p = "ERR_MEMORY";
 
470
        break;
 
471
    case MPI_T_ERR_NOT_INITIALIZED:
 
472
        p = "ERR_NOT_INITIALIZED";
 
473
        break;
 
474
    case MPI_T_ERR_CANNOT_INIT:
 
475
        p = "ERR_CANNOT_INIT";
 
476
        break;
 
477
    case MPI_T_ERR_INVALID_INDEX:
 
478
        p = "ERR_INVALID_INDEX";
 
479
        break;
 
480
    case MPI_T_ERR_INVALID_ITEM:
 
481
        p = "ERR_INVALID_ITEM";
 
482
        break;
 
483
    case MPI_T_ERR_INVALID_HANDLE:
 
484
        p = "ERR_INVALID_HANDLE";
 
485
        break;
 
486
    case MPI_T_ERR_OUT_OF_HANDLES:
 
487
        p = "ERR_OUT_OF_HANDLES";
 
488
        break;
 
489
    case MPI_T_ERR_OUT_OF_SESSIONS:
 
490
        p = "ERR_OUT_OF_SESSIONS";
 
491
        break;
 
492
    case MPI_T_ERR_INVALID_SESSION:
 
493
        p = "ERR_INVALID_SESSION";
 
494
        break;
 
495
    case MPI_T_ERR_CVAR_SET_NOT_NOW:
 
496
        p = "ERR_CVAR_SET_NOT_NOW";
 
497
        break;
 
498
    case MPI_T_ERR_CVAR_SET_NEVER:
 
499
        p = "ERR_CVAR_SET_NEVER";
 
500
        break;
 
501
    case MPI_T_ERR_PVAR_NO_STARTSTOP:
 
502
        p = "ERR_PVAR_NO_STARTSTOP";
 
503
        break;
 
504
    case MPI_T_ERR_PVAR_NO_WRITE:
 
505
        p = "ERR_PVAR_NO_WRITE";
 
506
        break;
 
507
    case MPI_T_ERR_PVAR_NO_ATOMIC:
 
508
        p = "ERR_PVAR_NO_ATOMIC";
 
509
        break;
 
510
    default:
 
511
        p = "Unknown MPI_T_ERR class";
 
512
        break;
 
513
    }
 
514
    return p;
 
515
}
 
516
 
 
517
/* Return the value of the performance variable as the value */
 
518
int perfvarReadInt(int pvarIndex, int isContinuous, int *found)
 
519
{
 
520
    int count, val = -1;
 
521
    int err1 = MPI_SUCCESS;
 
522
    int err2 = MPI_SUCCESS;
 
523
    MPI_T_pvar_session session;
 
524
    MPI_T_pvar_handle pvarHandle;
 
525
    MPI_T_pvar_session_create(&session);
 
526
    MPI_T_pvar_handle_alloc(session, pvarIndex, NULL, &pvarHandle, &count);
 
527
    MPI_T_pvar_start(session, MPI_T_PVAR_ALL_HANDLES);
 
528
    MPI_T_pvar_stop(session, MPI_T_PVAR_ALL_HANDLES);
 
529
    if (count == 1) {
 
530
        *found = 1;
 
531
        if (!isContinuous) {
 
532
            /* start and stop the variable (just because we can) */
 
533
            err1 = MPI_T_pvar_start(session, pvarHandle);
 
534
            err2 = MPI_T_pvar_stop(session, pvarHandle);
 
535
        }
 
536
        MPI_T_pvar_read(session, pvarHandle, &val);
 
537
    }
 
538
    MPI_T_pvar_handle_free(session, &pvarHandle);
 
539
    MPI_T_pvar_session_free(&session);
 
540
 
 
541
    /* Above codes imply that err1 and err2 should be MPI_SUCCESS.
 
542
     * If not, catch errors here, e.g., when MPI_ERR_INTERN is returned.
 
543
     */
 
544
    if (err1 != MPI_SUCCESS || err2 != MPI_SUCCESS) {
 
545
        fprintf(stderr, "Unexpected MPI_T_pvar_start/stop return code\n");
 
546
        abort();
 
547
    }
 
548
 
 
549
    return val;
 
550
}
 
551
 
 
552
/* Return the value of the performance variable as the value */
 
553
unsigned int perfvarReadUint(int pvarIndex, int isContinuous, int *found)
 
554
{
 
555
    int count;
 
556
    unsigned int val = 0;
 
557
    int err1 = MPI_SUCCESS;
 
558
    int err2 = MPI_SUCCESS;
 
559
    MPI_T_pvar_session session;
 
560
    MPI_T_pvar_handle pvarHandle;
 
561
 
 
562
    *found = 0;
 
563
    MPI_T_pvar_session_create(&session);
 
564
    MPI_T_pvar_handle_alloc(session, pvarIndex, NULL, &pvarHandle, &count);
 
565
    MPI_T_pvar_start(session, MPI_T_PVAR_ALL_HANDLES);
 
566
    MPI_T_pvar_stop(session, MPI_T_PVAR_ALL_HANDLES);
 
567
    if (count == 1) {
 
568
        *found = 1;
 
569
        if (!isContinuous) {
 
570
            /* start and stop the variable (just because we can) */
 
571
            err1 = MPI_T_pvar_start(session, pvarHandle);
 
572
            err2 = MPI_T_pvar_stop(session, pvarHandle);
 
573
        }
 
574
        MPI_T_pvar_read(session, pvarHandle, &val);
 
575
    }
 
576
    MPI_T_pvar_handle_free(session, &pvarHandle);
 
577
    MPI_T_pvar_session_free(&session);
 
578
 
 
579
    /* Above codes imply that err1 and err2 should be MPI_SUCCESS.
 
580
     * If not, catch errors here, e.g., when MPI_ERR_INTERN is returned.
 
581
     */
 
582
    if (err1 != MPI_SUCCESS || err2 != MPI_SUCCESS) {
 
583
        fprintf(stderr, "Unexpected MPI_T_pvar_start/stop return code\n");
 
584
        abort();
 
585
    }
 
586
 
 
587
    return val;
 
588
}
 
589
 
 
590
double perfvarReadDouble(int pvarIndex, int isContinuous, int *found)
 
591
{
 
592
    int count;
 
593
    double val = 0.0;
 
594
    int err1 = MPI_SUCCESS;
 
595
    int err2 = MPI_SUCCESS;
 
596
    MPI_T_pvar_session session;
 
597
    MPI_T_pvar_handle pvarHandle;
 
598
 
 
599
    *found = 0;
 
600
    MPI_T_pvar_session_create(&session);
 
601
    MPI_T_pvar_handle_alloc(session, pvarIndex, NULL, &pvarHandle, &count);
 
602
    MPI_T_pvar_start(session, MPI_T_PVAR_ALL_HANDLES);
 
603
    MPI_T_pvar_stop(session, MPI_T_PVAR_ALL_HANDLES);
 
604
    if (count == 1) {
 
605
        *found = 1;
 
606
        if (!isContinuous) {
 
607
            /* start and stop the variable (just because we can) */
 
608
            err1 = MPI_T_pvar_start(session, pvarHandle);
 
609
            err2 = MPI_T_pvar_stop(session, pvarHandle);
 
610
        }
 
611
        MPI_T_pvar_read(session, pvarHandle, &val);
 
612
    }
 
613
    MPI_T_pvar_handle_free(session, &pvarHandle);
 
614
    MPI_T_pvar_session_free(&session);
 
615
 
 
616
    /* Catch errors if MPI_T_pvar_start/stop are not properly implemented */
 
617
    if (err1 != MPI_SUCCESS || err2 != MPI_SUCCESS) {
 
618
        fprintf(stderr, "Unknown MPI_T return code when starting/stopping double pvar\n");
 
619
        abort();
 
620
    }
 
621
 
 
622
    return val;
 
623
}