File: infocreateenv.c

package info (click to toggle)
mpich 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 423,384 kB
  • sloc: ansic: 1,088,434; cpp: 71,364; javascript: 40,763; f90: 22,829; sh: 17,463; perl: 14,773; xml: 14,418; python: 10,265; makefile: 9,246; fortran: 8,008; java: 4,355; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (83 lines) | stat: -rw-r--r-- 2,300 bytes parent folder | download | duplicates (4)
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
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include "mpi.h"
#include <stdio.h>
#include <string.h>
#include "mpitest.h"

static int verbose = 0;
static int test_info(MPI_Info info1, MPI_Info info2);

int main(int argc, char *argv[])
{
    int nerrs = 0;
    MPI_Info info1, info2;

    MPI_Info_create_env(argc, argv, &info1);
    MPI_Info_create_env(argc, argv, &info2);
    nerrs += test_info(info1, info2);

    /* Free info1 and create it again */
    MPI_Info_free(&info1);
    MPI_Info_create_env(argc, argv, &info1);
    nerrs += test_info(info1, info2);

    MPI_Init(&argc, &argv);
    /* After MPI_Init() */

    /* Free info1 and create it again */
    MPI_Info_free(&info1);
    MPI_Info_create_env(argc, argv, &info1);
    nerrs += test_info(info1, info2);

    MPI_Finalize();
    /* After MPI_Finalize() */

    /* Free info1 and create it again */
    MPI_Info_free(&info1);
    MPI_Info_create_env(argc, argv, &info1);
    nerrs += test_info(info1, info2);

    MPI_Info_free(&info1);
    MPI_Info_free(&info2);

    if (nerrs) {
        printf(" Found %d errors\n", nerrs);
    } else {
        printf(" No Errors\n");
    }
    return nerrs ? 1 : 0;
}

static int test_info(MPI_Info info1, MPI_Info info2)
{
    int i, nerrs = 0;
    char value1[MPI_MAX_INFO_VAL], value2[MPI_MAX_INFO_VAL];
    const char *keys[] = { "command", "argv", "maxprocs", "soft", "host", "arch", "wdir", "file",
        "thread_level"
    };
    for (i = 0; i < (int) (sizeof(keys) / sizeof(keys[0])); i++) {
        int flag1, flag2;
        int size1 = MPI_MAX_INFO_VAL, size2 = MPI_MAX_INFO_VAL;
        MPI_Info_get_string(info1, keys[i], &size1, value1, &flag1);
        MPI_Info_get_string(info2, keys[i], &size2, value2, &flag2);
        if (verbose && flag1)
            printf("info1 %s: %s\n", keys[i], value1);
        if (verbose && flag2)
            printf("info2 %s: %s\n", keys[i], value2);
        if (flag1 == 0 && flag2 == 0) {
            /* Both failed. */
            continue;
        } else if (flag1 == 1 && flag2 == 1 && strcmp(value1, value2) == 0) {
            /* Both return the same. */
            continue;
        } else {
            /* info1 != info2 */
            nerrs++;
        }
    }
    return nerrs;
}