Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_DefaultMpiComm_decl.hpp
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TEUCHOS_DEFAULTMPICOMM_DECL_HPP
11#define TEUCHOS_DEFAULTMPICOMM_DECL_HPP
12
13#include "Teuchos_Comm.hpp"
14
15namespace Teuchos {
16
28template<class OrdinalType>
29class MpiCommStatus : public CommStatus<OrdinalType> {
30public:
32
34 virtual ~MpiCommStatus();
35
38
41
44
45private:
48
50 MPI_Status status_;
51};
52
56template<class OrdinalType>
58mpiCommStatus (MPI_Status rawMpiStatus);
59
75template<class OrdinalType>
76class MpiCommRequestBase : public CommRequest<OrdinalType> {
77public:
80
83
92
94 bool isNull() const;
95
96 bool isReady();
97
104
110
113
114private:
116 MPI_Request rawMpiRequest_;
117};
118
119
135template<class OrdinalType>
159
168template<class OrdinalType>
170mpiCommRequest (MPI_Request rawMpiRequest,
171 const ArrayView<char>::size_type numBytes);
172
188template<typename Ordinal>
189class MpiComm : public Comm<Ordinal> {
190public:
192
193
215
231
250 const int defaultTag);
251
268 MpiComm (const MpiComm<Ordinal>& other);
269
272 return rawMpiComm_;
273 }
274
340
342
344
346 virtual int getRank() const;
347
349 virtual int getSize() const;
350
352 virtual void barrier() const;
353
355 virtual void broadcast(
356 const int rootRank, const Ordinal bytes, char buffer[]
357 ) const;
358
360 virtual void
361 gather (const Ordinal sendBytes, const char sendBuffer[],
362 const Ordinal recvBytes, char recvBuffer[],
363 const int root) const;
365 virtual void gatherAll(
366 const Ordinal sendBytes, const char sendBuffer[]
367 ,const Ordinal recvBytes, char recvBuffer[]
368 ) const;
370 virtual void reduceAll(
372 ,const Ordinal bytes, const char sendBuffer[], char globalReducts[]
373 ) const;
375 virtual void scan(
377 ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
378 ) const;
380 virtual void send(
381 const Ordinal bytes, const char sendBuffer[], const int destRank
382 ) const;
384 virtual void
385 send (const Ordinal bytes,
386 const char sendBuffer[],
387 const int destRank,
388 const int tag) const;
390 virtual void ssend(
391 const Ordinal bytes, const char sendBuffer[], const int destRank
392 ) const;
394 virtual void
395 ssend (const Ordinal bytes,
396 const char sendBuffer[],
397 const int destRank,
398 const int tag) const;
400 virtual int receive(
401 const int sourceRank, const Ordinal bytes, char recvBuffer[]
402 ) const;
404 virtual void readySend(
406 const int destRank
407 ) const;
409 virtual void
410 readySend (const Ordinal bytes,
411 const char sendBuffer[],
412 const int destRank,
413 const int tag) const;
417 const int destRank
418 ) const;
422 const int destRank,
423 const int tag) const;
426 const ArrayView<char> &Buffer,
427 const int sourceRank
428 ) const;
432 const int sourceRank,
433 const int tag) const;
435 virtual void waitAll(
437 ) const;
439 virtual void
441 const ArrayView<RCP<CommStatus<Ordinal> > >& statuses) const;
446 virtual RCP< Comm<Ordinal> > duplicate() const;
448 virtual RCP< Comm<Ordinal> > split(const int color, const int key) const;
451 const ArrayView<const int>& ranks) const;
452
454
456
458 std::string description() const;
459
461
462 // These should be private but the PGI compiler requires them be public
463
464 static int const minTag_ = 26000; // These came from Teuchos::MpiComm???
465 static int const maxTag_ = 26099; // ""
466
472 int getTag () const { return tag_; }
473
475 ++tag_;
476 // Wrap at MPI_TAG_UB, NOT std::numeric_limits<int>::max(). The tag is
477 // passed straight to MPI_Isend/Irecv, and MPI rejects any tag above
478 // MPI_TAG_UB with MPI_ERR_TAG. MPI_TAG_UB is far below INT_MAX on real
479 // implementations (e.g. 2^23-1 = 8388607 on OpenMPI), so wrapping only
480 // at INT_MAX let the tag climb out of the valid range: the Tpetra
481 // Distributor calls this once per communication round, and a long run
482 // (~8.4M rounds) eventually aborts mid-solve with MPI_ERR_TAG. tagUb_
483 // is the queried MPI_TAG_UB (see setupMembersFromComm); wrapping back
484 // to minTag_ keeps the tag valid and matches the documented intent of
485 // "loop around back to a small value".
486 if (tag_ >= tagUb_)
487 tag_ = minTag_;
488 return tag_;
489 }
490
491private:
492
496 void setupMembersFromComm();
497 static int tagCounter_;
498
507
509 int rank_;
510
512 int size_;
513
521 int tag_;
522
528 int tagUb_ = 32767;
529
531 RCP<const OpaqueWrapper<MPI_Errhandler> > customErrorHandler_;
532
533 void assertRank(const int rank, const std::string &rankName) const;
534
535 // Not defined and not to be called!
536 MpiComm();
537
538#ifdef TEUCHOS_MPI_COMM_DUMP
539public:
540 static bool show_dump;
541#endif // TEUCHOS_MPI_COMM_DUMP
542
543};
544
545
559template<typename Ordinal>
560RCP<MpiComm<Ordinal> >
563 );
564
565
579template<typename Ordinal>
583 const int defaultTag
584 );
585
586
614template<typename Ordinal>
617
618}
619
620#endif
Nonowning array view.
Ordinal size_type
Type representing the number of elements in an ArrayRCP or view thereof.
Abstract interface for distributed-memory communication.
int rank(const Comm< Ordinal > &comm)
Get the process rank.
Encapsulation of a pending nonblocking communication operation.
Encapsulation of the result of a receive (blocking or nonblocking).
Implementation of Comm that uses MPI for communication.
virtual void reduceAll(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char globalReducts[]) const
MpiComm(const RCP< const OpaqueWrapper< MPI_Comm > > &rawMpiComm, const int defaultTag)
Construct an MpiComm with a wrapped MPI_Comm and a default tag.
virtual RCP< Comm< Ordinal > > createSubcommunicator(const ArrayView< const int > &ranks) const
MpiComm(const RCP< const OpaqueWrapper< MPI_Comm > > &rawMpiComm)
Construct an MpiComm with the given wrapped MPI_Comm.
RCP< MpiComm< Ordinal > > createMpiComm(const RCP< const OpaqueWrapper< MPI_Comm > > &rawMpiComm)
Helper function that creates a dynamically allocated MpiComm object or returns Teuchos::null to corre...
virtual RCP< CommRequest< Ordinal > > isend(const ArrayView< const char > &sendBuffer, const int destRank) const
int incrementTag()
Increments the tag and then returns it.
std::string description() const
int getTag() const
The current tag.
virtual void send(const Ordinal bytes, const char sendBuffer[], const int destRank, const int tag) const
virtual int getSize() const
The number of processes in the communicator.
virtual void readySend(const ArrayView< const char > &sendBuffer, const int destRank) const
virtual int receive(const int sourceRank, const Ordinal bytes, char recvBuffer[]) const
MPI_Comm getRawMpiComm(const Comm< Ordinal > &comm)
Helper function that extracts a raw MPI_Comm object out of a Teuchos::MpiComm wrapper object.
virtual void waitAll(const ArrayView< RCP< CommRequest< Ordinal > > > &requests) const
virtual RCP< CommRequest< Ordinal > > ireceive(const ArrayView< char > &Buffer, const int sourceRank) const
virtual void gatherAll(const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvBytes, char recvBuffer[]) const
virtual void ssend(const Ordinal bytes, const char sendBuffer[], const int destRank, const int tag) const
Variant of ssend() that takes a message tag.
virtual RCP< Comm< Ordinal > > split(const int color, const int key) const
RCP< const OpaqueWrapper< MPI_Comm > > getRawMpiComm() const
Return the embedded wrapped opaque MPI_Comm object.
virtual RCP< Comm< Ordinal > > duplicate() const
virtual void gather(const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvBytes, char recvBuffer[], const int root) const
Gather values from all processes to the root process.
virtual int getRank() const
The calling process' rank.
MpiComm(MPI_Comm rawMpiComm)
Construct an MpiComm with an MPI_Comm.
virtual void waitAll(const ArrayView< RCP< CommRequest< Ordinal > > > &requests, const ArrayView< RCP< CommStatus< Ordinal > > > &statuses) const
virtual void send(const Ordinal bytes, const char sendBuffer[], const int destRank) const
virtual RCP< CommRequest< Ordinal > > ireceive(const ArrayView< char > &Buffer, const int sourceRank, const int tag) const
MpiComm(const MpiComm< Ordinal > &other)
Construct a communicator with a new context with the same properties as the original.
RCP< MpiComm< Ordinal > > createMpiComm(const RCP< const OpaqueWrapper< MPI_Comm > > &rawMpiComm, const int defaultTag)
Helper function that creates a dynamically allocated MpiComm object or returns Teuchos::null to corre...
virtual RCP< CommStatus< Ordinal > > wait(const Ptr< RCP< CommRequest< Ordinal > > > &request) const
virtual void scan(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char scanReducts[]) const
virtual void ssend(const Ordinal bytes, const char sendBuffer[], const int destRank) const
void setErrorHandler(const RCP< const OpaqueWrapper< MPI_Errhandler > > &errHandler)
Set the MPI error handler for this communicator.
virtual void barrier() const
Execute a barrier; must be called collectively.
virtual void broadcast(const int rootRank, const Ordinal bytes, char buffer[]) const
virtual RCP< CommRequest< Ordinal > > isend(const ArrayView< const char > &sendBuffer, const int destRank, const int tag) const
Variant of isend() that takes a tag.
virtual void readySend(const Ordinal bytes, const char sendBuffer[], const int destRank, const int tag) const
Variant of readySend() that accepts a message tag.
Base class MPI implementation of CommRequest.
RCP< CommStatus< OrdinalType > > wait()
Wait on this communication request to complete.
bool isNull() const
Whether the raw MPI_Request is MPI_REQUEST_NULL.
RCP< CommStatus< OrdinalType > > cancel()
Cancel the communication request, and return its status.
virtual ~MpiCommRequestBase()
Destructor; cancels the request if it is still pending.
MpiCommRequestBase()
Default constructor.
MPI_Request releaseRawMpiRequest()
Return and relinquish ownership of the raw MPI_Request.
MpiCommRequestBase(MPI_Request rawMpiRequest)
Constructor (from a raw MPI_Request).
MPI implementation of CommRequest.
MpiCommRequest(MPI_Request rawMpiRequest, const ArrayView< char >::size_type numBytesInMessage)
Constructor (from a raw MPI_Request).
virtual ~MpiCommRequest()
Destructor; cancels the request if it is still pending.
MpiCommRequest()
Default constructor.
ArrayView< char >::size_type numBytes() const
Number of bytes in the nonblocking send or receive request.
MPI-specific implementation of CommStatus.
OrdinalType getSourceRank()
The source rank that sent the message.
virtual ~MpiCommStatus()
Destructor (declared virtual for memory safety)
OrdinalType getTag()
The tag of the received message.
OrdinalType getError()
The error code of the received message.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists.
Smart reference counting pointer class for automatic garbage collection.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...