Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_DefaultSerialComm.hpp
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TEUCHOS_SERIAL_COMM_HPP
11#define TEUCHOS_SERIAL_COMM_HPP
12
13#include "Teuchos_Comm.hpp"
15
16
17namespace Teuchos {
18
25template<class OrdinalType>
26class SerialCommStatus : public CommStatus<OrdinalType> {
27public:
30
32 OrdinalType getSourceRank () { return 0; }
33
35 OrdinalType getTag () { return 0; }
36};
37
38
43template<typename Ordinal>
44class SerialComm : public Comm<Ordinal> {
45public:
51 int getTag () const { return 0; }
52
54
55
57 SerialComm();
58
60 SerialComm(const SerialComm<Ordinal>& other);
61
63
65
66
68 virtual int getRank() const;
70 virtual int getSize() const;
72 virtual void barrier() const;
74 virtual void broadcast(
75 const int rootRank, const Ordinal bytes, char buffer[]
76 ) const;
78 virtual void
79 gather (const Ordinal sendBytes, const char sendBuffer[],
80 const Ordinal recvBytes, char recvBuffer[],
81 const int root) const;
83 virtual void gatherAll(
84 const Ordinal sendBytes, const char sendBuffer[]
85 ,const Ordinal recvBytes, char recvBuffer[]
86 ) const;
88 virtual void reduceAll(
90 ,const Ordinal bytes, const char sendBuffer[], char globalReducts[]
91 ) const;
93 virtual void scan(
95 ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
96 ) const;
98 virtual void send(
99 const Ordinal bytes, const char sendBuffer[], const int destRank
100 ) const;
102 virtual void
103 send (const Ordinal bytes,
104 const char sendBuffer[],
105 const int destRank,
106 const int tag) const;
108 virtual void ssend(
109 const Ordinal bytes, const char sendBuffer[], const int destRank
110 ) const;
112 virtual void
113 ssend (const Ordinal bytes,
114 const char sendBuffer[],
115 const int destRank,
116 const int tag) const;
118 virtual int receive(
119 const int sourceRank, const Ordinal bytes, char recvBuffer[]
120 ) const;
122 virtual void readySend(
124 const int destRank
125 ) const;
127 virtual void
128 readySend (const Ordinal bytes,
129 const char sendBuffer[],
130 const int destRank,
131 const int tag) const;
135 const int destRank
136 ) const;
140 const int destRank,
141 const int tag) const;
144 const ArrayView<char> &Buffer,
145 const int sourceRank
146 ) const;
150 const int sourceRank,
151 const int tag) const;
153 virtual void waitAll(
155 ) const;
157 virtual void
159 const ArrayView<RCP<CommStatus<Ordinal> > >& statuses) const;
162 wait (const Ptr<RCP<CommRequest<Ordinal> > >& request) const;
164 virtual RCP< Comm<Ordinal> > duplicate() const;
166 virtual RCP< Comm<Ordinal> > split(const int color, const int key) const;
169 const ArrayView<const int> & ranks) const;
170
172
174
175
177 std::string description() const;
178
180
181};
182
183
188template<typename Ordinal>
193
194
195// ////////////////////////
196// Implementations
197
198
199// Constructors
200
201
202template<typename Ordinal>
205
206template<typename Ordinal>
209
210
211// Overridden from Comm
212
213
214template<typename Ordinal>
216{
217 return 0;
218}
219
220
221template<typename Ordinal>
223{
224 return 1;
225}
226
227
228template<typename Ordinal>
230{
231 // Nothing to do
232}
233
234
235template<typename Ordinal>
237 const int /*rootRank*/, const Ordinal /*bytes*/, char []/*buffer*/
238 ) const
239{
240 // Nothing to do
241}
242
243
244template<typename Ordinal>
246 const Ordinal sendBytes, const char sendBuffer[]
247 ,const Ordinal recvBytes, char recvBuffer[]
248 ) const
249{
250 (void)sendBytes; // to remove "unused parameter" warning
254#ifdef TEUCHOS_DEBUG
256#endif
258}
259
260
261template<typename Ordinal>
262void
264 const char sendBuffer[],
265 const Ordinal recvBytes,
266 char recvBuffer[],
267 const int root) const
268{
269 (void) sendBytes; // to remove "unused parameter" warning
270 (void) recvBytes;
273 (void) root;
274#ifdef TEUCHOS_DEBUG
276#endif
278}
279
280
281template<typename Ordinal>
284 ,const Ordinal bytes, const char sendBuffer[], char globalReducts[]
285 ) const
286{
287 (void)reductOp;
289}
290
291
292template<typename Ordinal>
295 ,const Ordinal bytes, const char sendBuffer[], char scanReducts[]
296 ) const
297{
298 (void)reductOp;
300}
301
302
303template<typename Ordinal>
305 const Ordinal /*bytes*/, const char []/*sendBuffer*/, const int /*destRank*/
306 ) const
307{
309 true, std::logic_error
310 ,"SerialComm<Ordinal>::send(...): Error, you can not call send(...) when you"
311 " only have one process!"
312 );
313}
314
315template<typename Ordinal>
317send (const Ordinal /*bytes*/,
318 const char []/*sendBuffer*/,
319 const int /*destRank*/,
320 const int /*tag*/) const
321{
323 true, std::logic_error
324 ,"SerialComm<Ordinal>::send(...): Error, you can not call send(...) when you"
325 " only have one process!"
326 );
327}
328
329template<typename Ordinal>
331 const Ordinal /*bytes*/, const char []/*sendBuffer*/, const int /*destRank*/
332 ) const
333{
335 true, std::logic_error
336 ,"SerialComm<Ordinal>::send(...): Error, you can not call ssend(...) when you"
337 " only have one process!"
338 );
339}
340
341template<typename Ordinal>
342void
343SerialComm<Ordinal>::ssend (const Ordinal /* bytes */,
344 const char* /* sendBuffer */,
345 const int /* destRank */,
346 const int /* tag */) const
347{
349 true, std::logic_error
350 ,"SerialComm<Ordinal>::send(...): Error, you can not call ssend(...) when you"
351 " only have one process!"
352 );
353}
354
355template<typename Ordinal>
357 const int /*sourceRank*/, const Ordinal /*bytes*/, char []/*recvBuffer*/
358 ) const
359{
361 true, std::logic_error
362 ,"SerialComm<Ordinal>::receive(...): Error, you can not call receive(...) when you"
363 " only have one process!"
364 );
365}
366
367
368template<typename Ordinal>
370 const ArrayView<const char> &/*sendBuffer*/,
371 const int /*destRank*/
372 ) const
373{
375 true, std::logic_error
376 ,"SerialComm<Ordinal>::readySend(...): Error, you can not call readySend(...) when you"
377 " only have one process!"
378 );
379}
380
381template<typename Ordinal>
382void
384 const char sendBuffer[],
385 const int destRank,
386 const int tag) const
387{
388 (void) bytes;
390 (void) destRank;
391 (void) tag;
392
394 true, std::logic_error
395 ,"SerialComm<Ordinal>::readySend(...): Error, you can not call readySend(...) when you"
396 " only have one process!"
397 );
398}
399
400template<typename Ordinal>
402 const ArrayView<const char> &/*sendBuffer*/,
403 const int /*destRank*/
404 ) const
405{
406 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error, "SerialComm<Ordinal>::isend: You cannot call isend when you only have one process." );
407}
408
409
410template<typename Ordinal>
413isend (const ArrayView<const char> &/*sendBuffer*/,
414 const int /*destRank*/,
415 const int /*tag*/) const
416{
417 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error, "SerialComm<Ordinal>::isend: You cannot call isend when you only have one process." );
418}
419
420
421template<typename Ordinal>
423 const ArrayView<char> &/*Buffer*/,
424 const int /*sourceRank*/
425 ) const
426{
427 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error, "SerialComm<Ordinal>::ireceive: You cannot call isend when you only have one process." );
428}
429
430
431template<typename Ordinal>
434ireceive (const ArrayView<char> &/*Buffer*/,
435 const int /*sourceRank*/,
436 const int /*tag*/) const
437{
438 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error, "SerialComm<Ordinal>::ireceive: You cannot call isend when you only have one process." );
439}
440
441
442template<typename Ordinal>
444{
445 (void) requests;
446 // There's nothing to wait on!
447}
448
449
450template<typename Ordinal>
451void
454 const ArrayView<RCP<CommStatus<Ordinal> > >& statuses) const
455{
457 std::invalid_argument, "Teuchos::SerialComm::waitAll: There are not enough "
458 "entries in the statuses array to hold all the results of the communication"
459 " requests. requests.size() = " << requests.size() << " > statuses.size() "
460 "= " << statuses.size() << ".");
461
462 for (typename ArrayView<RCP<CommRequest<Ordinal> > >::iterator it = requests.begin();
463 it != requests.end(); ++it) {
464 *it = null; // A postcondition of the Teuchos::Comm interface.
465 }
466}
467
468template<typename Ordinal>
471{
472 (void) request;
473 TEUCHOS_TEST_FOR_EXCEPTION(request.getRawPtr() == NULL, std::invalid_argument,
474 "Teuchos::SerialComm::wait: On input, the request pointer is null.");
475
476 if (is_null (*request)) {
477 return null; // Nothing to wait on...
478 }
479 *request = null;
480 return rcp (new SerialCommStatus<Ordinal>);
481}
482
483template< typename Ordinal>
486{
487 return rcp(new SerialComm<Ordinal>(*this));
488}
489
490template<typename Ordinal>
492SerialComm<Ordinal>::split(const int color, const int /*key*/) const
493{
494 if (color < 0) {
495 return RCP< Comm<Ordinal> >();
496 }
497 // Simply return a copy of this communicator.
498 return rcp(new SerialComm<Ordinal>(*this));
499}
500
501template<typename Ordinal>
504{
505 if ((ranks.size()) == 1 && (ranks[0] == 0)) {
506 return rcp(new SerialComm<Ordinal>(*this));
507 } else {
508 return RCP< Comm<Ordinal> >();
509 }
510}
511
512// Overridden from Describable
513
514
515template<typename Ordinal>
517{
518 std::ostringstream oss;
519 oss << "Teuchos::SerialComm<"<<OrdinalTraits<Ordinal>::name()<<">";
520 return oss.str();
521}
522
523
524} // namespace Teuchos
525
526
527#endif // TEUCHOS_SERIAL_COMM_HPP
Defines basic traits for the ordinal field type.
Nonowning array view.
Encapsulation of the result of a receive (blocking or nonblocking).
Abstract interface for distributed-memory communication.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists.
Smart reference counting pointer class for automatic garbage collection.
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object.
bool is_null() const
Returns true if the underlying pointer is null.
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
Implementation of CommStatus for a serial communicator.
OrdinalType getSourceRank()
The source rank that sent the message (must be zero).
OrdinalType getTag()
The tag of the received message.
Concrete serial communicator subclass.
virtual RCP< CommRequest< Ordinal > > ireceive(const ArrayView< char > &Buffer, const int sourceRank) const
virtual RCP< CommRequest< Ordinal > > isend(const ArrayView< const char > &sendBuffer, const int destRank) const
virtual void broadcast(const int rootRank, const Ordinal bytes, char buffer[]) const
virtual RCP< Comm< Ordinal > > createSubcommunicator(const ArrayView< const int > &ranks) const
virtual void reduceAll(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char globalReducts[]) const
virtual void gather(const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvBytes, char recvBuffer[], const int root) const
Gather values from all processes to the root process.
virtual int receive(const int sourceRank, const Ordinal bytes, char recvBuffer[]) const
int getTag() const
The current tag.
virtual void readySend(const ArrayView< const char > &sendBuffer, const int destRank) const
RCP< SerialComm< Ordinal > > createSerialComm()
Nonmember constructor.
virtual RCP< Comm< Ordinal > > duplicate() const
virtual void ssend(const Ordinal bytes, const char sendBuffer[], const int destRank, const int tag) const
virtual void scan(const ValueTypeReductionOp< Ordinal, char > &reductOp, const Ordinal bytes, const char sendBuffer[], char scanReducts[]) const
virtual void send(const Ordinal bytes, const char sendBuffer[], const int destRank) const
virtual RCP< CommStatus< Ordinal > > wait(const Ptr< RCP< CommRequest< Ordinal > > > &request) const
virtual void waitAll(const ArrayView< RCP< CommRequest< Ordinal > > > &requests) const
virtual RCP< Comm< Ordinal > > split(const int color, const int key) const
virtual void gatherAll(const Ordinal sendBytes, const char sendBuffer[], const Ordinal recvBytes, char recvBuffer[]) const
virtual void ssend(const Ordinal bytes, const char sendBuffer[], const int destRank) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
static std::string name()
Returns name of this ordinal type.