Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix f77 tests
[simgrid.git] / teshsuite / smpi / mpich3-test / perf / commcreatep.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2009 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11
12 #define MAX_LOG_WSIZE 31
13 #define MAX_LOOP 20
14
15 int main(int argc, char *argv[])
16 {
17     MPI_Group gworld, g;
18     MPI_Comm comm, newcomm[MAX_LOOP];
19     int wsize, wrank, range[1][3], errs = 0;
20     double t[MAX_LOG_WSIZE], tf;
21     int maxi, i, k, ts, gsize[MAX_LOG_WSIZE];
22
23     MTest_Init(&argc, &argv);
24
25     MPI_Comm_size(MPI_COMM_WORLD, &wsize);
26     MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
27
28     if (wrank == 0)
29         MTestPrintfMsg(1, "size\ttime\n");
30
31     MPI_Comm_group(MPI_COMM_WORLD, &gworld);
32     ts = 1;
33     comm = MPI_COMM_WORLD;
34     for (i = 0; ts <= wsize; i++, ts = ts + ts) {
35         /* Create some groups with at most ts members */
36         range[0][0] = ts - 1;
37         range[0][1] = 0;
38         range[0][2] = -1;
39         MPI_Group_range_incl(gworld, 1, range, &g);
40
41         MPI_Barrier(MPI_COMM_WORLD);
42         tf = MPI_Wtime();
43         for (k = 0; k < MAX_LOOP; k++)
44             MPI_Comm_create(comm, g, &newcomm[k]);
45         tf = MPI_Wtime() - tf;
46         MPI_Allreduce(&tf, &t[i], 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
47         t[i] = t[i] / MAX_LOOP;
48         gsize[i] = ts;
49         if (wrank == 0)
50             MTestPrintfMsg(1, "%d\t%e\n", ts, t[i]);
51         MPI_Group_free(&g);
52         if (newcomm[0] != MPI_COMM_NULL)
53             for (k = 0; k < MAX_LOOP; k++)
54                 MPI_Comm_free(&newcomm[k]);
55     }
56     MPI_Group_free(&gworld);
57     maxi = i - 1;
58
59     /* The cost should be linear or at worst ts*log(ts).
60      * We can check this in a number of ways.
61      */
62     if (wrank == 0) {
63         for (i = 4; i <= maxi; i++) {
64             double rdiff;
65             if (t[i] > 0) {
66                 rdiff = (t[i] - t[i - 1]) / t[i];
67                 if (rdiff >= 4) {
68                     errs++;
69                     fprintf(stderr,
70                             "Relative difference between group of size %d and %d is %e exceeds 4\n",
71                             gsize[i - 1], gsize[i], rdiff);
72                 }
73             }
74         }
75     }
76
77     MTest_Finalize(errs);
78
79     MPI_Finalize();
80
81     return 0;
82 }