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 
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 
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
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
Nonowning array view.
Encapsulation of a pending nonblocking communication operation.
virtual ~CommRequest()
Destructor; cancels the request if it is still pending.
virtual RCP< CommStatus< OrdinalType > > wait()=0
Wait on this request (a blocking operation).
Encapsulation of the result of a receive (blocking or nonblocking).
virtual OrdinalType getSourceRank()=0
The source rank that sent the message.
virtual ~CommStatus()
Destructor (declared virtual for memory safety)
virtual OrdinalType getTag()=0
The tag of the received message.
Abstract interface for distributed-memory communication.
virtual RCP< CommRequest< Ordinal > > isend(const ArrayView< const char > &sendBuffer, const int destRank, const int tag) const =0
Variant of isend() that takes a tag.
virtual void broadcast(const int rootRank, const Ordinal bytes, char buffer[]) const =0
Broadcast values from the root process to the slave processes.
virtual void gather(const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvBytes, char recvBuffer[], const int root) const =0
Gather values from all processes to the root process.
virtual void waitAll(const ArrayView< RCP< CommRequest< Ordinal > > > &requests) const =0
Wait on a set of communication requests.
virtual void readySend(const ArrayView< const char > &sendBuffer, const int destRank) const =0
Ready send of data from this process to another process.
virtual RCP< Comm > duplicate() const =0
Duplicate this communicator.
virtual void reduceAll(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char globalReducts[]) const =0
Global reduction.
virtual ~Comm()
Destructor, declared virtual for safety of derived classes.
virtual int getSize() const =0
Returns the number of processes that make up this communicator.
virtual void gatherAll(const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvBytes, char recvBuffer[]) const =0
Gather values from each process to collect on all processes.
virtual RCP< CommRequest< Ordinal > > isend(const ArrayView< const char > &sendBuffer, const int destRank) const =0
Non-blocking send.
virtual void ssend(const Ordinal bytes, const char sendBuffer[], const int destRank, const int tag) const =0
Variant of ssend() that takes a message tag.
virtual RCP< CommRequest< Ordinal > > ireceive(const ArrayView< char > &recvBuffer, const int sourceRank) const =0
Non-blocking receive.
virtual void send(const Ordinal bytes, const char sendBuffer[], const int destRank) const =0
Possibly blocking send of data from this process to another process.
virtual void scan(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char scanReducts[]) const =0
Scan reduction.
virtual RCP< CommStatus< Ordinal > > wait(const Ptr< RCP< CommRequest< Ordinal > > > &request) const =0
Wait on a single communication request, and return its status.
virtual RCP< CommRequest< Ordinal > > ireceive(const ArrayView< char > &recvBuffer, const int sourceRank, const int tag) const =0
Variant of ireceive that takes a tag.
virtual int getTag() const =0
The current tag.
virtual int receive(const int sourceRank, const Ordinal bytes, char recvBuffer[]) const =0
Blocking receive of data from this process to another process.
virtual RCP< Comm > split(const int color, const int key) const =0
Split a communicator into subcommunicators based on color and key.
virtual void ssend(const Ordinal bytes, const char sendBuffer[], const int destRank) const =0
Always blocking send of data from this process to another process.
virtual int getRank() const =0
Returns the rank of this process.
virtual void readySend(const Ordinal bytes, const char sendBuffer[], const int destRank, const int tag) const =0
Variant of readySend() that accepts a message tag.
virtual RCP< Comm > createSubcommunicator(const ArrayView< const int > &ranks) const =0
Create a subcommunicator containing the specified processes.
virtual void barrier() const =0
Pause every process in *this communicator until all the processes reach this point.
virtual void waitAll(const ArrayView< RCP< CommRequest< Ordinal > > > &requests, const ArrayView< RCP< CommStatus< Ordinal > > > &statuses) const =0
Wait on communication requests, and return their statuses.
virtual void send(const Ordinal bytes, const char sendBuffer[], const int destRank, const int tag) const =0
Variant of send() that takes a tag.
Base class for all objects that can describe themselves.
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,...