File: session_psets.c

package info (click to toggle)
mpich 4.3.0%2Breally4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 419,120 kB
  • sloc: ansic: 1,215,557; cpp: 74,755; javascript: 40,763; f90: 20,649; sh: 18,463; xml: 14,418; python: 14,397; perl: 13,772; makefile: 9,279; fortran: 8,063; java: 4,553; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (120 lines) | stat: -rw-r--r-- 3,870 bytes parent folder | download | duplicates (3)
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
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

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

/* This is adapted example 10.9 from MPI Standard 4.0
 * This example illustrates the use of Process Set query functions to select a
 * Process Set to use for MPI Group creation. First, the default error handler
 * can be specified when instatiating a Session instance. Second, there must be
 * at least two process sets associated with a Session. Third, the example
 * illustrates use of session info object and the one required key: "mpi_size".
 */

int main(int argc, char *argv[])
{
    int errs = 0;
    int n_psets, psetlen, rc;
    int valuelen;
    int flag = 0;
    char *info_val = NULL;
    char *pset_name = NULL;
    char **all_pset_names;
    MPI_Session shandle = MPI_SESSION_NULL;
    MPI_Info sinfo = MPI_INFO_NULL;
    MPI_Group pgroup = MPI_GROUP_NULL;

    rc = MPI_Session_init(MPI_INFO_NULL, MPI_ERRORS_RETURN, &shandle);
    if (rc != MPI_SUCCESS) {
        printf("Could not initialize session, bailing out\n");
        errs++;
        return MTestReturnValue(errs);
    }

    MPI_Session_get_num_psets(shandle, MPI_INFO_NULL, &n_psets);
    all_pset_names = malloc(n_psets * sizeof(char *));
    assert(all_pset_names);

    for (int i = 0; i < n_psets; i++) {
        psetlen = 0;
        MPI_Session_get_nth_pset(shandle, MPI_INFO_NULL, i, &psetlen, NULL);
        if (psetlen <= 0) {
            printf("MPI_Session_get_nth_pset: returns psetlen = %d\n", psetlen);
            errs++;
        }

        pset_name = (char *) malloc(sizeof(char) * psetlen);
        MPI_Session_get_nth_pset(shandle, MPI_INFO_NULL, i, &psetlen, pset_name);
        if (strlen(pset_name) + 1 != psetlen) {
            printf("MPI_Session_get_nth_pset: strlen(\"%s\") + 1 != %d\n", pset_name, psetlen);
            errs++;
        }

        all_pset_names[i] = strdup(pset_name);

        free(pset_name);
        pset_name = NULL;
    }

    bool got_world = false;
    bool got_self = false;
    for (int i = 0; i < n_psets; i++) {
        /* get instance of an info object for this Session */
        MPI_Session_get_pset_info(shandle, all_pset_names[i], &sinfo);
        MPI_Info_get_valuelen(sinfo, "mpi_size", &valuelen, &flag);
        if (valuelen <= 0) {
            printf("MPI_Session_get_pset_info: valuelen of mpi_size is %d\n", valuelen);
            errs++;
        }
        info_val = (char *) malloc(valuelen + 1);
        MPI_Info_get(sinfo, "mpi_size", valuelen, info_val, &flag);
        if (atol(info_val) <= 0) {
            printf("\"mpi_size\" of %s proc set is %s\n", all_pset_names[i], info_val);
        }
        if (strcmp("mpi://WORLD", all_pset_names[i]) == 0) {
            got_world = true;
        }
        if (strcmp("mpi://SELF", all_pset_names[i]) == 0) {
            got_self = true;
            if (atol(info_val) != 1) {
                printf("\"mpi_size\" of SELF proc set is %s\n", info_val);
            }
        }
        free(info_val);

        /* create a group from the process set */
        rc = MPI_Group_from_session_pset(shandle, all_pset_names[i], &pgroup);
        if (rc != MPI_SUCCESS) {
            printf("Could not create group from pset %s\n", all_pset_names[i]);
            errs++;
        }

        free(all_pset_names[i]);
        MPI_Group_free(&pgroup);
        MPI_Info_free(&sinfo);
    }
    free(all_pset_names);
    MPI_Session_finalize(&shandle);

    if (!got_self) {
        printf("proc set mpi://SELF not found\n");
        errs++;
    }
    if (!got_world) {
        printf("proc set mpi://WORLD not found\n");
        errs++;
    }

    if (errs == 0) {
        printf("No Errors\n");
    } else {
        printf("%d Errors\n", errs);
    }
    return MTestReturnValue(errs);
}