|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* (C) 2003 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
* See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
#include "mpi.h"
|
|
Packit |
0848f5 |
#include <stdio.h>
|
|
Packit |
0848f5 |
#include <stdlib.h>
|
|
Packit |
0848f5 |
#include "mpitest.h"
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
static char MTEST_Descrip[] = "A simple test of Reduce with all choices of root process";
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int errs = 0;
|
|
Packit |
0848f5 |
int rank, size, root;
|
|
Packit |
0848f5 |
int *sendbuf, *recvbuf, i;
|
|
Packit |
0848f5 |
int minsize = 2, count;
|
|
Packit |
0848f5 |
MPI_Comm comm;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Init(&argc, &argv);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
|
|
Packit |
0848f5 |
if (comm == MPI_COMM_NULL)
|
|
Packit |
0848f5 |
continue;
|
|
Packit |
0848f5 |
/* Determine the sender and receiver */
|
|
Packit |
0848f5 |
MPI_Comm_rank(comm, &rank;;
|
|
Packit |
0848f5 |
MPI_Comm_size(comm, &size);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
for (count = 1; count < 130000; count = count * 2) {
|
|
Packit |
0848f5 |
sendbuf = (int *) malloc(count * sizeof(int));
|
|
Packit |
0848f5 |
recvbuf = (int *) malloc(count * sizeof(int));
|
|
Packit |
0848f5 |
for (root = 0; root < size; root++) {
|
|
Packit |
0848f5 |
for (i = 0; i < count; i++)
|
|
Packit |
0848f5 |
sendbuf[i] = i;
|
|
Packit |
0848f5 |
for (i = 0; i < count; i++)
|
|
Packit |
0848f5 |
recvbuf[i] = -1;
|
|
Packit |
0848f5 |
MPI_Reduce(sendbuf, recvbuf, count, MPI_INT, MPI_SUM, root, comm);
|
|
Packit |
0848f5 |
if (rank == root) {
|
|
Packit |
0848f5 |
for (i = 0; i < count; i++) {
|
|
Packit |
0848f5 |
if (recvbuf[i] != i * size) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
free(sendbuf);
|
|
Packit |
0848f5 |
free(recvbuf);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
MTestFreeComm(&comm);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Finalize(errs);
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|