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 
437  virtual void scan(
438  const ValueTypeReductionOp<Ordinal,char> &reductOp
439  ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
440  ) const = 0;
441 
443 
444 
465  virtual void send(
466  const Ordinal bytes, const char sendBuffer[], const int destRank
467  ) const = 0;
468 
470  virtual void
471  send (const Ordinal bytes,
472  const char sendBuffer[],
473  const int destRank,
474  const int tag) const = 0;
475 
495  virtual void ssend(
496  const Ordinal bytes, const char sendBuffer[], const int destRank
497  ) const = 0;
498 
500  virtual void
501  ssend (const Ordinal bytes,
502  const char sendBuffer[],
503  const int destRank,
504  const int tag) const = 0;
505 
526  virtual int receive(
527  const int sourceRank, const Ordinal bytes, char recvBuffer[]
528  ) const = 0;
529 
530 
542  virtual void readySend(
543  const ArrayView<const char> &sendBuffer,
544  const int destRank
545  ) const = 0;
546 
548  virtual void
549  readySend (const Ordinal bytes,
550  const char sendBuffer[],
551  const int destRank,
552  const int tag) const = 0;
553 
555 
557 
569  virtual RCP<CommRequest<Ordinal> > isend(
570  const ArrayView<const char> &sendBuffer,
571  const int destRank
572  ) const = 0;
573 
575  virtual RCP<CommRequest<Ordinal> >
576  isend (const ArrayView<const char> &sendBuffer,
577  const int destRank,
578  const int tag) const = 0;
579 
595  const ArrayView<char> &recvBuffer,
596  const int sourceRank
597  ) const = 0;
598 
600  virtual RCP<CommRequest<Ordinal> >
601  ireceive (const ArrayView<char> &recvBuffer,
602  const int sourceRank,
603  const int tag) const = 0;
604 
615  virtual void waitAll(
616  const ArrayView<RCP<CommRequest<Ordinal> > > &requests
617  ) const = 0;
618 
635  virtual void
636  waitAll (const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
637  const ArrayView<RCP<CommStatus<Ordinal> > >& statuses) const = 0;
638 
662  virtual RCP<CommStatus<Ordinal> >
663  wait (const Ptr<RCP<CommRequest<Ordinal> > >& request) const = 0;
664 
666 
668 
669 
737  virtual RCP< Comm > duplicate() const = 0;
738 
776  virtual RCP<Comm> split (const int color, const int key) const = 0;
777 
800  virtual RCP<Comm>
801  createSubcommunicator (const ArrayView<const int>& ranks) const = 0;
803 
804 }; // class Comm
805 
806 } // namespace Teuchos
807 
808 #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...