47 int main(
int argc,
char* argv[]) {
55 RCP<const Teuchos::Comm<int> >
58 const int size = Teuchos::size(*comm);
59 const int rank = Teuchos::rank(*comm);
64 <<
"\t\tSize: " << size << std::endl;
69 std::vector<int> sendbuf(size,one);
70 std::vector<int> recvcounts(size,one);
75 std::vector<int> sbuf(sendbuf);
76 std::vector<int> rcnt(recvcounts);
79 MPI_Comm mpi_comm = MPI_COMM_WORLD;
80 MPI_Reduce_scatter(&sbuf[0],&rbuf,&rcnt[0],MPI_INT,MPI_SUM,mpi_comm);
84 std::cout <<
"Received from direct MPI call: " << rbuf << std::endl;
86 ierr += (rbuf == size ? 0 : 1);
93 std::vector<int> sbuf(sendbuf);
94 std::vector<int> rcnt(recvcounts);
97 MPI_Comm mpi_comm = MPI_COMM_WORLD;
98 MPI_Datatype _chars_type;
99 MPI_Type_contiguous(
sizeof(
int), MPI_CHAR, &_chars_type);
100 MPI_Reduce_scatter(&sbuf[0], &rbuf, &rcnt[0], _chars_type, MPI_SUM, mpi_comm);
104 std::cout <<
"Received from direct MPI call with user type: " << rbuf << std::endl;
106 ierr += (rbuf == size ? 0 : 1);
112 std::vector<int> sbuf(sendbuf);
113 std::vector<int> rcnt(recvcounts);
116 Teuchos::reduceAllAndScatter<int>(*comm,
Teuchos::REDUCE_SUM,(int)sbuf.size(),&sbuf[0],&rcnt[0],&rbuf);
120 std::cout <<
"Received from MPI-via-Teuchos call: " << rbuf << std::endl;
122 ierr += (rbuf == size ? 0 : 1);
127 std::cerr <<
"Test FAILED." << std::endl;
130 std::cerr <<
"Test passed." << std::endl;
static T one()
Returns representation of one for this ordinal type.
int main(int argc, char *argv[])
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
int rank(const Comm< Ordinal > &comm)
Get the process rank.
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator.
Initialize, finalize, and query the global MPI session.
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Smart reference counting pointer class for automatic garbage collection.