13 #ifdef HAVE_TEUCHOS_MPI 
   15 #endif // HAVE_TEUCHOS_MPI 
   19 template<
class PacketType>
 
   27   typedef PacketType packet_type;
 
   32   out << 
"Testing Teuchos::scatterv<int, " 
   33       << TypeNameTraits<packet_type>::name ()
 
   34       << 
"> with root = " << root << endl;
 
   38   int gblSuccess = lclSuccess;
 
   40 #ifdef HAVE_TEUCHOS_MPI 
   41   using Teuchos::MpiComm;
 
   42   int errCode = MPI_SUCCESS;
 
   44   MPI_Comm rawMpiComm = * (mpiComm.getRawMpiComm());
 
   45 #endif // HAVE_TEUCHOS_MPI 
   49   const int myRank = comm.
getRank ();
 
   50   const int numProcs = comm.
getSize ();
 
   51   const int sendCount = 10; 
 
   52   const int recvCount = 10; 
 
   54   out << 
"Initializing receive buffer (on all processes)" << endl;
 
   58   for (
int i = 0; i < recvCount; ++i) {
 
   62   out << 
"Filling send buffer (on root process only)" << endl;
 
   69     sendBuf.
resize (sendCount * numProcs);
 
   74       for (
int p = 0; p < numProcs; ++p) {
 
   75         for (
int k = 0; k < sendCount; ++k) {
 
   76           const packet_type val = 
static_cast<packet_type
> (p+1) *
 
   77             (ONE + static_cast<packet_type> (k));
 
   78           sendBuf[p*sendCount + k] = val;
 
   81     } 
catch (std::exception& e) {
 
   82       std::cerr << 
"Root process " << root << 
" threw an exception: " 
   88 #ifdef HAVE_TEUCHOS_MPI 
   92   gblSuccess = lclSuccess;
 
   93   errCode = MPI_Bcast (&gblSuccess, 1, MPI_INT, root, rawMpiComm);
 
   95     (errCode != MPI_SUCCESS, std::logic_error, 
"MPI_Bcast failed!");
 
   97     (gblSuccess != 1, std::logic_error, 
"Filling the send buffer failed on " 
   98      "the root (" << root << 
") process!  This probably indicates a bug in " 
  100 #endif // HAVE_TEUCHOS_MPI 
  105   for( 
int i = 0; i < numProcs; ++i ) {
 
  106     displs[i+1] = displs[i] + sendCount;
 
  107     sendCounts[i] = sendCount;
 
  111   out << 
"About to invoke scatterv" << endl;
 
  112   Teuchos::scatterv <int, packet_type> (sendBuf.
getRawPtr (), sendCounts.data(), displs.
data(),
 
  113                                         recvBuf.
getRawPtr (), recvCount, root, comm);
 
  114   out << 
"Done with scatterv" << endl;
 
  117   for (
int k = 0; k < recvCount; ++k) {
 
  118     const packet_type expectedVal = 
static_cast<packet_type
> (myRank+1) *
 
  119       (ONE + static_cast<packet_type> (k));
 
  122   lclSuccess = success ? 1 : 0;
 
  123   gblSuccess = lclSuccess;
 
  134 #ifdef HAVE_TEUCHOS_MPI 
  135   errCode = MPI_Allreduce (&lclSuccess, &gblSuccess, 1,
 
  136                            MPI_INT, MPI_MIN, rawMpiComm);
 
  138     (errCode != MPI_SUCCESS, std::logic_error, 
"MPI_Allreduce failed!");
 
  139 #else // HAVE_TEUCHOS_MPI 
  141     (comm.
getSize () != 1, std::logic_error, 
"Not building with MPI, but " 
  142      "communicator has size = " << comm.
getSize () << 
" != 1.  We don't know " 
  143      "how to test this case.");
 
  145     (comm.
getRank () != root, std::logic_error, 
"Not building with MPI, but " 
  146      "the one process of rank " << comm.
getRank () << 
" is not the root " 
  147      "process of rank " << root << 
".  We don't know how to test this case.");
 
  148 #endif // HAVE_TEUCHOS_MPI 
  150   return gblSuccess == 1;
 
  159   typedef PacketType packet_type;
 
  162   out << 
"Testing Teuchos::scatterv" << endl;
 
  166   const int numProcs = comm->getSize ();
 
  170   for (
int root = 0; root < numProcs; ++root) {
 
  171     out << 
"Test for root = " << root << endl;
 
  172     const bool curSuccess = testScatterv<packet_type> (success, out, root, *comm);
 
  174     success = success && curSuccess;
 
  178   out << 
"Done with test!" << endl;
 
virtual int getSize() const =0
Returns the number of processes that make up this communicator. 
 
virtual int getRank() const =0
Returns the rank of this process. 
 
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging. 
 
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(TEST_GROUP, TEST_NAME, TYPE)
Macro for defining a templated unit test with one template parameter. 
 
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
 
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2. 
 
T * getRawPtr()
Return a raw pointer to beginning of array or NULL if unsized. 
 
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator. 
 
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
 
T_To & dyn_cast(T_From &from)
Dynamic casting utility function meant to replace dynamic_cast<T&> by throwing a better documented er...
 
Implementation of Teuchos wrappers for MPI. 
 
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2. 
 
T * data()
Return a raw pointer to beginning of array. 
 
void resize(size_type new_size, const value_type &x=value_type())
 
Default traits class that just returns typeid(T).name(). 
 
static T zero()
Returns representation of zero for this scalar type. 
 
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(TEST_GROUP, TEST_NAME, TYPE)
Instantiate a templated unit test with one template parameter. 
 
Smart reference counting pointer class for automatic garbage collection. 
 
void scatterv(const Packet sendBuf[], const Ordinal sendCounts[], const Ordinal displs[], Packet recvBuf[], const Ordinal recvCount, const Ordinal root, const Comm< Ordinal > &comm)
 
static T one()
Returns representation of one for this scalar type. 
 
bool testScatterv(bool &success, std::ostream &out, const int root, const Teuchos::Comm< int > &comm)
 
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...