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