Teuchos - Trilinos Tools Package  Version of the Day
Teuchos_Comm.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef TEUCHOS_COMM_HPP
43 #define TEUCHOS_COMM_HPP
44 
45 #include "Teuchos_ReductionOp.hpp"
46 #include "Teuchos_ArrayRCP.hpp"
47 
48 
49 namespace Teuchos {
50 
70 template<class OrdinalType>
71 class CommStatus {
72 public:
74  virtual ~CommStatus() {}
75 
77  virtual OrdinalType getSourceRank () = 0;
78 
80  virtual OrdinalType getTag () = 0;
81 };
82 
83 // Forward declaration for CommRequest::wait.
84 template<class OrdinalType>
85 class Comm;
86 
136 template<class OrdinalType>
138 public:
146  virtual ~CommRequest() {}
147 
149  virtual RCP<CommStatus<OrdinalType> > wait () = 0;
150 };
151 
309 template<typename Ordinal>
310 class Comm : virtual public Describable {
311 public:
317  virtual int getTag () const = 0;
318 
320 
321 
323  virtual ~Comm() {}
325 
327 
328 
335  virtual int getRank() const = 0;
336 
343  virtual int getSize() const = 0;
344 
346 
348 
349 
353  virtual void barrier() const = 0;
354 
369  virtual void broadcast(
370  const int rootRank, const Ordinal bytes, char buffer[]
371  ) const = 0;
372 
374  virtual void
375  gather (const Ordinal sendBytes, const char sendBuffer[],
376  const Ordinal recvBytes, char recvBuffer[],
377  const int root) const = 0;
378 
401  virtual void gatherAll(
402  const Ordinal sendBytes, const char sendBuffer[]
403  ,const Ordinal recvBytes, char recvBuffer[]
404  ) const = 0;
405 
419  virtual void reduceAll(
420  const ValueTypeReductionOp<Ordinal,char> &reductOp
421  ,const Ordinal bytes, const char sendBuffer[], char globalReducts[]
422  ) const = 0;
423 
447  TEUCHOS_DEPRECATED virtual void reduceAllAndScatter(
448  const ValueTypeReductionOp<Ordinal,char> &reductOp
449  ,const Ordinal sendBytes, const char sendBuffer[]
450  ,const Ordinal recvCounts[], char myGlobalReducts[]
451  ) const = 0;
452 
466  virtual void scan(
467  const ValueTypeReductionOp<Ordinal,char> &reductOp
468  ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
469  ) const = 0;
470 
472 
473 
494  virtual void send(
495  const Ordinal bytes, const char sendBuffer[], const int destRank
496  ) const = 0;
497 
499  virtual void
500  send (const Ordinal bytes,
501  const char sendBuffer[],
502  const int destRank,
503  const int tag) const = 0;
504 
524  virtual void ssend(
525  const Ordinal bytes, const char sendBuffer[], const int destRank
526  ) const = 0;
527 
529  virtual void
530  ssend (const Ordinal bytes,
531  const char sendBuffer[],
532  const int destRank,
533  const int tag) const = 0;
534 
555  virtual int receive(
556  const int sourceRank, const Ordinal bytes, char recvBuffer[]
557  ) const = 0;
558 
559 
571  virtual void readySend(
572  const ArrayView<const char> &sendBuffer,
573  const int destRank
574  ) const = 0;
575 
577  virtual void
578  readySend (const Ordinal bytes,
579  const char sendBuffer[],
580  const int destRank,
581  const int tag) const = 0;
582 
584 
586 
598  virtual RCP<CommRequest<Ordinal> > isend(
599  const ArrayView<const char> &sendBuffer,
600  const int destRank
601  ) const = 0;
602 
604  virtual RCP<CommRequest<Ordinal> >
605  isend (const ArrayView<const char> &sendBuffer,
606  const int destRank,
607  const int tag) const = 0;
608 
624  const ArrayView<char> &recvBuffer,
625  const int sourceRank
626  ) const = 0;
627 
629  virtual RCP<CommRequest<Ordinal> >
630  ireceive (const ArrayView<char> &recvBuffer,
631  const int sourceRank,
632  const int tag) const = 0;
633 
644  virtual void waitAll(
645  const ArrayView<RCP<CommRequest<Ordinal> > > &requests
646  ) const = 0;
647 
664  virtual void
665  waitAll (const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
666  const ArrayView<RCP<CommStatus<Ordinal> > >& statuses) const = 0;
667 
691  virtual RCP<CommStatus<Ordinal> >
692  wait (const Ptr<RCP<CommRequest<Ordinal> > >& request) const = 0;
693 
695 
697 
698 
766  virtual RCP< Comm > duplicate() const = 0;
767 
805  virtual RCP<Comm> split (const int color, const int key) const = 0;
806 
829  virtual RCP<Comm>
830  createSubcommunicator (const ArrayView<const int>& ranks) const = 0;
832 
833 }; // class Comm
834 
835 } // namespace Teuchos
836 
837 #endif // TEUCHOS_COMM_HPP
virtual ~CommRequest()
Destructor; cancels the request if it is still pending.
virtual ~Comm()
Destructor, declared virtual for safety of derived classes.
TEUCHOS_DEPRECATED void scan(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *scanReduct)
Deprecated.
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
Deprecated .
Encapsulation of the result of a receive (blocking or nonblocking).
void send(const Packet sendBuffer[], const Ordinal count, const int destRank, const int tag, const Comm< Ordinal > &comm)
Variant of send() that takes a tag (and restores the correct order of arguments). ...
virtual ~CommStatus()
Destructor (declared virtual for memory safety)
RCP< CommRequest< Ordinal > > ireceive(const ArrayRCP< Packet > &recvBuffer, const int sourceRank, const int tag, const Comm< Ordinal > &comm)
Variant of ireceive that takes a tag argument (and restores the correct order of arguments).
Abstract interface for distributed-memory communication.
Nonowning array view.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
virtual OrdinalType getTag()=0
The tag of the received message.
void ssend(const Packet sendBuffer[], const Ordinal count, const int destRank, const int tag, const Comm< Ordinal > &comm)
Variant of ssend() that takes a tag (and restores the correct order of arguments).
Base class for all objects that can describe themselves.
virtual OrdinalType getSourceRank()=0
The source rank that sent the message.
Smart reference counting pointer class for automatic garbage collection.
Encapsulation of a pending nonblocking communication operation.
void readySend(const Packet sendBuffer[], const Ordinal count, const int destRank, const int tag, const Comm< Ordinal > &comm)
Variant of readySend() that accepts a message tag.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...