Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Finish pulling changes from mpich trunk testsuite
[simgrid.git] / teshsuite / smpi / mpich3-test / group / groupcreate.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdio.h>
8 /* stdlib.h Needed for malloc declaration */
9 #include <stdlib.h>
10
11 int main( int argc, char **argv )
12 {
13     int i, n, n_goal = 2048, n_all, rc, n_ranks, *ranks, rank, size, len;
14     int group_size;
15     MPI_Group *group_array, world_group;
16     char msg[MPI_MAX_ERROR_STRING];
17
18     MPI_Init( &argc, &argv );
19     MPI_Comm_size( MPI_COMM_WORLD, &size );
20     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
21     n = n_goal;
22     
23     group_array = (MPI_Group *)malloc( n * sizeof(MPI_Group) );
24
25     MPI_Comm_group( MPI_COMM_WORLD, &world_group );
26
27     n_ranks = size;
28     ranks = (int *)malloc( size * sizeof(int) );
29     for (i=0; i<size; i++) ranks[i] = i;
30
31     MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
32     for (i=0; i<n; i++) {
33         rc = MPI_Group_incl( world_group, n_ranks, ranks, group_array + i );
34         if (rc) {
35             fprintf( stderr, "Error when creating group number %d\n", i );
36             MPI_Error_string( rc, msg, &len );
37             fprintf( stderr, "%s\n", msg );
38             n = i + 1;
39             break;
40         }
41         else {
42             /* Check that the group was created (and that any errors were
43                caught) */
44             rc = MPI_Group_size( group_array[i], &group_size );
45             if (group_size != size) {
46                 fprintf( stderr, "Group number %d not correct (size = %d)\n", 
47                          i, size );
48                 n = i + 1; 
49                 break;
50             }
51         }
52         
53     }
54
55     for (i=0; i<n; i++) {
56         rc = MPI_Group_free( group_array + i );
57         if (rc) {
58             fprintf( stderr, "Error when freeing group number %d\n", i );
59             MPI_Error_string( rc, msg, &len );
60             fprintf( stderr, "%s\n", msg );
61             break;
62         }
63     }
64
65     MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL );
66     MPI_Group_free( &world_group );
67
68     MPI_Reduce( &n, &n_all, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD );
69     if (rank == 0) {
70         /* printf( "Completed test of %d type creations\n", n_all ); */
71         if (n_all != n_goal) {
72             printf (
73 "This MPI implementation limits the number of groups that can be created\n\
74 This is allowed by the standard and is not a bug, but is a limit on the\n\
75 implementation\n" );
76         }
77         else {
78             printf( " No Errors\n" );
79         }
80     }
81
82     free( group_array );
83
84     MPI_Finalize( );
85     return 0;
86 }