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 #include "Teuchos_TimeMonitor.hpp"
12 
13 namespace Tpetra {
14 namespace Details {
15 
16  DistributorActor::DistributorActor()
17  : mpiTag_(DEFAULT_MPI_TAG)
18  {
19 #ifdef HAVE_TPETRA_DISTRIBUTOR_TIMINGS
20  makeTimers();
21 #endif // HAVE_TPETRA_DISTRIBUTOR_TIMINGS
22  }
23 
24  DistributorActor::DistributorActor(const DistributorActor& otherActor)
25  : mpiTag_(otherActor.mpiTag_),
26  requestsRecv_(otherActor.requestsRecv_),
27  requestsSend_(otherActor.requestsSend_)
28  {
29 #ifdef HAVE_TPETRA_DISTRIBUTOR_TIMINGS
30  makeTimers();
31 #endif // HAVE_TPETRA_DISTRIBUTOR_TIMINGS
32  }
33 
34  void DistributorActor::doWaits(const DistributorPlan& plan) {
35 #ifdef HAVE_TPETRA_DISTRIBUTOR_TIMINGS
36  Teuchos::TimeMonitor timeMon (*timer_doWaitsRecv_);
37 #endif // HAVE_TPETRA_DISTRIBUTOR_TIMINGS
38 
39  if (requestsRecv_.size() > 0) {
40  Teuchos::waitAll(*plan.getComm(), requestsRecv_());
41 
42  // Restore the invariant that requests_.size() is the number of
43  // outstanding nonblocking communication requests.
44  requestsRecv_.resize(0);
45  }
46 
47 #ifdef HAVE_TPETRA_DISTRIBUTOR_TIMINGS
48  Teuchos::TimeMonitor timeMon (*timer_doWaitsSend_);
49 #endif // HAVE_TPETRA_DISTRIBUTOR_TIMINGS
50 
51  if (requestsSend_.size() > 0) {
52  Teuchos::waitAll(*plan.getComm(), requestsSend_());
53 
54  // Restore the invariant that requests_.size() is the number of
55  // outstanding nonblocking communication requests.
56  requestsSend_.resize(0);
57  }
58  }
59 
60  void DistributorActor::doWaitsRecv(const DistributorPlan& plan) {
61 #ifdef HAVE_TPETRA_DISTRIBUTOR_TIMINGS
62  Teuchos::TimeMonitor timeMon (*timer_doWaitsRecv_);
63 #endif // HAVE_TPETRA_DISTRIBUTOR_TIMINGS
64 
65  if (requestsRecv_.size() > 0) {
66  Teuchos::waitAll(*plan.getComm(), requestsRecv_());
67 
68  // Restore the invariant that requests_.size() is the number of
69  // outstanding nonblocking communication requests.
70  requestsRecv_.resize(0);
71  }
72  }
73 
74  void DistributorActor::doWaitsSend(const DistributorPlan& plan) {
75 #ifdef HAVE_TPETRA_DISTRIBUTOR_TIMINGS
76  Teuchos::TimeMonitor timeMon (*timer_doWaitsSend_);
77 #endif // HAVE_TPETRA_DISTRIBUTOR_TIMINGS
78 
79  if (requestsSend_.size() > 0) {
80  Teuchos::waitAll(*plan.getComm(), requestsSend_());
81 
82  // Restore the invariant that requests_.size() is the number of
83  // outstanding nonblocking communication requests.
84  requestsSend_.resize(0);
85  }
86  }
87 
88  bool DistributorActor::isReady() const {
89  bool result = true;
90  for (auto& request : requestsRecv_) {
91  result &= request->isReady();
92  }
93  for (auto& request : requestsSend_) {
94  result &= request->isReady();
95  }
96  return result;
97  }
98 
99 #ifdef HAVE_TPETRA_DISTRIBUTOR_TIMINGS
100  void DistributorActor::makeTimers () {
101  timer_doWaitsRecv_ = Teuchos::TimeMonitor::getNewTimer (
102  "Tpetra::Distributor: doWaitsRecv");
103 
104  timer_doWaitsSend_ = Teuchos::TimeMonitor::getNewTimer (
105  "Tpetra::Distributor: doWaitsSend");
106 
107  timer_doPosts3KV_ = Teuchos::TimeMonitor::getNewTimer (
108  "Tpetra::Distributor: doPosts(3) KV");
109  timer_doPosts4KV_ = Teuchos::TimeMonitor::getNewTimer (
110  "Tpetra::Distributor: doPosts(4) KV");
111 
112  timer_doPosts3KV_recvs_ = Teuchos::TimeMonitor::getNewTimer (
113  "Tpetra::Distributor: doPosts(3): recvs KV");
114  timer_doPosts4KV_recvs_ = Teuchos::TimeMonitor::getNewTimer (
115  "Tpetra::Distributor: doPosts(4): recvs KV");
116 
117  timer_doPosts3KV_barrier_ = Teuchos::TimeMonitor::getNewTimer (
118  "Tpetra::Distributor: doPosts(3): barrier KV");
119  timer_doPosts4KV_barrier_ = Teuchos::TimeMonitor::getNewTimer (
120  "Tpetra::Distributor: doPosts(4): barrier KV");
121 
122  timer_doPosts3KV_sends_ = Teuchos::TimeMonitor::getNewTimer (
123  "Tpetra::Distributor: doPosts(3): sends KV");
124  timer_doPosts4KV_sends_ = Teuchos::TimeMonitor::getNewTimer (
125  "Tpetra::Distributor: doPosts(4): sends KV");
126  timer_doPosts3KV_sends_slow_ = Teuchos::TimeMonitor::getNewTimer (
127  "Tpetra::Distributor: doPosts(3): sends KV SLOW");
128  timer_doPosts4KV_sends_slow_ = Teuchos::TimeMonitor::getNewTimer (
129  "Tpetra::Distributor: doPosts(4): sends KV SLOW");
130  timer_doPosts3KV_sends_fast_ = Teuchos::TimeMonitor::getNewTimer (
131  "Tpetra::Distributor: doPosts(3): sends KV FAST");
132  timer_doPosts4KV_sends_fast_ = Teuchos::TimeMonitor::getNewTimer (
133  "Tpetra::Distributor: doPosts(4): sends KV FAST");
134  }
135 #endif // HAVE_TPETRA_DISTRIBUTOR_TIMINGS
136 }
137 }