59 typedef PacketType packet_type;
64 out <<
"Testing Teuchos::scatter<int, "
65 << TypeNameTraits<packet_type>::name ()
66 <<
"> with root = " << root << endl;
70 int gblSuccess = lclSuccess;
72#ifdef HAVE_TEUCHOS_MPI
73 using Teuchos::MpiComm;
74 int errCode = MPI_SUCCESS;
76 const MpiComm<int>* mpiComm =
dynamic_cast<const MpiComm<int>*
> (&comm);
78 (mpiComm == NULL, std::logic_error,
"Building with MPI, but default "
79 "communicator is not a Teuchos::MpiComm!");
80 MPI_Comm rawMpiComm = * (mpiComm->getRawMpiComm ());
85 const int myRank = comm.
getRank ();
86 const int numProcs = comm.
getSize ();
87 const int sendCount = 10;
88 const int recvCount = 10;
90 out <<
"Initializing receive buffer (on all processes)" << endl;
94 for (
int i = 0; i < recvCount; ++i) {
98 out <<
"Filling send buffer (on root process only)" << endl;
104 if (myRank == root) {
105 sendBuf.resize (sendCount * numProcs);
110 for (
int p = 0; p < numProcs; ++p) {
111 for (
int k = 0; k < sendCount; ++k) {
112 const packet_type val =
static_cast<packet_type
> (p+1) *
113 (ONE +
static_cast<packet_type
> (k));
114 sendBuf[p*sendCount + k] = val;
117 }
catch (std::exception& e) {
118 std::cerr <<
"Root process " << root <<
" threw an exception: "
119 << e.what () << endl;
124#ifdef HAVE_TEUCHOS_MPI
128 gblSuccess = lclSuccess;
129 errCode = MPI_Bcast (&gblSuccess, 1, MPI_INT, root, rawMpiComm);
131 (errCode != MPI_SUCCESS, std::logic_error,
"MPI_Bcast failed!");
133 (gblSuccess != 1, std::logic_error,
"Filling the send buffer failed on "
134 "the root (" << root <<
") process! This probably indicates a bug in "
139 out <<
"About to invoke scatter" << endl;
140 scatter<int, packet_type> (sendBuf.getRawPtr (), sendCount,
141 recvBuf.getRawPtr (), recvCount,
143 out <<
"Done with scatter" << endl;
146 for (
int k = 0; k < recvCount; ++k) {
147 const packet_type expectedVal =
static_cast<packet_type
> (myRank+1) *
148 (ONE +
static_cast<packet_type
> (k));
151 lclSuccess = success ? 1 : 0;
152 gblSuccess = lclSuccess;
162#ifdef HAVE_TEUCHOS_MPI
163 errCode = MPI_Allreduce (&lclSuccess, &gblSuccess, 1,
164 MPI_INT, MPI_MIN, rawMpiComm);
166 (errCode != MPI_SUCCESS, std::logic_error,
"MPI_Allreduce failed!");
169 (comm.
getSize () != 1, std::logic_error,
"Not building with MPI, but "
170 "communicator has size = " << comm.
getSize () <<
" != 1. We don't know "
171 "how to test this case.");
173 (comm.
getRank () != root, std::logic_error,
"Not building with MPI, but "
174 "the one process of rank " << comm.
getRank () <<
" is not the root "
175 "process of rank " << root <<
". We don't know how to test this case.");
178 return gblSuccess == 1;
187 typedef PacketType packet_type;
190 out <<
"Testing Teuchos::scatter" << endl;
194 const int numProcs = comm->getSize ();
198 for (
int root = 0; root < numProcs; ++root) {
199 out <<
"Test for root = " << root << endl;
200 const bool curSuccess = testScatter<packet_type> (success, out, root, *comm);
202 success = success && curSuccess;
206 out <<
"Done with test!" << endl;
TEUCHOSCOMM_LIB_DLL_EXPORT void scatter(const int sendBuf[], const int sendCount, int recvBuf[], const int recvCount, const int root, const Comm< int > &comm)