|
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 |
/*
|
|
Packit Service |
c5cf8c |
* Test of reduce scatter.
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* Each processor contributes its rank + the index to the reduction,
|
|
Packit Service |
c5cf8c |
* then receives the ith sum
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* Can be called with any number of processors.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include "mpicolltest.h"
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char **argv)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int err = 0;
|
|
Packit Service |
c5cf8c |
int *sendbuf, recvbuf, *recvcounts;
|
|
Packit Service |
c5cf8c |
int size, rank, i, sumval;
|
|
Packit Service |
c5cf8c |
MPI_Comm comm;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
comm = MPI_COMM_WORLD;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(comm, &size);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(comm, &rank;;
|
|
Packit Service |
c5cf8c |
sendbuf = (int *) malloc(size * sizeof(int));
|
|
Packit Service |
c5cf8c |
for (i = 0; i < size; i++)
|
|
Packit Service |
c5cf8c |
sendbuf[i] = rank + i;
|
|
Packit Service |
c5cf8c |
recvcounts = (int *) malloc(size * sizeof(int));
|
|
Packit Service |
c5cf8c |
for (i = 0; i < size; i++)
|
|
Packit Service |
c5cf8c |
recvcounts[i] = 1;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Reduce_scatter(sendbuf, &recvbuf, recvcounts, MPI_INT, MPI_SUM, comm);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
sumval = size * rank + ((size - 1) * size) / 2;
|
|
Packit Service |
c5cf8c |
/* recvbuf should be size * (rank + i) */
|
|
Packit Service |
c5cf8c |
if (recvbuf != sumval) {
|
|
Packit Service |
c5cf8c |
err++;
|
|
Packit Service |
c5cf8c |
fprintf(stdout, "Did not get expected value for reduce scatter\n");
|
|
Packit Service |
c5cf8c |
fprintf(stdout, "[%d] Got %d expected %d\n", rank, recvbuf, sumval);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
free(sendbuf);
|
|
Packit Service |
c5cf8c |
free(recvcounts);
|
|
Packit Service |
c5cf8c |
MTest_Finalize(err);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(err);
|
|
Packit Service |
c5cf8c |
}
|