Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
16681a202d61905e865df516acfdc1de40389ceb
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / cmsplit_type.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2011 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 /* USE_STRICT_MPI may be defined in mpitestconf.h */
8 #include "mpitestconf.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 /* FIXME: This test only checks that the MPI_Comm_split_type routine
13    doesn't fail.  It does not check for correct behavior */
14
15 int main(int argc, char *argv[])
16 {
17     int rank, size, verbose = 0, errs=0, tot_errs=0;
18     int wrank;
19     MPI_Comm comm;
20     MPI_Info __attribute__((unused)) info;
21
22     MPI_Init(&argc, &argv);
23
24     if (getenv("MPITEST_VERBOSE"))
25         verbose = 1;
26
27     MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
28
29     /* Check to see if MPI_COMM_TYPE_SHARED works correctly */
30     MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &comm);
31     if (comm == MPI_COMM_NULL) {
32         printf("Expected a non-null communicator, but got MPI_COMM_NULL\n");
33         errs++;
34     }
35     else {
36         MPI_Comm_rank(comm, &rank);
37         MPI_Comm_size(comm, &size);
38         if (rank == 0 && verbose)
39             printf("Created shared subcommunicator of size %d\n", size);
40         MPI_Comm_free(&comm);
41     }
42
43 #ifdef MPIX_COMM_TYPE_NEIGHBORHOOD
44     /* the MPICH-specific MPIX_COMM_TYPE_NEIGHBORHOOD*/
45     /* test #1: expected behavior -- user provided a directory, and we
46      * determine which processes share access to it */
47     MPI_Info_create(&info);
48     if (argc == 2)
49             MPI_Info_set(info, "nbhd_common_dirname", argv[1]);
50     else
51         MPI_Info_set(info, "nbhd_common_dirname", ".");
52     MPI_Comm_split_type(MPI_COMM_WORLD, MPIX_COMM_TYPE_NEIGHBORHOOD, 0,
53             info, &comm);
54     if (comm == MPI_COMM_NULL) {
55         printf("Expected a non-null communicator, but got MPI_COMM_NULL\n");
56         errs++;
57     }
58     else {
59         MPI_Comm_rank(comm, &rank);
60         MPI_Comm_size(comm, &size);
61         if (rank == 0 && verbose)
62             printf("Correctly created common-file subcommunicator of size %d\n", size);
63         MPI_Comm_free(&comm);
64     }
65
66     /* test #2: a hint we don't know about */
67     MPI_Info_delete(info, "nbhd_common_dirname");
68     MPI_Info_set(info, "mpix_tooth_fairy", "enable");
69     MPI_Comm_split_type(MPI_COMM_WORLD, MPIX_COMM_TYPE_NEIGHBORHOOD, 0,
70             info, &comm);
71     if (comm != MPI_COMM_NULL) {
72         printf("Expected a NULL communicator, but got something else\n");
73         errs++;
74         MPI_Comm_free(&comm);
75     }
76     else {
77         if (rank == 0 && verbose)
78             printf("Unknown hint correctly resulted in NULL communicator\n");
79     }
80
81
82     MPI_Info_free(&info);
83 #endif
84
85     /* Check to see if MPI_UNDEFINED is respected */
86     MPI_Comm_split_type(MPI_COMM_WORLD, (wrank % 2 == 0) ? MPI_COMM_TYPE_SHARED : MPI_UNDEFINED,
87                         0, MPI_INFO_NULL, &comm);
88     if ((wrank % 2) && (comm != MPI_COMM_NULL)) {
89         printf("Expected MPI_COMM_NULL, but did not get one\n");
90         errs++;
91     }
92     if (wrank % 2 == 0) {
93         if (comm == MPI_COMM_NULL) {
94             printf("Expected a non-null communicator, but got MPI_COMM_NULL\n");
95             errs++;
96         }
97         else {
98             MPI_Comm_rank(comm, &rank);
99             MPI_Comm_size(comm, &size);
100             if (rank == 0 && verbose)
101                 printf("Created shared subcommunicator of size %d\n", size);
102             MPI_Comm_free(&comm);
103         }
104     }
105     MPI_Reduce(&errs, &tot_errs, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
106
107     /* Use wrank because Comm_split_type may return more than one communicator
108      * across the job, and if so, each will have a rank 0 entry.  Test
109      * output rules are for a single process to write the successful
110      * test (No Errors) output. */
111     if (wrank == 0 && errs == 0)
112         printf(" No errors\n");
113
114     MPI_Finalize();
115
116     return 0;
117 }