|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2012 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include <string.h>
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include <mpi.h>
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if !defined(USE_STRICT_MPI) && defined(MPICH)
|
|
Packit Service |
c5cf8c |
#define TEST_NEIGHB_COLL 1
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* assert-like macro that bumps the err count and emits a message */
|
|
Packit Service |
c5cf8c |
#define check(x_) \
|
|
Packit Service |
c5cf8c |
do { \
|
|
Packit Service |
c5cf8c |
if (!(x_)) { \
|
|
Packit Service |
c5cf8c |
++errs; \
|
|
Packit Service |
c5cf8c |
if (errs < 10) { \
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "check failed: (%s), line %d\n", #x_, __LINE__); \
|
|
Packit Service |
c5cf8c |
} \
|
|
Packit Service |
c5cf8c |
} \
|
|
Packit Service |
c5cf8c |
} while (0)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int errs = 0;
|
|
Packit Service |
c5cf8c |
int wrank, wsize;
|
|
Packit Service |
c5cf8c |
int periods[1] = { 0 };
|
|
Packit Service |
c5cf8c |
MPI_Comm cart, dgraph, graph;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(MPI_COMM_WORLD, &wsize);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if defined(TEST_NEIGHB_COLL)
|
|
Packit Service |
c5cf8c |
/* a basic test for the 10 (5 patterns x {blocking,nonblocking}) MPI-3
|
|
Packit Service |
c5cf8c |
* neighborhood collective routines */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* (wrap)--> 0 <--> 1 <--> ... <--> p-1 <--(wrap) */
|
|
Packit Service |
c5cf8c |
MPI_Cart_create(MPI_COMM_WORLD, 1, &wsize, periods, /*reorder= */ 0, &cart;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* allgather */
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int sendbuf[1] = { wrank };
|
|
Packit Service |
c5cf8c |
int recvbuf[2] = { 0xdeadbeef, 0xdeadbeef };
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* should see one send to each neighbor (rank-1 and rank+1) and one receive
|
|
Packit Service |
c5cf8c |
* each from same */
|
|
Packit Service |
c5cf8c |
MPI_Neighbor_allgather(sendbuf, 1, MPI_INT, recvbuf, 1, MPI_INT, cart);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (wrank == 0)
|
|
Packit Service |
c5cf8c |
check(recvbuf[0] == 0xdeadbeef);
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
check(recvbuf[0] == wrank - 1);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (wrank == wsize - 1)
|
|
Packit Service |
c5cf8c |
check(recvbuf[1] == 0xdeadbeef);
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
check(recvbuf[1] == wrank + 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* allgatherv */
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int sendbuf[1] = { wrank };
|
|
Packit Service |
c5cf8c |
int recvbuf[2] = { 0xdeadbeef, 0xdeadbeef };
|
|
Packit Service |
c5cf8c |
int recvcounts[2] = { 1, 1 };
|
|
Packit Service |
c5cf8c |
int displs[2] = { 1, 0 };
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* should see one send to each neighbor (rank-1 and rank+1) and one receive
|
|
Packit Service |
c5cf8c |
* each from same, but put them in opposite slots in the buffer */
|
|
Packit Service |
c5cf8c |
MPI_Neighbor_allgatherv(sendbuf, 1, MPI_INT, recvbuf, recvcounts, displs, MPI_INT, cart);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (wrank == 0)
|
|
Packit Service |
c5cf8c |
check(recvbuf[1] == 0xdeadbeef);
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
check(recvbuf[1] == wrank - 1);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (wrank == wsize - 1)
|
|
Packit Service |
c5cf8c |
check(recvbuf[0] == 0xdeadbeef);
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
check(recvbuf[0] == wrank + 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* alltoall */
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int sendbuf[2] = { -(wrank + 1), wrank + 1 };
|
|
Packit Service |
c5cf8c |
int recvbuf[2] = { 0xdeadbeef, 0xdeadbeef };
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* should see one send to each neighbor (rank-1 and rank+1) and one
|
|
Packit Service |
c5cf8c |
* receive each from same */
|
|
Packit Service |
c5cf8c |
MPI_Neighbor_alltoall(sendbuf, 1, MPI_INT, recvbuf, 1, MPI_INT, cart);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (wrank == 0)
|
|
Packit Service |
c5cf8c |
check(recvbuf[0] == 0xdeadbeef);
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
check(recvbuf[0] == wrank);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (wrank == wsize - 1)
|
|
Packit Service |
c5cf8c |
check(recvbuf[1] == 0xdeadbeef);
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
check(recvbuf[1] == -(wrank + 2));
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* alltoallv */
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int sendbuf[2] = { -(wrank + 1), wrank + 1 };
|
|
Packit Service |
c5cf8c |
int recvbuf[2] = { 0xdeadbeef, 0xdeadbeef };
|
|
Packit Service |
c5cf8c |
int sendcounts[2] = { 1, 1 };
|
|
Packit Service |
c5cf8c |
int recvcounts[2] = { 1, 1 };
|
|
Packit Service |
c5cf8c |
int sdispls[2] = { 0, 1 };
|
|
Packit Service |
c5cf8c |
int rdispls[2] = { 1, 0 };
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* should see one send to each neighbor (rank-1 and rank+1) and one receive
|
|
Packit Service |
c5cf8c |
* each from same, but put them in opposite slots in the buffer */
|
|
Packit Service |
c5cf8c |
MPI_Neighbor_alltoallv(sendbuf, sendcounts, sdispls, MPI_INT,
|
|
Packit Service |
c5cf8c |
recvbuf, recvcounts, rdispls, MPI_INT, cart);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (wrank == 0)
|
|
Packit Service |
c5cf8c |
check(recvbuf[1] == 0xdeadbeef);
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
check(recvbuf[1] == wrank);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (wrank == wsize - 1)
|
|
Packit Service |
c5cf8c |
check(recvbuf[0] == 0xdeadbeef);
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
check(recvbuf[0] == -(wrank + 2));
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* alltoallw */
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int sendbuf[2] = { -(wrank + 1), wrank + 1 };
|
|
Packit Service |
c5cf8c |
int recvbuf[2] = { 0xdeadbeef, 0xdeadbeef };
|
|
Packit Service |
c5cf8c |
int sendcounts[2] = { 1, 1 };
|
|
Packit Service |
c5cf8c |
int recvcounts[2] = { 1, 1 };
|
|
Packit Service |
c5cf8c |
MPI_Aint sdispls[2] = { 0, sizeof(int) };
|
|
Packit Service |
c5cf8c |
MPI_Aint rdispls[2] = { sizeof(int), 0 };
|
|
Packit Service |
c5cf8c |
MPI_Datatype sendtypes[2] = { MPI_INT, MPI_INT };
|
|
Packit Service |
c5cf8c |
MPI_Datatype recvtypes[2] = { MPI_INT, MPI_INT };
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* should see one send to each neighbor (rank-1 and rank+1) and one receive
|
|
Packit Service |
c5cf8c |
* each from same, but put them in opposite slots in the buffer */
|
|
Packit Service |
c5cf8c |
MPI_Neighbor_alltoallw(sendbuf, sendcounts, sdispls, sendtypes,
|
|
Packit Service |
c5cf8c |
recvbuf, recvcounts, rdispls, recvtypes, cart);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (wrank == 0)
|
|
Packit Service |
c5cf8c |
check(recvbuf[1] == 0xdeadbeef);
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
check(recvbuf[1] == wrank);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (wrank == wsize - 1)
|
|
Packit Service |
c5cf8c |
check(recvbuf[0] == 0xdeadbeef);
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
check(recvbuf[0] == -(wrank + 2));
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&cart;;
|
|
Packit Service |
c5cf8c |
#endif /* defined(TEST_NEIGHB_COLL) */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|