Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_DistributorActor.cpp
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Tpetra_Details_DistributorActor.hpp"
11 
12 namespace Tpetra::Details {
13 
14  DistributorActor::DistributorActor()
15  : mpiTag_(DEFAULT_MPI_TAG) {}
16 
17  DistributorActor::DistributorActor(const DistributorActor& otherActor)
18  : mpiTag_(otherActor.mpiTag_),
19  requestsRecv_(otherActor.requestsRecv_),
20  requestsSend_(otherActor.requestsSend_) {}
21 
22  void DistributorActor::doWaits(const DistributorPlan& plan) {
23  if (requestsRecv_.size() > 0) {
24  ProfilingRegion wr("Tpetra::Distributor: doWaitsRecv");
25 
26  Teuchos::waitAll(*plan.getComm(), requestsRecv_());
27 
28  // Restore the invariant that requests_.size() is the number of
29  // outstanding nonblocking communication requests.
30  requestsRecv_.resize(0);
31  }
32 
33  if (requestsSend_.size() > 0) {
34  ProfilingRegion ws("Tpetra::Distributor: doWaitsSend");
35 
36  Teuchos::waitAll(*plan.getComm(), requestsSend_());
37 
38  // Restore the invariant that requests_.size() is the number of
39  // outstanding nonblocking communication requests.
40  requestsSend_.resize(0);
41  }
42  }
43 
44  void DistributorActor::doWaitsRecv(const DistributorPlan& plan) {
45  if (requestsRecv_.size() > 0) {
46  ProfilingRegion wr("Tpetra::Distributor: doWaitsRecv");
47 
48  Teuchos::waitAll(*plan.getComm(), requestsRecv_());
49 
50  // Restore the invariant that requests_.size() is the number of
51  // outstanding nonblocking communication requests.
52  requestsRecv_.resize(0);
53  }
54  }
55 
56  void DistributorActor::doWaitsSend(const DistributorPlan& plan) {
57  if (requestsSend_.size() > 0) {
58  ProfilingRegion ws("Tpetra::Distributor: doWaitsSend");
59 
60  Teuchos::waitAll(*plan.getComm(), requestsSend_());
61 
62  // Restore the invariant that requests_.size() is the number of
63  // outstanding nonblocking communication requests.
64  requestsSend_.resize(0);
65  }
66  }
67 
68  bool DistributorActor::isReady() const {
69  bool result = true;
70  for (auto& request : requestsRecv_) {
71  result &= request->isReady();
72  }
73  for (auto& request : requestsSend_) {
74  result &= request->isReady();
75  }
76  return result;
77  }
78 }