|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
This program tests MPI_Alltoallv by having processor each process
|
|
Packit Service |
c5cf8c |
send data to two neighbors only, using counts of 0 for the other processes.
|
|
Packit Service |
c5cf8c |
This idiom is sometimes used for halo exchange operations.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Because there are separate send and receive types to alltoallv,
|
|
Packit Service |
c5cf8c |
there need to be tests to rearrange data on the fly. Not done yet.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Currently, the test uses only MPI_INT; this is adequate for testing systems
|
|
Packit Service |
c5cf8c |
that use point-to-point operations
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char **argv)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm comm;
|
|
Packit Service |
c5cf8c |
int *sbuf, *rbuf;
|
|
Packit Service |
c5cf8c |
int rank, size;
|
|
Packit Service |
c5cf8c |
int *sendcounts, *recvcounts, *rdispls, *sdispls;
|
|
Packit Service |
c5cf8c |
int i, *p, errs;
|
|
Packit Service |
c5cf8c |
int left, right, length;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
errs = 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
while (MTestGetIntracommGeneral(&comm, 2, 1)) {
|
|
Packit Service |
c5cf8c |
if (comm == MPI_COMM_NULL)
|
|
Packit Service |
c5cf8c |
continue;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(comm, &size);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(comm, &rank;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (size < 3)
|
|
Packit Service |
c5cf8c |
continue;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Create and load the arguments to alltoallv */
|
|
Packit Service |
c5cf8c |
sendcounts = (int *) malloc(size * sizeof(int));
|
|
Packit Service |
c5cf8c |
recvcounts = (int *) malloc(size * sizeof(int));
|
|
Packit Service |
c5cf8c |
rdispls = (int *) malloc(size * sizeof(int));
|
|
Packit Service |
c5cf8c |
sdispls = (int *) malloc(size * sizeof(int));
|
|
Packit Service |
c5cf8c |
if (!sendcounts || !recvcounts || !rdispls || !sdispls) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Could not allocate arg items!\n");
|
|
Packit Service |
c5cf8c |
MPI_Abort(comm, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Get the neighbors */
|
|
Packit Service |
c5cf8c |
left = (rank - 1 + size) % size;
|
|
Packit Service |
c5cf8c |
right = (rank + 1) % size;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Set the defaults */
|
|
Packit Service |
c5cf8c |
for (i = 0; i < size; i++) {
|
|
Packit Service |
c5cf8c |
sendcounts[i] = 0;
|
|
Packit Service |
c5cf8c |
recvcounts[i] = 0;
|
|
Packit Service |
c5cf8c |
rdispls[i] = 0;
|
|
Packit Service |
c5cf8c |
sdispls[i] = 0;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (length = 1; length < 66000; length = length * 2 + 1) {
|
|
Packit Service |
c5cf8c |
/* Get the buffers */
|
|
Packit Service |
c5cf8c |
sbuf = (int *) malloc(2 * length * sizeof(int));
|
|
Packit Service |
c5cf8c |
rbuf = (int *) malloc(2 * length * sizeof(int));
|
|
Packit Service |
c5cf8c |
if (!sbuf || !rbuf) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Could not allocate buffers!\n");
|
|
Packit Service |
c5cf8c |
MPI_Abort(comm, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Load up the buffers */
|
|
Packit Service |
c5cf8c |
for (i = 0; i < length; i++) {
|
|
Packit Service |
c5cf8c |
sbuf[i] = i + 100000 * rank;
|
|
Packit Service |
c5cf8c |
sbuf[i + length] = i + 100000 * rank;
|
|
Packit Service |
c5cf8c |
rbuf[i] = -i;
|
|
Packit Service |
c5cf8c |
rbuf[i + length] = -i - length;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
sendcounts[left] = length;
|
|
Packit Service |
c5cf8c |
sendcounts[right] = length;
|
|
Packit Service |
c5cf8c |
recvcounts[left] = length;
|
|
Packit Service |
c5cf8c |
recvcounts[right] = length;
|
|
Packit Service |
c5cf8c |
rdispls[left] = 0;
|
|
Packit Service |
c5cf8c |
rdispls[right] = length;
|
|
Packit Service |
c5cf8c |
sdispls[left] = 0;
|
|
Packit Service |
c5cf8c |
sdispls[right] = length;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Alltoallv(sbuf, sendcounts, sdispls, MPI_INT,
|
|
Packit Service |
c5cf8c |
rbuf, recvcounts, rdispls, MPI_INT, comm);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Check rbuf */
|
|
Packit Service |
c5cf8c |
p = rbuf; /* left */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < length; i++) {
|
|
Packit Service |
c5cf8c |
if (p[i] != i + 100000 * left) {
|
|
Packit Service |
c5cf8c |
if (errs < 10) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "[%d from %d] got %d expected %d for %dth\n",
|
|
Packit Service |
c5cf8c |
rank, left, p[i], i + 100000 * left, i);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
p = rbuf + length; /* right */
|
|
Packit Service |
c5cf8c |
for (i = 0; i < length; i++) {
|
|
Packit Service |
c5cf8c |
if (p[i] != i + 100000 * right) {
|
|
Packit Service |
c5cf8c |
if (errs < 10) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "[%d from %d] got %d expected %d for %dth\n",
|
|
Packit Service |
c5cf8c |
rank, right, p[i], i + 100000 * right, i);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
free(rbuf);
|
|
Packit Service |
c5cf8c |
free(sbuf);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
free(sdispls);
|
|
Packit Service |
c5cf8c |
free(rdispls);
|
|
Packit Service |
c5cf8c |
free(recvcounts);
|
|
Packit Service |
c5cf8c |
free(sendcounts);
|
|
Packit Service |
c5cf8c |
MTestFreeComm(&comm);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|