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
|
/*
* Copyright (C) by Argonne National Laboratory
* See COPYRIGHT in top-level directory
*/
/* Based on a test case contributed by Michael Hofmann.
*
* This test makes sure that zero counts with non-zero-sized types on the
* send (recv) side match and don't cause a problem with non-zero counts and
* zero-sized types on the recv (send) side when using MPI_Alltoallw and
* MPI_Alltoallv. */
/* TODO test intercommunicators as well */
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#include "mpitest.h"
int main(int argc, char *argv[])
{
int sendbuf, recvbuf;
int *sendcounts;
int *recvcounts;
int *sdispls;
int *rdispls;
MPI_Datatype sendtype;
MPI_Datatype *sendtypes;
MPI_Datatype *recvtypes;
int rank = -1;
int size = -1;
int i;
MTest_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
sendtypes = malloc(size * sizeof(MPI_Datatype));
recvtypes = malloc(size * sizeof(MPI_Datatype));
sendcounts = malloc(size * sizeof(int));
recvcounts = malloc(size * sizeof(int));
sdispls = malloc(size * sizeof(int));
rdispls = malloc(size * sizeof(int));
if (!sendtypes || !recvtypes || !sendcounts || !recvcounts || !sdispls || !rdispls) {
printf("error, unable to allocate memory\n");
goto fn_exit;
}
MPI_Type_contiguous(0, MPI_INT, &sendtype);
MPI_Type_commit(&sendtype);
for (i = 0; i < size; ++i) {
sendtypes[i] = sendtype;
sendcounts[i] = 1;
sdispls[i] = 0;
recvtypes[i] = MPI_INT;
recvcounts[i] = 0;
rdispls[i] = 0;
}
/* try zero-counts on both the send and recv side in case only one direction is broken for some reason */
MPI_Alltoallw(&sendbuf, sendcounts, sdispls, sendtypes, &recvbuf, recvcounts, rdispls,
recvtypes, MPI_COMM_WORLD);
MPI_Alltoallw(&sendbuf, recvcounts, rdispls, recvtypes, &recvbuf, sendcounts, sdispls,
sendtypes, MPI_COMM_WORLD);
#if MTEST_HAVE_MIN_MPI_VERSION(2,2)
/* pass MPI_IN_PLACE and different but compatible types rank is even/odd */
if (rank % 2)
MPI_Alltoallw(MPI_IN_PLACE, NULL, NULL, NULL, &recvbuf, recvcounts, rdispls, recvtypes,
MPI_COMM_WORLD);
else
MPI_Alltoallw(MPI_IN_PLACE, NULL, NULL, NULL, &recvbuf, sendcounts, sdispls, sendtypes,
MPI_COMM_WORLD);
#endif
/* now the same for Alltoallv instead of Alltoallw */
MPI_Alltoallv(&sendbuf, sendcounts, sdispls, sendtypes[0], &recvbuf, recvcounts, rdispls,
recvtypes[0], MPI_COMM_WORLD);
MPI_Alltoallv(&sendbuf, recvcounts, rdispls, recvtypes[0], &recvbuf, sendcounts, sdispls,
sendtypes[0], MPI_COMM_WORLD);
#if MTEST_HAVE_MIN_MPI_VERSION(2,2)
if (rank % 2)
MPI_Alltoallv(MPI_IN_PLACE, NULL, NULL, MPI_DATATYPE_NULL, &recvbuf, recvcounts, rdispls,
recvtypes[0], MPI_COMM_WORLD);
else
MPI_Alltoallv(MPI_IN_PLACE, NULL, NULL, MPI_DATATYPE_NULL, &recvbuf, sendcounts, sdispls,
sendtypes[0], MPI_COMM_WORLD);
#endif
MPI_Type_free(&sendtype);
fn_exit:
if (rdispls)
free(rdispls);
if (sdispls)
free(sdispls);
if (recvcounts)
free(recvcounts);
if (sendcounts)
free(sendcounts);
if (recvtypes)
free(recvtypes);
if (sendtypes)
free(sendtypes);
MTest_Finalize(0);
return 0;
}
|