Tpetra Matrix/Vector Services Version of the Day
Namespaces | Defines | Functions
Tpetra_Util.hpp File Reference

Stand-alone utility functions and macros. More...

#include "Tpetra_ConfigDefs.hpp"
#include <iterator>
#include <algorithm>
#include <Teuchos_Utils.hpp>
#include <Teuchos_Assert.hpp>
#include <sstream>

Go to the source code of this file.

Namespaces

namespace  Tpetra
 

Namespace Tpetra contains the class and methods constituting the Tpetra library.


namespace  SortDetails
 

Implementation details of sort routines used by Tpetra.


Defines

#define TPETRA_EFFICIENCY_WARNING(throw_exception_test, Exception, msg)
 Print or throw an efficency warning.
#define TPETRA_ABUSE_WARNING(throw_exception_test, Exception, msg)
 Handle an abuse warning, according to HAVE_TPETRA_THROW_ABUSE_WARNINGS and HAVE_TPETRA_PRINT_ABUSE_WARNINGS.
#define SHARED_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg, comm)
 Test for exception, with reduction over the given communicator.
#define SWITCHED_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg, comm)
 If TEUCHOS_DEBUG is defined, then it calls SHARED_TEST_FOR_EXCEPTION. Otherwise, it calls TEUCHOS_TEST_FOR_EXCEPTION.

Functions

template<typename MapType , typename KeyArgType , typename ValueArgType >
MapType::iterator Tpetra::efficientAddOrUpdate (MapType &m, const KeyArgType &k, const ValueArgType &v)
 Efficiently insert or replace an entry in an std::map.
template<class IT1 >
bool Tpetra::SortDetails::isAlreadySorted (const IT1 &first, const IT1 &last)
 Determines whether or not a random access sequence is already sorted.
template<class IT >
IT Tpetra::SortDetails::getPivot (const IT &first, const IT &last)
 Determines the pivot point as part of the quicksort routine.
template<class IT1 , class IT2 >
IT1 Tpetra::SortDetails::partition2 (const IT1 &first1, const IT1 &last1, const IT2 &first2, const IT2 &last2, const IT1 &pivot)
 Partition operation for quicksort2().
template<class IT1 , class IT2 , class IT3 >
IT1 Tpetra::SortDetails::partition3 (const IT1 &first1, const IT1 &last1, const IT2 &first2, const IT2 &last2, const IT3 &first3, const IT3 &last3, const IT1 &pivot)
 Partition operation for quicksort3().
template<class IT1 , class IT2 >
void Tpetra::SortDetails::quicksort2 (const IT1 &first1, const IT1 &last1, const IT2 &first2, const IT2 &last2)
 Sort the first array using Quicksort, and apply the resulting permutation to the second array.
template<class IT1 , class IT2 , class IT3 >
void Tpetra::SortDetails::quicksort3 (const IT1 &first1, const IT1 &last1, const IT2 &first2, const IT2 &last2, const IT3 &first3, const IT3 &last3)
 Sort the first array using Quicksort, and apply the resulting permutation to the second and third arrays.
template<class IT1 , class IT2 , class IT3 >
void Tpetra::SortDetails::sh_sort3 (const IT1 &first1, const IT1 &last1, const IT2 &first2, const IT2 &last2, const IT3 &first3, const IT3 &last3)
 Sort the first array using shell sort, and apply the resulting permutation to the second and third arrays.
template<class IT1 , class IT2 >
void Tpetra::SortDetails::sh_sort2 (const IT1 &first1, const IT1 &last1, const IT2 &first2, const IT2 &last2)
 Sort the first array using shell sort, and apply the resulting permutation to the second array.
template<class IT1 , class IT2 >
void Tpetra::sort2 (const IT1 &first1, const IT1 &last1, const IT2 &first2)
 Sort the first array, and apply the resulting permutation to the second array.
template<class IT1 , class IT2 , class IT3 >
void Tpetra::sort3 (const IT1 &first1, const IT1 &last1, const IT2 &first2, const IT3 &first3)
 Sort the first array, and apply the same permutation to the second and third arrays.
template<class IT1 , class IT2 >
void Tpetra::merge2 (IT1 &indResultOut, IT2 &valResultOut, IT1 indBeg, IT1 indEnd, IT2 valBeg, IT2 valEnd)
 Merge values in place, additively, with the same index.
template<class IT1 , class IT2 , class BinaryFunction >
void Tpetra::merge2 (IT1 &indResultOut, IT2 &valResultOut, IT1 indBeg, IT1 indEnd, IT2 valBeg, IT2 valEnd, BinaryFunction f)
 Merge values in place with the same index, using any associative binary function.
