10 #ifndef TEUCHOS_DEFAULT_COMM_HPP
11 #define TEUCHOS_DEFAULT_COMM_HPP
14 #include "Teuchos_DefaultSerialComm.hpp"
24 template<
class OrdinalType>
26 mpiFreeDefaultComm (MPI_Comm,
int,
void*,
void*);
28 template<
class OrdinalType>
30 mpiFreeDefaultSerialComm (MPI_Comm,
int,
void*,
void*);
61 template<
typename OrdinalType>
102 Details::mpiFreeDefaultComm (MPI_Comm,
int,
void*,
void*);
107 Details::mpiFreeDefaultSerialComm (MPI_Comm,
int,
void*,
void*);
111 static void freeDefaultComm () {
119 static void freeDefaultSerialComm () {
120 if (defaultSerialComm_ != NULL) {
121 delete defaultSerialComm_;
122 defaultSerialComm_ = NULL;
130 template<
class OrdinalType>
132 mpiFreeDefaultComm (MPI_Comm,
int,
void*,
void*)
139 std::cerr <<
"Teuchos::DefaultComm: Failed to free default Comm! We can't "
140 "throw an exception here because this is a singleton destructor that "
141 "should only be called at MPI_Finalize or (if not building with MPI) at "
142 "exit from main()." << std::endl;
147 return (MPI_SUCCESS == 0) ? -1 : 0;
152 template<
class OrdinalType>
154 mpiFreeDefaultSerialComm (MPI_Comm,
int,
void*,
void*)
161 std::cerr <<
"Teuchos::DefaultComm: Failed to free default serial Comm! "
162 "We can't throw an exception here because this is a singleton destructor "
163 "that should only be called at MPI_Finalize or (if not building with MPI)"
164 " at exit from main()." << std::endl;
169 return (MPI_SUCCESS == 0) ? -1 : 0;
178 template<
typename OrdinalType>
184 # if MPI_VERSION >= 2
186 comm_ =
new MpiComm<OrdinalType> (MPI_COMM_WORLD);
194 int key = MPI_KEYVAL_INVALID;
196 MPI_Comm_create_keyval (MPI_COMM_NULL_COPY_FN,
197 Details::mpiFreeDefaultComm<OrdinalType>,
200 if (err != MPI_SUCCESS) {
206 "Teuchos::DefaultComm::getComm: MPI_Comm_create_keyval failed!");
211 err = MPI_Comm_set_attr (MPI_COMM_SELF, key, &val);
212 if (err != MPI_SUCCESS) {
226 "Teuchos::DefaultComm::getComm: MPI_Comm_set_attr failed!");
256 (void) MPI_Comm_free_keyval (&key);
258 # else // MPI_VERSION < 2
259 # 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."
260 # endif // MPI_VERSION >= 2
262 #else // NOT HAVE_MPI
276 int err = atexit (freeDefaultComm);
283 "Teuchos::DefaultComm::getComm: atexit failed!");
289 (comm_ == NULL, std::logic_error,
"Teuchos::DefaultComm::getComm: "
290 "comm_ == NULL before return. This should never happen. "
291 "Please report this bug to the Teuchos developers.");
296 return rcp (comm_,
false);
299 template<
typename OrdinalType>
304 if (! comm.is_null ()) {
307 if (defaultSerialComm_ == NULL) {
309 # if MPI_VERSION >= 2
316 int key = MPI_KEYVAL_INVALID;
318 MPI_Comm_create_keyval (MPI_COMM_NULL_COPY_FN,
319 Details::mpiFreeDefaultSerialComm<OrdinalType>,
322 if (err != MPI_SUCCESS) {
323 if (defaultSerialComm_ != NULL) {
324 delete defaultSerialComm_;
325 defaultSerialComm_ = NULL;
328 true, std::runtime_error,
"Teuchos::DefaultComm::getDefaultSerialComm"
329 ": MPI_Comm_create_keyval failed!");
334 err = MPI_Comm_set_attr (MPI_COMM_SELF, key, &val);
335 if (err != MPI_SUCCESS) {
338 if (defaultSerialComm_ != NULL) {
339 delete defaultSerialComm_;
340 defaultSerialComm_ = NULL;
343 true, std::runtime_error,
"Teuchos::DefaultComm::getDefaultSerialComm"
344 ": MPI_Comm_set_attr failed!");
350 (void) MPI_Comm_free_keyval (&key);
352 # else // MPI_VERSION < 2
353 # 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."
354 # endif // MPI_VERSION >= 2
356 #else // NOT HAVE_MPI
370 int err = atexit (freeDefaultComm);
372 if (defaultSerialComm_ != NULL) {
373 delete defaultSerialComm_;
374 defaultSerialComm_ = NULL;
377 "Teuchos::DefaultComm::getDefaultSerialComm: atexit failed!");
383 (defaultSerialComm_ == NULL, std::logic_error,
"Teuchos::DefaultComm::"
384 "getDefaultSerialComm: defaultSerialComm_ == NULL before return. This sh"
385 "ould never happen. Please report this bug to the Teuchos developers.");
390 return rcp (defaultSerialComm_,
false);
394 template<
typename OrdinalType>
398 template<
typename OrdinalType>
404 #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.
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.
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.