45 #ifdef HAVE_TEUCHOS_MPI 
   47 #endif // HAVE_TEUCHOS_MPI 
   51 template<
class PacketType>
 
   56 #ifdef HAVE_TEUCHOS_MPI 
   57   using Teuchos::MpiComm;
 
   58 #endif // HAVE_TEUCHOS_MPI 
   59   using Teuchos::reduce;
 
   62   typedef PacketType packet_type;
 
   66   out << 
"Testing Teuchos::reduce<int, " << TypeNameTraits<packet_type>::name ()
 
   67       << 
"> with reductType = REDUCE_SUM and root = " << root << endl;
 
   72   packet_type sendBuf[10];
 
   73   packet_type recvBuf[10];
 
   74   for (
int i = 0; i < count; ++i) {
 
   79   reduce<int, packet_type> (sendBuf, recvBuf, count, reductType, root, comm);
 
   86 #ifdef HAVE_TEUCHOS_MPI 
   87   using Teuchos::MpiComm;
 
   88   int err = MPI_SUCCESS;
 
   90   const MpiComm<int>* mpiComm = 
dynamic_cast<const MpiComm<int>* 
> (&comm);
 
   92     (mpiComm == NULL, std::logic_error, 
"Building with MPI, but default " 
   93      "communicator is not a Teuchos::MpiComm!");
 
   94   MPI_Comm rawMpiComm = * (mpiComm->getRawMpiComm ());
 
   97   err = MPI_Barrier (rawMpiComm);
 
   99     (err != MPI_SUCCESS, std::logic_error, 
"MPI_Barrier failed!");
 
  102   packet_type sendBuf2[10];
 
  103   packet_type recvBuf2[10];
 
  104   for (
int i = 0; i < count; ++i) {
 
  109   MPI_Datatype rawMpiType;
 
  110   if (
typeid (packet_type) == 
typeid (
short)) {
 
  111     rawMpiType = MPI_SHORT;
 
  112   } 
else if (
typeid (packet_type) == 
typeid (
unsigned short)) {
 
  113     rawMpiType = MPI_UNSIGNED_SHORT;
 
  114   } 
else if (
typeid (packet_type) == 
typeid (
int)) {
 
  115     rawMpiType = MPI_INT;
 
  116   } 
else if (
typeid (packet_type) == 
typeid (
unsigned int)) {
 
  117     rawMpiType = MPI_UNSIGNED;
 
  118   } 
else if (
typeid (packet_type) == 
typeid (
long)) {
 
  119     rawMpiType = MPI_LONG;
 
  120   } 
else if (
typeid (packet_type) == 
typeid (
unsigned long)) {
 
  121     rawMpiType = MPI_UNSIGNED_LONG;
 
  122   } 
else if (
typeid (packet_type) == 
typeid (
long long)) {
 
  123     rawMpiType = MPI_LONG_LONG;
 
  124   } 
else if (
typeid (packet_type) == 
typeid (
unsigned long long)) {
 
  125     rawMpiType = MPI_UNSIGNED_LONG_LONG;
 
  126   } 
else if (
typeid (packet_type) == 
typeid (
float)) {
 
  127     rawMpiType = MPI_FLOAT;
 
  128   } 
else if (
typeid (packet_type) == 
typeid (
double)) {
 
  129     rawMpiType = MPI_DOUBLE;
 
  132       (
true, std::logic_error, 
"Unimplemented conversion from PacketType = " 
  133        << TypeNameTraits<packet_type>::name () << 
" to MPI_Datatype.");
 
  136   err = MPI_Allreduce (sendBuf2, recvBuf2, count, rawMpiType, MPI_SUM, rawMpiComm);
 
  138     (err != MPI_SUCCESS, std::logic_error, 
"MPI_Allreduce failed!");
 
  140     for (
int i = 0; i < count; ++i) {
 
  145   int lclSuccess = success ? 1 : 0;
 
  146   int gblSuccess = lclSuccess;
 
  147   err = MPI_Allreduce (&lclSuccess, &gblSuccess, 1, MPI_INT, MPI_MIN, rawMpiComm);
 
  149     (err != MPI_SUCCESS, std::logic_error, 
"MPI_Allreduce failed!");
 
  150   success = gblSuccess == 1 ? 
true : 
false;
 
  152 #else // HAVE_TEUCHOS_MPI 
  154     (comm.
getSize () != 1, std::logic_error, 
"Not building with MPI, but " 
  155      "communicator has size = " << comm.
getSize () << 
" != 1.  We don't know " 
  156      "how to test this case.");
 
  157   for (
int i = 0; i < count; ++i) {
 
  161 #endif // HAVE_TEUCHOS_MPI 
  171   using Teuchos::reduce;
 
  172   typedef PacketType packet_type;
 
  175   const int numProcs = comm->getSize ();
 
  179   for (
int root = 0; root < numProcs; ++root) {
 
  180     const bool curSuccess = testReduceSum<packet_type> (success, out, root, *comm);
 
  182     success = success && curSuccess;
 
virtual int getSize() const =0
Returns the number of processes that make up this communicator. 
 
EReductionType
Predefined reduction operations that Teuchos::Comm understands. 
 
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. 
 
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator. 
 
Implementation of Teuchos wrappers for MPI. 
 
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2. 
 
Abstract interface for distributed-memory communication. 
 
Default traits class that just returns typeid(T).name(). 
 
bool testReduceSum(bool &success, std::ostream &out, const int root, const Teuchos::Comm< int > &comm)
 
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. 
 
static T one()
Returns representation of one for this scalar type.