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
356 alltoAll(const Ordinal sendBytes, const char sendBuffer[],
357 const Ordinal recvBytes, char recvBuffer[]) const;
358
360 virtual void broadcast(
361 const int rootRank, const Ordinal bytes, char buffer[]
362 ) const;
363
365 virtual void
366 gather (const Ordinal sendBytes, const char sendBuffer[],
367 const Ordinal recvBytes, char recvBuffer[],
368 const int root) const;
370 virtual void gatherAll(
371 const Ordinal sendBytes, const char sendBuffer[]
372 ,const Ordinal recvBytes, char recvBuffer[]
373 ) const;
375 virtual void reduceAll(
377 ,const Ordinal bytes, const char sendBuffer[], char globalReducts[]
378 ) const;
380 virtual void scan(
382 ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
383 ) const;
385 virtual void send(
386 const Ordinal bytes, const char sendBuffer[], const int destRank
387 ) const;
389 virtual void
390 send (const Ordinal bytes,
391 const char sendBuffer[],
392 const int destRank,
393 const int tag) const;
395 virtual void ssend(
396 const Ordinal bytes, const char sendBuffer[], const int destRank
397 ) const;
399 virtual void
400 ssend (const Ordinal bytes,
401 const char sendBuffer[],
402 const int destRank,
403 const int tag) const;
405 virtual int receive(
406 const int sourceRank, const Ordinal bytes, char recvBuffer[]
407 ) const;
409 virtual void readySend(
411 const int destRank
412 ) const;
414 virtual void
415 readySend (const Ordinal bytes,
416 const char sendBuffer[],
417 const int destRank,
418 const int tag) const;
422 const int destRank
423 ) const;
427 const int destRank,
428 const int tag) const;
431 const ArrayView<char> &Buffer,
432 const int sourceRank
433 ) const;
437 const int sourceRank,
438 const int tag) const;
440 virtual void waitAll(
442 ) const;
444 virtual void
446 const ArrayView<RCP<CommStatus<Ordinal> > >& statuses) const;
451 virtual RCP< Comm<Ordinal> > duplicate() const;
453 virtual RCP< Comm<Ordinal> > split(const int color, const int key) const;
456 const ArrayView<const int>& ranks) const;
457
459
461
463 std::string description() const;
464
466
467 // These should be private but the PGI compiler requires them be public
468
469 static int const minTag_ = 26000; // These came from Teuchos::MpiComm???
470 static int const maxTag_ = 26099; // ""
471
477 int getTag () const { return tag_; }
478
480 ++tag_;
481 // Wrap at MPI_TAG_UB, NOT std::numeric_limits<int>::max(). The tag is
482 // passed straight to MPI_Isend/Irecv, and MPI rejects any tag above
483 // MPI_TAG_UB with MPI_ERR_TAG. MPI_TAG_UB is far below INT_MAX on real
484 // implementations (e.g. 2^23-1 = 8388607 on OpenMPI), so wrapping only
485 // at INT_MAX let the tag climb out of the valid range: the Tpetra
486 // Distributor calls this once per communication round, and a long run
487 // (~8.4M rounds) eventually aborts mid-solve with MPI_ERR_TAG. tagUb_
488 // is the queried MPI_TAG_UB (see setupMembersFromComm); wrapping back
489 // to minTag_ keeps the tag valid and matches the documented intent of
490 // "loop around back to a small value".
491 if (tag_ >= tagUb_)
492 tag_ = minTag_;
493 return tag_;
494 }
495
496private:
497
501 void setupMembersFromComm();
502 static int tagCounter_;
503
512
514 int rank_;
515
517 int size_;
518
526 int tag_;
527
533 int tagUb_ = 32767;
534
536 RCP<const OpaqueWrapper<MPI_Errhandler> > customErrorHandler_;
537
538 void assertRank(const int rank, const std::string &rankName) const;
539
540 // Not defined and not to be called!
541 MpiComm();
542
543#ifdef TEUCHOS_MPI_COMM_DUMP
544public:
545 static bool show_dump;
546#endif // TEUCHOS_MPI_COMM_DUMP
547
548};
549
550
564template<typename Ordinal>
565RCP<MpiComm<Ordinal> >
568 );
569
570
584template<typename Ordinal>
588 const int defaultTag
589 );
590
591
619template<typename Ordinal>
622
623}
624
625#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 void alltoAll(const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvBytes, char recvBuffer[]) const
Scatter values from all processes to all processes.
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,...