1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2009 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
12 #define MAX_LOG_WSIZE 31
15 int main( int argc, char *argv[] )
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];
23 MTest_Init( &argc, &argv );
25 MPI_Comm_size( MPI_COMM_WORLD, &wsize );
26 MPI_Comm_rank( MPI_COMM_WORLD, &wrank );
29 MTestPrintfMsg( 1, "size\ttime\n" );
31 MPI_Comm_group( MPI_COMM_WORLD, &gworld );
33 comm = MPI_COMM_WORLD;
34 for (i=0; ts<=wsize; i++, ts = ts + ts) {
35 /* Create some groups with at most ts members */
39 MPI_Group_range_incl( gworld, 1, range, &g );
41 MPI_Barrier( MPI_COMM_WORLD );
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;
50 MTestPrintfMsg( 1, "%d\t%e\n", ts, t[i] );
52 if (newcomm[0] != MPI_COMM_NULL)
53 for (k=0; k<MAX_LOOP; k++)
54 MPI_Comm_free( &newcomm[k] );
56 MPI_Group_free( &gworld );
59 /* The cost should be linear or at worst ts*log(ts).
60 We can check this in a number of ways.
63 for (i=4; i<=maxi; i++) {
66 rdiff = (t[i] - t[i-1]) / t[i];
69 fprintf( stderr, "Relative difference between group of size %d and %d is %e exceeds 4\n",
70 gsize[i-1], gsize[i], rdiff );
76 MTest_Finalize( errs );