Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
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
12namespace Tpetra::Details {
13
14DistributorActor::DistributorActor()
15 : mpiTag_(DEFAULT_MPI_TAG)
16 , ialltofewvRootTag_(DEFAULT_MPI_TAG) {}
17
18void DistributorActor::doWaits(const DistributorPlan& plan) {
19 doWaitsRecv(plan);
20 doWaitsSend(plan);
21}
22
23void DistributorActor::doWaitsRecv(const DistributorPlan& plan) {
24 if (requestsRecv_.size() > 0) {
25 ProfilingRegion wr("Tpetra::Distributor::doWaitsRecv");
26
27 Teuchos::waitAll(*plan.getComm(), requestsRecv_());
28
29 // Restore the invariant that requests_.size() is the number of
30 // outstanding nonblocking communication requests.
31 requestsRecv_.resize(0);
32 }
33
34 doWaitsIalltofewv(plan);
35}
36
37void DistributorActor::doWaitsSend(const DistributorPlan& plan) {
38 if (requestsSend_.size() > 0) {
39 ProfilingRegion ws("Tpetra::Distributor::doWaitsSend");
40
41 Teuchos::waitAll(*plan.getComm(), requestsSend_());
42
43 // Restore the invariant that requests_.size() is the number of
44 // outstanding nonblocking communication requests.
45 requestsSend_.resize(0);
46 }
47}
48
49void DistributorActor::doWaitsIalltofewv(const DistributorPlan& plan) {
50#ifdef HAVE_TPETRA_MPI
51 if (ialltofewv_.req) {
52 ProfilingRegion ws("Tpetra::Distributor::doWaitsIalltofewv");
53 ialltofewv_.impl.wait(*ialltofewv_.req);
54
55 ialltofewv_.sendcounts.reset();
56 ialltofewv_.sdispls.reset();
57 ialltofewv_.recvcounts.reset();
58 ialltofewv_.rdispls.reset();
59 ialltofewv_.req = std::nullopt;
60 ialltofewv_.roots.clear();
61 }
62#endif
63}
64
65bool DistributorActor::isReady() const {
66 bool result = true;
67 for (auto& request : requestsRecv_) {
68 result &= request->isReady();
69 }
70 for (auto& request : requestsSend_) {
71 result &= request->isReady();
72 }
73
74 // isReady just calls MPI_Test and returns flag != 0
75 // don't use test because these are for a collective, and not
76 // all ranks may call test, so progress may not be possible
77#ifdef HAVE_TPETRA_MPI
78 if (ialltofewv_.req) {
79 int flag;
80 ialltofewv_.impl.get_status(*ialltofewv_.req, &flag, MPI_STATUS_IGNORE);
81 result &= flag;
82 }
83#endif
84
85 return result;
86}
87} // namespace Tpetra::Details
Nonmember function that computes a residual Computes R = B - A * X.