|
Packit |
0848f5 |
/* -*- Mode: C++; c-basic-offset:4 ; -*- */
|
|
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 <iostream>
|
|
Packit |
0848f5 |
#include "mpitestconf.h"
|
|
Packit |
0848f5 |
#include "mpitestcxx.h"
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
static char MTEST_Descrip[] = "Simple intercomm reduce test";
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main( int argc, char *argv[] )
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int errs = 0;
|
|
Packit |
0848f5 |
int *sendbuf = 0, *recvbuf=0;
|
|
Packit |
0848f5 |
int leftGroup, i, count, rank;
|
|
Packit |
0848f5 |
MPI::Intercomm comm;
|
|
Packit |
0848f5 |
MPI::Datatype datatype;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Init();
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
datatype = MPI::INT;
|
|
Packit |
0848f5 |
while (MTestGetIntercomm( comm, leftGroup, 4 )) {
|
|
Packit |
0848f5 |
if (comm == MPI::COMM_NULL) continue;
|
|
Packit |
0848f5 |
for (count = 1; count < 65000; count = 2 * count) {
|
|
Packit |
0848f5 |
sendbuf = new int [count];
|
|
Packit |
0848f5 |
recvbuf = new int [count];
|
|
Packit |
0848f5 |
/* Get an intercommunicator */
|
|
Packit |
0848f5 |
for (i=0; i
|
|
Packit |
0848f5 |
sendbuf[i] = -1;
|
|
Packit |
0848f5 |
recvbuf[i] = -1;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (leftGroup) {
|
|
Packit |
0848f5 |
rank = comm.Get_rank();
|
|
Packit |
0848f5 |
try
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
comm.Reduce( sendbuf, recvbuf, count, datatype, MPI::SUM,
|
|
Packit |
0848f5 |
(rank == 0) ? MPI::ROOT : MPI::PROC_NULL );
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
catch (MPI::Exception e)
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
MTestPrintError( e.Get_error_code() );
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
/* Test that no other process in this group received the
|
|
Packit |
0848f5 |
broadcast, and that we got the right answers */
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
int rsize;
|
|
Packit |
0848f5 |
rsize = comm.Get_remote_size();
|
|
Packit |
0848f5 |
for (i=0; i
|
|
Packit |
0848f5 |
if (recvbuf[i] != i * rsize) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
for (i=0; i
|
|
Packit |
0848f5 |
if (recvbuf[i] != -1) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
/* In the right group */
|
|
Packit |
0848f5 |
for (i=0; i
|
|
Packit |
0848f5 |
try
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
comm.Reduce( sendbuf, recvbuf, count, datatype, MPI::SUM, 0 );
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
catch (MPI::Exception e)
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
MTestPrintError( e.Get_error_code() );
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
/* Check that we have received no data */
|
|
Packit |
0848f5 |
for (i=0; i
|
|
Packit |
0848f5 |
if (recvbuf[i] != -1) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
delete [] sendbuf;
|
|
Packit |
0848f5 |
delete [] 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 |
}
|