template<class KeyInputIterType , class ValueInputIterType , class KeyOutputIterType , class ValueOutputIterType , class BinaryFunction >
void Tpetra::keyValueMerge (KeyInputIterType keyBeg1, KeyInputIterType keyEnd1, ValueInputIterType valBeg1, ValueInputIterType valEnd1, KeyInputIterType keyBeg2, KeyInputIterType keyEnd2, ValueInputIterType valBeg2, ValueInputIterType valEnd2, KeyOutputIterType keyOut, ValueOutputIterType valOut, BinaryFunction f)
 Merge two sorted (by keys) sequences of unique (key,value) pairs by combining pairs with equal keys.
bool Tpetra::Details::congruent (const Teuchos::Comm< int > &comm1, const Teuchos::Comm< int > &comm2)
 Whether the two communicators are congruent.

Detailed Description

Stand-alone utility functions and macros.

Tpetra_Util contains utility functions macros that are used throughout Tpetra, by many classes and functions. They are placed here so that they can be updated and maintained in a single spot.

Here are some of the utility functions found in this file:

Definition in file Tpetra_Util.hpp.


Define Documentation

#define TPETRA_EFFICIENCY_WARNING (   throw_exception_test,
  Exception,
  msg 
)

Print or throw an efficency warning.

This macro is only for use by Tpetra developers. It is only to be used in the implementation of a Tpetra class' instance method.

If HAVE_TPETRA_THROW_EFFICIENCY_WARNINGS is defined, throw an exception of type Exception, whose exception message will include msg (along with other useful information).

If HAVE_TPETRA_PRINT_EFFICIENCY_WARNINGS is defined, print the given message to std::cerr, along with other useful information.

This macro must be called in an instance method of a class. (Alas, C++ gives us no way to search the scope for a list of defined names. Otherwise, the macro could search for "this" to determine whether it is in a class' instance method.)

Macro arguments:

throw_exception_test: Boolean expression to evaluate. If true, this macro will trigger the efficiency warning. The test will be evaluated at most once. Nevertheless, the test should not have side effects, since it will not be evaluated at all if neither HAVE_TPETRA_THROW_EFFICIENCY_WARNINGS nor HAVE_TPETRA_PRINT_EFFICIENCY_WARNINGS are defined.

Exception: The type of exception to throw, if throw_exception_test evaluates to true and TPETRA_THROWS_EFFICIENCY_WARNINGS is defined. The Exception should be a subclass of std::exception.

msg: The message to include in the warning. The warning also includes the name of the class, and other useful information.

Definition at line 161 of file Tpetra_Util.hpp.

#define TPETRA_ABUSE_WARNING (   throw_exception_test,
  Exception,
  msg 
)

Handle an abuse warning, according to HAVE_TPETRA_THROW_ABUSE_WARNINGS and HAVE_TPETRA_PRINT_ABUSE_WARNINGS.

Definition at line 179 of file Tpetra_Util.hpp.

#define SHARED_TEST_FOR_EXCEPTION (   throw_exception_test,
  Exception,
  msg,
  comm 
)
Value:
{ \
    using Teuchos::outArg; \
    const int lcl_throw_exception = (throw_exception_test) ? Teuchos::rank(comm)+1 : 0; \
    int gbl_throw; \
    Teuchos::reduceAll(comm,Teuchos::REDUCE_MAX,lcl_throw_exception,outArg(gbl_throw)); \
    TEUCHOS_TEST_FOR_EXCEPTION(gbl_throw,Exception,  \
      msg << " Failure on at least one process, including process " << gbl_throw-1 << "." << std::endl); \
}

Test for exception, with reduction over the given communicator.

This is like Teuchos' TEUCHOS_TEST_FOR_EXCEPTION macro, except that it performs an all-reduce over the given communicator to ensure that all processes throw the exception if the test is true on at least one process.

Macro arguments:

throw_exception_test: Boolean expression to evaluate. If true on at least one calling process in the given communicator, this macro will throw an exception of the given type on all processes in the communicator. The exception message may differ on different processes. The expression will only be evaluated once on each process.

Exception: The type of exception to throw, if throw_exception_test evaluates to true on at least one process in the given communicator. The Exception should be a subclass of std::exception.

msg: The message to include in the warning. The warning also includes the name of the class, and the maximum process rank on which the test evaluated to true. The message may be different on different processes.

comm: The communicator (instance of a subclass of Teuchos::Comm<int>) over which to test. This must evaluate to a class instance or reference, not a Teuchos::RCP of an instance.

Definition at line 211 of file Tpetra_Util.hpp.

#define SWITCHED_TEST_FOR_EXCEPTION (   throw_exception_test,
  Exception,
  msg,
  comm 
)
Value:
{ \
    TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test,Exception,msg); \
}

If TEUCHOS_DEBUG is defined, then it calls SHARED_TEST_FOR_EXCEPTION. Otherwise, it calls TEUCHOS_TEST_FOR_EXCEPTION.

Definition at line 229 of file Tpetra_Util.hpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines