42 #ifndef TEUCHOS_DEFAULT_COMM_HPP 43 #define TEUCHOS_DEFAULT_COMM_HPP 46 #include "Teuchos_DefaultSerialComm.hpp" 56 template<
class OrdinalType>
58 mpiFreeDefaultComm (MPI_Comm,
int,
void*,
void*);
60 template<
class OrdinalType>
62 mpiFreeDefaultSerialComm (MPI_Comm,
int,
void*,
void*);
93 template<
typename OrdinalType>
134 Details::mpiFreeDefaultComm (MPI_Comm,
int,
void*,
void*);
139 Details::mpiFreeDefaultSerialComm (MPI_Comm,
int,
void*,
void*);
143 static void freeDefaultComm () {
151 static void freeDefaultSerialComm () {
152 if (defaultSerialComm_ != NULL) {
153 delete defaultSerialComm_;
154 defaultSerialComm_ = NULL;
162 template<
class OrdinalType>
164 mpiFreeDefaultComm (MPI_Comm,
int,
void*,
void*)
171 std::cerr <<
"Teuchos::DefaultComm: Failed to free default Comm! We can't " 172 "throw an exception here because this is a singleton destructor that " 173 "should only be called at MPI_Finalize or (if not building with MPI) at " 174 "exit from main()." << std::endl;
179 return (MPI_SUCCESS == 0) ? -1 : 0;
184 template<
class OrdinalType>
186 mpiFreeDefaultSerialComm (MPI_Comm,
int,
void*,
void*)
193 std::cerr <<
"Teuchos::DefaultComm: Failed to free default serial Comm! " 194 "We can't throw an exception here because this is a singleton destructor " 195 "that should only be called at MPI_Finalize or (if not building with MPI)" 196 " at exit from main()." << std::endl;
201 return (MPI_SUCCESS == 0) ? -1 : 0;
210 template<
typename OrdinalType>
216 comm_ =
new MpiComm<OrdinalType> (MPI_COMM_WORLD);
224 int key = MPI_KEYVAL_INVALID;
226 MPI_Comm_create_keyval (MPI_COMM_NULL_COPY_FN,
227 Details::mpiFreeDefaultComm<OrdinalType>,
230 if (err != MPI_SUCCESS) {
236 "Teuchos::DefaultComm::getComm: MPI_Comm_create_keyval failed!");
241 err = MPI_Comm_set_attr (MPI_COMM_SELF, key, &val);
242 if (err != MPI_SUCCESS) {
256 "Teuchos::DefaultComm::getComm: MPI_Comm_set_attr failed!");
286 (void) MPI_Comm_free_keyval (&key);
288 #else // NOT HAVE_MPI 302 int err = atexit (freeDefaultComm);
309 "Teuchos::DefaultComm::getComm: atexit failed!");
315 (comm_ == NULL, std::logic_error,
"Teuchos::DefaultComm::getComm: " 316 "comm_ == NULL before return. This should never happen. " 317 "Please report this bug to the Teuchos developers.");
322 return rcp (comm_,
false);
325 template<
typename OrdinalType>
330 if (! comm.is_null ()) {
333 if (defaultSerialComm_ == NULL) {
341 int key = MPI_KEYVAL_INVALID;
343 MPI_Comm_create_keyval (MPI_COMM_NULL_COPY_FN,
344 Details::mpiFreeDefaultSerialComm<OrdinalType>,
347 if (err != MPI_SUCCESS) {
348 if (defaultSerialComm_ != NULL) {
349 delete defaultSerialComm_;
350 defaultSerialComm_ = NULL;
353 true, std::runtime_error,
"Teuchos::DefaultComm::getDefaultSerialComm" 354 ": MPI_Comm_create_keyval failed!");
359 err = MPI_Comm_set_attr (MPI_COMM_SELF, key, &val);
360 if (err != MPI_SUCCESS) {
363 if (defaultSerialComm_ != NULL) {
364 delete defaultSerialComm_;
365 defaultSerialComm_ = NULL;
368 true, std::runtime_error,
"Teuchos::DefaultComm::getDefaultSerialComm" 369 ": MPI_Comm_set_attr failed!");
375 (void) MPI_Comm_free_keyval (&key);
377 #else // NOT HAVE_MPI 391 int err = atexit (freeDefaultComm);
393 if (defaultSerialComm_ != NULL) {
394 delete defaultSerialComm_;
395 defaultSerialComm_ = NULL;
398 "Teuchos::DefaultComm::getDefaultSerialComm: atexit failed!");
404 (defaultSerialComm_ == NULL, std::logic_error,
"Teuchos::DefaultComm::" 405 "getDefaultSerialComm: defaultSerialComm_ == NULL before return. This sh" 406 "ould never happen. Please report this bug to the Teuchos developers.");
411 return rcp (defaultSerialComm_,
false);
415 template<
typename OrdinalType>
419 template<
typename OrdinalType>
425 #endif // TEUCHOS_DEFAULT_COMM_HPP static Teuchos::RCP< const Comm< OrdinalType > > getDefaultSerialComm(const Teuchos::RCP< const Comm< OrdinalType > > &comm)
Return a serial Comm if the input Comm is null.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Concrete serial communicator subclass.
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator.
Namespace of implementation details.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Implementation of Teuchos wrappers for MPI.
Return a default global communicator appropriate for the build.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
Smart reference counting pointer class for automatic garbage collection.
Reference-counted pointer class and non-member templated function implementations.