42 #ifndef TEUCHOS_DEFAULT_COMM_HPP
43 #define TEUCHOS_DEFAULT_COMM_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*);
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 # if MPI_VERSION >= 2
218 comm_ =
new MpiComm<OrdinalType> (MPI_COMM_WORLD);
226 int key = MPI_KEYVAL_INVALID;
228 MPI_Comm_create_keyval (MPI_COMM_NULL_COPY_FN,
229 Details::mpiFreeDefaultComm<OrdinalType>,
232 if (err != MPI_SUCCESS) {
238 "Teuchos::DefaultComm::getComm: MPI_Comm_create_keyval failed!");
243 err = MPI_Comm_set_attr (MPI_COMM_SELF, key, &val);
244 if (err != MPI_SUCCESS) {
258 "Teuchos::DefaultComm::getComm: MPI_Comm_set_attr failed!");
288 (void) MPI_Comm_free_keyval (&key);
290 # else // MPI_VERSION < 2
291 # error "Sorry, you need an MPI implementation that supports at least MPI 2.0 in order to build this code. MPI 2.0 came out in 1997. I wrote this comment in 2017. If you really _really_ want MPI 1.x support, please file a GitHub issue for this feature request at github.com/trilinos/trilinos/issues with an expression of its priority and we will get to it as soon as we can."
292 # endif // MPI_VERSION >= 2
294 #else // NOT HAVE_MPI
308 int err = atexit (freeDefaultComm);
315 "Teuchos::DefaultComm::getComm: atexit failed!");
321 (comm_ == NULL, std::logic_error,
"Teuchos::DefaultComm::getComm: "
322 "comm_ == NULL before return. This should never happen. "
323 "Please report this bug to the Teuchos developers.");
328 return rcp (comm_,
false);
331 template<
typename OrdinalType>
336 if (! comm.is_null ()) {
339 if (defaultSerialComm_ == NULL) {
341 # if MPI_VERSION >= 2
348 int key = MPI_KEYVAL_INVALID;
350 MPI_Comm_create_keyval (MPI_COMM_NULL_COPY_FN,
351 Details::mpiFreeDefaultSerialComm<OrdinalType>,
354 if (err != MPI_SUCCESS) {
355 if (defaultSerialComm_ != NULL) {
356 delete defaultSerialComm_;
357 defaultSerialComm_ = NULL;
360 true, std::runtime_error,
"Teuchos::DefaultComm::getDefaultSerialComm"
361 ": MPI_Comm_create_keyval failed!");
366 err = MPI_Comm_set_attr (MPI_COMM_SELF, key, &val);
367 if (err != MPI_SUCCESS) {
370 if (defaultSerialComm_ != NULL) {
371 delete defaultSerialComm_;
372 defaultSerialComm_ = NULL;
375 true, std::runtime_error,
"Teuchos::DefaultComm::getDefaultSerialComm"
376 ": MPI_Comm_set_attr failed!");
382 (void) MPI_Comm_free_keyval (&key);
384 # else // MPI_VERSION < 2
385 # error "Sorry, you need an MPI implementation that supports at least MPI 2.0 in order to build this code. MPI 2.0 came out in 1997. I wrote this comment in 2017. If you really _really_ want MPI 1.x support, please file a GitHub issue for this feature request at github.com/trilinos/trilinos/issues with an expression of its priority and we will get to it as soon as we can."
386 # endif // MPI_VERSION >= 2
388 #else // NOT HAVE_MPI
402 int err = atexit (freeDefaultComm);
404 if (defaultSerialComm_ != NULL) {
405 delete defaultSerialComm_;
406 defaultSerialComm_ = NULL;
409 "Teuchos::DefaultComm::getDefaultSerialComm: atexit failed!");
415 (defaultSerialComm_ == NULL, std::logic_error,
"Teuchos::DefaultComm::"
416 "getDefaultSerialComm: defaultSerialComm_ == NULL before return. This sh"
417 "ould never happen. Please report this bug to the Teuchos developers.");
422 return rcp (defaultSerialComm_,
false);
426 template<
typename OrdinalType>
430 template<
typename OrdinalType>
436 #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.
static const Comm< OrdinalType > * defaultSerialComm_
A "serial" communicator (containing one process, whose rank is zero).
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
static const Comm< OrdinalType > * comm_
The default global communicator.
Concrete serial communicator subclass.
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator.
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.
static void freeDefaultSerialComm()
Free the default serial Comm object.
Abstract interface for distributed-memory communication.
Smart reference counting pointer class for automatic garbage collection.
Reference-counted pointer class and non-member templated function implementations.
static void freeDefaultComm()
Free the default Comm object.