File: commcreatep.c

package info (click to toggle)
mpich 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • 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 (80 lines) | stat: -rw-r--r-- 2,203 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
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

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

#define MAX_LOG_WSIZE 31
#define MAX_LOOP 20

int main(int argc, char *argv[])
{
    MPI_Group gworld, g;
    MPI_Comm comm, newcomm[MAX_LOOP];
    int wsize, wrank, range[1][3], errs = 0;
    double t[MAX_LOG_WSIZE], tf;
    int maxi, i, k, ts, gsize[MAX_LOG_WSIZE];

    MTest_Init(&argc, &argv);

    MPI_Comm_size(MPI_COMM_WORLD, &wsize);
    MPI_Comm_rank(MPI_COMM_WORLD, &wrank);

    if (wrank == 0)
        MTestPrintfMsg(1, "size\ttime\n");

    MPI_Comm_group(MPI_COMM_WORLD, &gworld);
    ts = 1;
    comm = MPI_COMM_WORLD;
    for (i = 0; ts <= wsize; i++, ts = ts + ts) {
        /* Create some groups with at most ts members */
        range[0][0] = ts - 1;
        range[0][1] = 0;
        range[0][2] = -1;
        MPI_Group_range_incl(gworld, 1, range, &g);

        MPI_Barrier(MPI_COMM_WORLD);
        tf = MPI_Wtime();
        for (k = 0; k < MAX_LOOP; k++)
            MPI_Comm_create(comm, g, &newcomm[k]);
        tf = MPI_Wtime() - tf;
        MPI_Allreduce(&tf, &t[i], 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
        t[i] = t[i] / MAX_LOOP;
        gsize[i] = ts;
        if (wrank == 0)
            MTestPrintfMsg(1, "%d\t%e\n", ts, t[i]);
        MPI_Group_free(&g);
        if (newcomm[0] != MPI_COMM_NULL)
            for (k = 0; k < MAX_LOOP; k++)
                MPI_Comm_free(&newcomm[k]);
    }
    MPI_Group_free(&gworld);
    maxi = i - 1;

    /* The cost should be linear or at worst ts*log(ts).
     * We can check this in a number of ways.
     */
    if (wrank == 0) {
        for (i = 4; i <= maxi; i++) {
            double rdiff;
            if (t[i] > 0) {
                rdiff = (t[i] - t[i - 1]) / t[i];
                if (rdiff >= 4) {
                    errs++;
                    fprintf(stderr,
                            "Relative difference between group of size %d and %d is %e exceeds 4\n",
                            gsize[i - 1], gsize[i], rdiff);
                }
            }
        }
    }

    MTest_Finalize(errs);


    return MTestReturnValue(errs);
}