Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'v3_8_x'
[simgrid.git] / teshsuite / smpi / mpich-test / context / groupcreate.c
1 #include "mpi.h"
2 #include <stdio.h>
3 /* stdlib.h Needed for malloc declaration */
4 #include <stdlib.h>
5 #include "test.h"
6
7 int main( int argc, char **argv )
8 {
9     int i, n, n_goal = 2048, n_all, rc, n_ranks, *ranks, rank, size, len;
10     MPI_Group *group_array, world_group;
11     char msg[MPI_MAX_ERROR_STRING];
12
13     MPI_Init( &argc, &argv );
14     MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
15     MPI_Comm_size( MPI_COMM_WORLD, &size );
16     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
17     n = n_goal;
18     
19     group_array = (MPI_Group *)malloc( n * sizeof(MPI_Group) );
20
21     MPI_Comm_group( MPI_COMM_WORLD, &world_group );
22
23     n_ranks = size;
24     ranks = (int *)malloc( size * sizeof(int) );
25     for (i=0; i<size; i++) ranks[i] = i;
26
27     for (i=0; i<n; i++) {
28         rc = MPI_Group_incl( world_group, n_ranks, ranks, group_array + i );
29         if (rc) {
30             fprintf( stderr, "Error when creating group number %d\n", i );
31             MPI_Error_string( rc, msg, &len );
32             fprintf( stderr, "%s\n", msg );
33             n = i + 1;
34             break;
35         }
36         
37     }
38
39     for (i=0; i<n; i++) {
40         rc = MPI_Group_free( group_array + i );
41         if (rc) {
42             fprintf( stderr, "Error when freeing group number %d\n", i );
43             MPI_Error_string( rc, msg, &len );
44             fprintf( stderr, "%s\n", msg );
45             break;
46         }
47     }
48     
49     MPI_Group_free( &world_group );
50
51     MPI_Reduce( &n, &n_all, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD );
52     if (rank == 0) {
53         /* printf( "Completed test of %d type creations\n", n_all ); */
54         if (n_all != n_goal) {
55             printf (
56 "This MPI implementation limits the number of groups that can be created\n\
57 This is allowed by the standard and is not a bug, but is a limit on the\n\
58 implementation\n" );
59         }
60         else {
61             printf( " No Errors\n" );
62         }
63     }
64
65     MPI_Finalize( );
66     return 0;
67 }