1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2011 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
7 /* USE_STRICT_MPI may be defined in mpitestconf.h */
8 #include "mpitestconf.h"
12 /* FIXME: This test only checks that the MPI_Comm_split_type routine
13 doesn't fail. It does not check for correct behavior */
15 int main(int argc, char *argv[])
17 int rank, size, verbose = 0, errs=0, tot_errs=0;
20 MPI_Info __attribute__((unused)) info;
22 MPI_Init(&argc, &argv);
24 if (getenv("MPITEST_VERBOSE"))
27 MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
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");
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);
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);
49 MPI_Info_set(info, "nbhd_common_dirname", argv[1]);
51 MPI_Info_set(info, "nbhd_common_dirname", ".");
52 MPI_Comm_split_type(MPI_COMM_WORLD, MPIX_COMM_TYPE_NEIGHBORHOOD, 0,
54 if (comm == MPI_COMM_NULL) {
55 printf("Expected a non-null communicator, but got MPI_COMM_NULL\n");
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);
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,
71 if (comm != MPI_COMM_NULL) {
72 printf("Expected a NULL communicator, but got something else\n");
77 if (rank == 0 && verbose)
78 printf("Unknown hint correctly resulted in NULL communicator\n");
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");
93 if (comm == MPI_COMM_NULL) {
94 printf("Expected a non-null communicator, but got MPI_COMM_NULL\n");
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);
105 MPI_Reduce(&errs, &tot_errs, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
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");