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  doWaitsRecv(plan);
24  doWaitsSend(plan);
25  }
26 
27  void DistributorActor::doWaitsRecv(const DistributorPlan& plan) {
28  if (requestsRecv_.size() > 0) {
29  ProfilingRegion wr("Tpetra::Distributor::doWaitsRecv");
30 
31  Teuchos::waitAll(*plan.getComm(), requestsRecv_());
32 
33  // Restore the invariant that requests_.size() is the number of
34  // outstanding nonblocking communication requests.
35  requestsRecv_.resize(0);
36  }
37  }
38 
39  void DistributorActor::doWaitsSend(const DistributorPlan& plan) {
40  if (requestsSend_.size() > 0) {
41  ProfilingRegion ws("Tpetra::Distributor::doWaitsSend");
42 
43  Teuchos::waitAll(*plan.getComm(), requestsSend_());
44 
45  // Restore the invariant that requests_.size() is the number of
46  // outstanding nonblocking communication requests.
47  requestsSend_.resize(0);
48  }
49  }
50 
51  bool DistributorActor::isReady() const {
52  bool result = true;
53  for (auto& request : requestsRecv_) {
54  result &= request->isReady();
55  }
56  for (auto& request : requestsSend_) {
57  result &= request->isReady();
58  }
59  return result;
60  }
61 }