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 
311 template<typename Ordinal>
312 class Comm : virtual public Describable {
313 public:
319  virtual int getTag () const = 0;
320 
322 
323 
325  virtual ~Comm() {}
327 
329 
330 
337  virtual int getRank() const = 0;
338 
345  virtual int getSize() const = 0;
346 
348 
350 
351 
355  virtual void barrier() const = 0;
356 
371  virtual void broadcast(
372  const int rootRank, const Ordinal bytes, char buffer[]
373  ) const = 0;
374 
376  virtual void
377  gather (const Ordinal sendBytes, const char sendBuffer[],
378  const Ordinal recvBytes, char recvBuffer[],
379  const int root) const = 0;
380 
403  virtual void gatherAll(
404  const Ordinal sendBytes, const char sendBuffer[]
405  ,const Ordinal recvBytes, char recvBuffer[]
406  ) const = 0;
407 
421  virtual void reduceAll(
422  const ValueTypeReductionOp<Ordinal,char> &reductOp
423  ,const Ordinal bytes, const char sendBuffer[], char globalReducts[]
424  ) const = 0;
425 
439  virtual void scan(
440  const ValueTypeReductionOp<Ordinal,char> &reductOp
441  ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
442  ) const = 0;
443 
445 
446 
467  virtual void send(
468  const Ordinal bytes, const char sendBuffer[], const int destRank
469  ) const = 0;
470 
472  virtual void
473  send (const Ordinal bytes,
474  const char sendBuffer[],
475  const int destRank,
476  const int tag) const = 0;
477 
497  virtual void ssend(
498  const Ordinal bytes, const char sendBuffer[], const int destRank
499  ) const = 0;
500 
502  virtual void
503  ssend (const Ordinal bytes,
504  const char sendBuffer[],
505  const int destRank,
506  const int tag) const = 0;
507 
528  virtual int receive(
529  const int sourceRank, const Ordinal bytes, char recvBuffer[]
530  ) const = 0;
531 
532 
544  virtual void readySend(
545  const ArrayView<const char> &sendBuffer,
546  const int destRank
547  ) const = 0;
548 
550  virtual void
551  readySend (const Ordinal bytes,
552  const char sendBuffer[],
553  const int destRank,
554  const int tag) const = 0;
555 
557 
559 
572  const ArrayView<const char> &sendBuffer,
573  const int destRank
574  ) const = 0;
575 
577  virtual RCP<CommRequest<Ordinal> >
578  isend (const ArrayView<const char> &sendBuffer,
579  const int destRank,
580  const int tag) const = 0;
581 
597  const ArrayView<char> &recvBuffer,
598  const int sourceRank
599  ) const = 0;
600 
602  virtual RCP<CommRequest<Ordinal> >
603  ireceive (const ArrayView<char> &recvBuffer,
604  const int sourceRank,
605  const int tag) const = 0;
606 
617  virtual void waitAll(
618  const ArrayView<RCP<CommRequest<Ordinal> > > &requests
619  ) const = 0;
620 
637  virtual void
639  const ArrayView<RCP<CommStatus<Ordinal> > >& statuses) const = 0;
640 
664  virtual RCP<CommStatus<Ordinal> >
665  wait (const Ptr<RCP<CommRequest<Ordinal> > >& request) const = 0;
666 
668 
670 
671 
739  virtual RCP< Comm > duplicate() const = 0;
740 
778  virtual RCP<Comm> split (const int color, const int key) const = 0;
779 
802  virtual RCP<Comm>
803  createSubcommunicator (const ArrayView<const int>& ranks) const = 0;
805 
806 }; // class Comm
807 
808 } // namespace Teuchos
809 
810 #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,...