Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[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++)
30         ranks[i] = i;
31
32     MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
33     for (i = 0; i < n; i++) {
34         rc = MPI_Group_incl(world_group, n_ranks, ranks, group_array + i);
35         if (rc) {
36             fprintf(stderr, "Error when creating group number %d\n", i);
37             MPI_Error_string(rc, msg, &len);
38             fprintf(stderr, "%s\n", msg);
39             n = i + 1;
40             break;
41         }
42         else {
43             /* Check that the group was created (and that any errors were
44              * caught) */
45             rc = MPI_Group_size(group_array[i], &group_size);
46             if (group_size != size) {
47                 fprintf(stderr, "Group number %d not correct (size = %d)\n", 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("This MPI implementation limits the number of groups that can be created\n\
73 This is allowed by the standard and is not a bug, but is a limit on the\n\
74 implementation\n");
75         }
76         else {
77             printf(" No Errors\n");
78         }
79     }
80
81     free(group_array);
82     free(ranks);
83
84     MPI_Finalize();
85     return 0;
86 }