19 #ifndef viskores_filter_flow_internal_AdvectAlgorithmTerminator_h
20 #define viskores_filter_flow_internal_AdvectAlgorithmTerminator_h
60 class AdvectAlgorithmTerminator
63 #ifdef VISKORES_ENABLE_MPI
64 AdvectAlgorithmTerminator(viskoresdiy::mpi::communicator& comm)
68 , MPIComm(viskoresdiy::mpi::mpi_cast(comm.handle()))
72 AdvectAlgorithmTerminator(viskoresdiy::mpi::communicator&
viskoresNotUsed(comm))
76 this->FirstCall =
true;
81 #ifdef VISKORES_ENABLE_MPI
82 return this->State == AdvectAlgorithmTerminatorState::DONE;
84 return !this->HaveWork;
88 void Control(
bool haveLocalWork)
90 #ifdef VISKORES_ENABLE_MPI
94 this->FirstCall =
false;
100 if (this->State == STATE_0 && !haveLocalWork)
104 MPI_Ibarrier(this->MPIComm, &this->StateReq);
106 this->State = STATE_1;
108 else if (this->State == STATE_1)
112 MPI_Test(&this->StateReq, &flag, &status);
115 this->LocalDirty = this->Dirty;
117 &this->LocalDirty, &this->AllDirty, 1, MPI_INT, MPI_LOR, this->MPIComm, &this->StateReq);
118 this->State = STATE_2;
121 else if (this->State == STATE_2)
125 MPI_Test(&this->StateReq, &flag, &status);
130 if (this->AllDirty == 0)
133 this->State = STATE_0;
137 this->HaveWork = haveLocalWork;
144 #ifdef VISKORES_ENABLE_MPI
145 enum AdvectAlgorithmTerminatorState
155 std::atomic<int> Dirty;
157 std::atomic<int> LocalWork;
160 AdvectAlgorithmTerminatorState State = AdvectAlgorithmTerminatorState::STATE_0;
161 MPI_Request StateReq;
173 #endif //viskores_filter_flow_internal_AdvectAlgorithmTerminator_h