Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_Comm.hpp
Go to the documentation of this file.
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 
148  virtual bool isReady() = 0;
149 
151  virtual RCP<CommStatus<OrdinalType> > wait () = 0;
152 };
153 
313 template<typename Ordinal>
314 class Comm : virtual public Describable {
315 public:
321  virtual int getTag () const = 0;
322 
324 
325 
327  virtual ~Comm() {}
329 
331 
332 
339  virtual int getRank() const = 0;
340 
347  virtual int getSize() const = 0;
348 
350 
352 
353 
357  virtual void barrier() const = 0;
358 
373  virtual void broadcast(
374  const int rootRank, const Ordinal bytes, char buffer[]
375  ) const = 0;
376 
378  virtual void
379  gather (const Ordinal sendBytes, const char sendBuffer[],
380  const Ordinal recvBytes, char recvBuffer[],
381  const int root) const = 0;
382 
405  virtual void gatherAll(
406  const Ordinal sendBytes, const char sendBuffer[]
407  ,const Ordinal recvBytes, char recvBuffer[]
408  ) const = 0;
409 
423  virtual void reduceAll(
424  const ValueTypeReductionOp<Ordinal,char> &reductOp
425  ,const Ordinal bytes, const char sendBuffer[], char globalReducts[]
426  ) const = 0;
427 
441  virtual void scan(
442  const ValueTypeReductionOp<Ordinal,char> &reductOp
443  ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
444  ) const = 0;
445 
447 
448 
469  virtual void send(
470  const Ordinal bytes, const char sendBuffer[], const int destRank
471  ) const = 0;
472 
474  virtual void
475  send (const Ordinal bytes,
476  const char sendBuffer[],
477  const int destRank,
478  const int tag) const = 0;
479 
499  virtual void ssend(
500  const Ordinal bytes, const char sendBuffer[], const int destRank
501  ) const = 0;
502 
504  virtual void
505  ssend (const Ordinal bytes,
506  const char sendBuffer[],
507  const int destRank,
508  const int tag) const = 0;
509 
530  virtual int receive(
531  const int sourceRank, const Ordinal bytes, char recvBuffer[]
532  ) const = 0;
533 
534 
546  virtual void readySend(
547  const ArrayView<const char> &sendBuffer,
548  const int destRank
549  ) const = 0;
550 
552  virtual void
553  readySend (const Ordinal bytes,
554  const char sendBuffer[],
555  const int destRank,
556  const int tag) const = 0;
557 
559 
561 
574  const ArrayView<const char> &sendBuffer,
575  const int destRank
576  ) const = 0;
577 
579  virtual RCP<CommRequest<Ordinal> >
580  isend (const ArrayView<const char> &sendBuffer,
581  const int destRank,
582  const int tag) const = 0;
583 
599  const ArrayView<char> &recvBuffer,
600  const int sourceRank
601  ) const = 0;
602 
604  virtual RCP<CommRequest<Ordinal> >
605  ireceive (const ArrayView<char> &recvBuffer,
606  const int sourceRank,
607  const int tag) const = 0;
608 
619  virtual void waitAll(
620  const ArrayView<RCP<CommRequest<Ordinal> > > &requests
621  ) const = 0;
622 
639  virtual void
640  waitAll (const ArrayView<RCP<CommRequest<Ordinal> > >& requests,
641  const ArrayView<RCP<CommStatus<Ordinal> > >& statuses) const = 0;
642 
666  virtual RCP<CommStatus<Ordinal> >
667  wait (const Ptr<RCP<CommRequest<Ordinal> > >& request) const = 0;
668 
670 
672 
673 
741  virtual RCP< Comm > duplicate() const = 0;
742 
780  virtual RCP<Comm> split (const int color, const int key) const = 0;
781 
804  virtual RCP<Comm>
805  createSubcommunicator (const ArrayView<const int>& ranks) const = 0;
807 
808 }; // class Comm
809 
810 } // namespace Teuchos
811 
812 #endif // TEUCHOS_COMM_HPP
virtual bool isReady()=0
virtual void waitAll(const ArrayView< RCP< CommRequest< Ordinal > > > &requests) const =0
Wait on a set of communication requests.
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 int getSize() const =0
Returns the number of processes that make up this communicator.
virtual int getRank() const =0
Returns the rank of this process.
virtual ~CommRequest()
Destructor; cancels the request if it is still pending.
virtual RCP< Comm > createSubcommunicator(const ArrayView< const int > &ranks) const =0
Create a subcommunicator containing the specified processes.
virtual RCP< Comm > split(const int color, const int key) const =0
Split a communicator into subcommunicators based on color and key.
virtual RCP< CommStatus< Ordinal > > wait(const Ptr< RCP< CommRequest< Ordinal > > > &request) const =0
Wait on a single communication request, and return its status.
virtual int receive(const int sourceRank, const Ordinal bytes, char recvBuffer[]) const =0
Blocking receive of data from this process to another process.
virtual void barrier() const =0
Pause every process in *this communicator until all the processes reach this point.
virtual ~Comm()
Destructor, declared virtual for safety of derived classes.
virtual RCP< CommRequest< Ordinal > > ireceive(const ArrayView< char > &recvBuffer, const int sourceRank) const =0
Non-blocking receive.
virtual void reduceAll(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char globalReducts[]) const =0
Global reduction.
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 RCP< Comm > duplicate() const =0
Duplicate this communicator.
Encapsulation of the result of a receive (blocking or nonblocking).
virtual void readySend(const ArrayView< const char > &sendBuffer, const int destRank) const =0
Ready send of data from this process to another process.
virtual ~CommStatus()
Destructor (declared virtual for memory safety)
virtual void broadcast(const int rootRank, const Ordinal bytes, char buffer[]) const =0
Broadcast values from the root process to the slave processes.
Abstract interface for distributed-memory communication.
Nonowning array view.
virtual OrdinalType getTag()=0
The tag of the received message.
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 ssend(const Ordinal bytes, const char sendBuffer[], const int destRank) const =0
Always blocking send of data from this process to another process.
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.
virtual RCP< CommRequest< Ordinal > > isend(const ArrayView< const char > &sendBuffer, const int destRank) const =0
Non-blocking send.
virtual void scan(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char scanReducts[]) const =0
Scan reduction.
virtual int getTag() const =0
The current tag.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
virtual RCP< CommStatus< OrdinalType > > wait()=0
Wait on this request (a blocking operation).