1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
/*
* Copyright (C) by Argonne National Laboratory
* See COPYRIGHT in top-level directory
*/
#include "mpi.h"
/* USE_STRICT_MPI may be defined in mpitestconf.h */
#include "mpitestconf.h"
#include <stdio.h>
#include <stdlib.h>
#include "mpitest.h"
/* FIXME: This test only checks that the MPI_Comm_split_type routine
doesn't fail. It does not check for correct behavior */
static const char *split_topo[] = {
"machine", "socket", "package", "numanode", "core", "hwthread", "pu", "l1cache",
"l1ucache", "l1dcache", "l1icache", "l2cache", "l2ucache",
"l2dcache", "l2icache", "l3cache", "l3ucache", "l3dcache", "l3icache", "pci:x",
"ib", "ibx", "gpu", "gpux", "en", "enx", "eth", "ethx", "hfi", "hfix", NULL
};
static const char *split_topo_network[] = {
"switch_level:2", "subcomm_min_size:2", "min_mem_size:512" /* Minimum memory size in bytes */ ,
"torus_dimension:2", NULL
};
int main(int argc, char *argv[])
{
int rank, size, verbose = 0, errs = 0, tot_errs = 0;
int wrank, i;
MPI_Comm comm;
MPI_Info info;
int world_size;
MTest_Init(&argc, &argv);
if (getenv("MPITEST_VERBOSE"))
verbose = 1;
MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
/* Check to see if MPI_COMM_TYPE_SHARED works correctly */
MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &comm);
if (comm == MPI_COMM_NULL) {
printf("MPI_COMM_TYPE_SHARED (no hint): got MPI_COMM_NULL\n");
errs++;
} else {
MPI_Comm_rank(comm, &rank);
MPI_Comm_size(comm, &size);
if (rank == 0 && verbose)
printf("MPI_COMM_TYPE_SHARED (no hint): Created shared subcommunicator of size %d\n",
size);
MPI_Comm_free(&comm);
}
#if MTEST_HAVE_MIN_MPI_VERSION(4,0)
/* Check to see if MPI_COMM_TYPE_HW_GUIDED works correctly */
for (i = 0; split_topo[i]; i++) {
MPI_Info_create(&info);
MPI_Info_set(info, "mpi_hw_resource_type", split_topo[i]);
int ret;
ret = MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_HW_GUIDED, 0, info, &comm);
/* result will depend on platform and process bindings, just check returns */
if (ret != MPI_SUCCESS) {
printf("MPI_COMM_TYPE_HW_GUIDED (%s) failed\n", split_topo[i]);
errs++;
} else if (comm != MPI_COMM_NULL) {
MPI_Comm_free(&comm);
}
MPI_Info_free(&info);
}
/* Test MPI_COMM_TYPE_HW_GUIDED: pass MPI_INFO_NULL, it must return MPI_COMM_NULL. */
info = MPI_INFO_NULL;
MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_HW_GUIDED, 0, info, &comm);
if (comm != MPI_COMM_NULL) {
printf("MPI_COMM_TYPE_HW_GUIDED with MPI_INFO_NULL didn't return MPI_COMM_NULL\n");
errs++;
MPI_Comm_free(&comm);
}
/* Test MPI_COMM_TYPE_HW_GUIDED: info without correct key, it must return MPI_COMM_NULL. */
MPI_Info_create(&info);
/* note: shmem_topo is the wrong key for MPI_COMM_TYPE_HW_GUIDED */
MPI_Info_set(info, "shmem_topo", split_topo[0]);
MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_HW_GUIDED, 0, info, &comm);
if (comm != MPI_COMM_NULL) {
printf("MPI_COMM_TYPE_HW_GUIDED without correct key didn't return MPI_COMM_NULL\n");
errs++;
MPI_Comm_free(&comm);
}
MPI_Info_free(&info);
/* Check to see if MPI_COMM_TYPE_HW_UNGUIDED works correctly */
MPI_Info_create(&info);
MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_HW_UNGUIDED, 0, info, &comm);
if (comm != MPI_COMM_NULL) {
int newsize;
MPI_Comm_size(comm, &newsize);
if (!(newsize < world_size)) {
printf("MPI_COMM_TYPE_HW_UNGUIDED: Expected comm to be a proper sub communicator\n");
errs++;
}
char resource_type[100] = "";
int has_key = 0;
MPI_Info_get(info, "mpi_hw_resource_type", 100, resource_type, &has_key);
if (!has_key || strlen(resource_type) == 0) {
printf("MPI_COMM_TYPE_HW_UNGUIDED: info for mpi_hw_resource_type not returned\n");
errs++;
}
MPI_Comm_free(&comm);
}
#endif
#if MTEST_HAVE_MIN_MPI_VERSION(4,1)
/* Check to see if MPI_COMM_TYPE_HW_GUIDED works correctly */
for (i = 0; split_topo[i]; i++) {
MPI_Info_create(&info);
MPI_Info_set(info, "mpi_hw_resource_type", split_topo[i]);
int ret;
ret = MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_RESOURCE_GUIDED, 0, info, &comm);
/* result will depend on platform and process bindings, just check returns */
if (ret != MPI_SUCCESS) {
printf("MPI_COMM_TYPE_HW_GUIDED (%s) failed\n", split_topo[i]);
errs++;
} else if (comm != MPI_COMM_NULL) {
MPI_Comm_free(&comm);
}
MPI_Info_free(&info);
}
#endif
#if MTEST_HAVE_MIN_MPI_VERSION(4,1)
/* test for topology hints: pass different info values from
* different processes, the hint must be ignored then. */
MPI_Info_create(&info);
if (rank % 2 == 0) {
MPI_Info_set(info, "mpi_hw_resource_type", split_topo[0]);
} else {
MPI_Info_set(info, "mpi_hw_resource_type", split_topo[1]);
}
MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_RESOURCE_GUIDED, 0, info, &comm);
if (comm != MPI_COMM_NULL) {
int newsize;
MPI_Comm_size(comm, &newsize);
if (newsize > size) {
printf
("MPI_COMM_TYPE_RESOURCE_GUIDED (mpi_hw_resource_type): comm size (%d) > node size (%d)\n",
newsize, size);
errs++;
}
MPI_Comm_free(&comm);
}
MPI_Info_free(&info);
/* test for topology hints: pass info value to some processes, but
* not others. */
if (rank % 2 == 0) {
MPI_Info_create(&info);
MPI_Info_set(info, "mpi_hw_resource_type", split_topo[0]);
} else
info = MPI_INFO_NULL;
MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_RESOURCE_GUIDED, 0, info, &comm);
if (comm != MPI_COMM_NULL) {
int newsize;
MPI_Comm_size(comm, &newsize);
if (newsize > size) {
printf
("MPI_COMM_TYPE_RESOURCE_GUIDED (mpi_hw_resource_type): comm size (%d) > node size (%d)\n",
newsize, size);
errs++;
}
MPI_Comm_free(&comm);
}
if (rank % 2 == 0)
MPI_Info_free(&info);
/* test for topology hints: pass an invalid info value and make
* sure the behavior is as if no info key was passed. */
MPI_Info_create(&info);
MPI_Info_set(info, "mpi_hw_resource_type", "__garbage_value__");
MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_RESOURCE_GUIDED, 0, info, &comm);
if (comm != MPI_COMM_NULL) {
printf
("MPI_COMM_TYPE_RESOURCE_GUIDED (mpi_hw_resource_type): invalid info value didn't result in MPI_COMM_NULL\n");
errs++;
}
MPI_Info_free(&info);
#endif
#if defined(MPIX_COMM_TYPE_NEIGHBORHOOD) && defined(HAVE_MPI_IO)
/* the MPICH-specific MPIX_COMM_TYPE_NEIGHBORHOOD */
/* test #1: expected behavior -- user provided a directory, and we
* determine which processes share access to it */
MPI_Info_create(&info);
if (argc == 2)
MPI_Info_set(info, "nbhd_common_dirname", argv[1]);
else
MPI_Info_set(info, "nbhd_common_dirname", ".");
MPI_Comm_split_type(MPI_COMM_WORLD, MPIX_COMM_TYPE_NEIGHBORHOOD, 0, info, &comm);
if (comm == MPI_COMM_NULL) {
printf("MPIX_COMM_TYPE_NEIGHBORHOOD: got MPI_COMM_NULL\n");
errs++;
} else {
MPI_Comm_rank(comm, &rank);
MPI_Comm_size(comm, &size);
if (rank == 0 && verbose)
printf("MPIX_COMM_TYPE_NEIGHBORHOOD: common-file subcommunicator size = %d\n", size);
MPI_Comm_free(&comm);
}
/* test #2: mismatching hints across processes */
MPI_Info_delete(info, "nbhd_common_dirname");
if (wrank == 1)
MPI_Info_set(info, "nbhd_common_dirname", "__first_garbage_value__");
else
MPI_Info_set(info, "nbhd_common_dirname", "__second_garbage_value__");
MPI_Comm_split_type(MPI_COMM_WORLD, MPIX_COMM_TYPE_NEIGHBORHOOD, 0, info, &comm);
if (world_size > 1 && comm != MPI_COMM_NULL) {
printf("MPIX_COMM_TYPE_NEIGHBORHOOD: mismatched hints got non null communicator\n");
MPI_Comm_free(&comm);
errs++;
}
/* test #3: a hint we don't know about */
MPI_Info_delete(info, "nbhd_common_dirname");
MPI_Info_set(info, "mpix_tooth_fairy", "enable");
MPI_Comm_split_type(MPI_COMM_WORLD, MPIX_COMM_TYPE_NEIGHBORHOOD, 0, info, &comm);
if (comm != MPI_COMM_NULL) {
printf("MPIX_COMM_TYPE_NEIGHBORHOOD: bad info value didn't return NULL communicator\n");
errs++;
MPI_Comm_free(&comm);
}
MPI_Info_free(&info);
#endif
#if defined(MPIX_COMM_TYPE_NEIGHBORHOOD)
/* Network topology tests */
for (i = 0; split_topo_network[i]; i++) {
MPI_Info_create(&info);
MPI_Info_set(info, "network_topo", split_topo_network[i]);
MPI_Comm_split_type(MPI_COMM_WORLD, MPIX_COMM_TYPE_NEIGHBORHOOD, 0, info, &comm);
if (comm != MPI_COMM_NULL) {
int newsize;
MPI_Comm_size(comm, &newsize);
if (newsize > world_size) {
printf("MPIX_COMM_TYPE_NEIGHBORHOOD (network_topo): impossible\n");
errs++;
}
MPI_Comm_free(&comm);
}
MPI_Info_free(&info);
}
#endif
/* Check to see if MPI_UNDEFINED is respected */
MPI_Comm_split_type(MPI_COMM_WORLD, (wrank % 2 == 0) ? MPI_COMM_TYPE_SHARED : MPI_UNDEFINED, 0,
MPI_INFO_NULL, &comm);
if ((wrank % 2) && (comm != MPI_COMM_NULL)) {
printf("MPI_UNDEFINED: Expected MPI_COMM_NULL, but did not get one\n");
errs++;
}
if (wrank % 2 == 0) {
if (comm == MPI_COMM_NULL) {
printf("MPI_UNDEFINED: Expected a non-null communicator, but got MPI_COMM_NULL\n");
errs++;
} else {
MPI_Comm_rank(comm, &rank);
MPI_Comm_size(comm, &size);
if (rank == 0 && verbose)
printf("Created shared subcommunicator of size %d\n", size);
MPI_Comm_free(&comm);
}
}
MPI_Reduce(&errs, &tot_errs, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
MTest_Finalize(errs);
return MTestReturnValue(errs);
}
|