------------------------------------------------------------------------------ Description: Manages the communication of traces between processes
| 971 | // Description: |
| 972 | // Manages the communication of traces between processes |
| 973 | class TaskManager |
| 974 | { |
| 975 | public: |
| 976 | enum Message |
| 977 | { |
| 978 | NewTask, |
| 979 | NoMoreTasks, |
| 980 | TaskFinished |
| 981 | }; |
| 982 | |
| 983 | TaskManager(ProcessLocator* locator, PStreamTracerPoint* proto) |
| 984 | : Locator(locator) |
| 985 | , Proto(proto) |
| 986 | { |
| 987 | this->Controller = nullptr; |
| 988 | this->SetController( |
| 989 | vtkMPIController::SafeDownCast(vtkMultiProcessController::GetGlobalController())); |
| 990 | AssertNe(this->Controller, nullptr); |
| 991 | this->NumProcs = this->Controller->GetNumberOfProcesses(); |
| 992 | this->Rank = this->Controller->GetLocalProcessId(); |
| 993 | |
| 994 | int prototypeSize = Proto == nullptr ? 0 : Proto->GetSize(); |
| 995 | this->MessageSize = prototypeSize + sizeof(Task); |
| 996 | this->ReceiveBuffer = nullptr; |
| 997 | |
| 998 | this->NumSends = 0; |
| 999 | this->Timer = vtkSmartPointer<vtkTimerLog>::New(); |
| 1000 | this->ReceiveTime = 0; |
| 1001 | } |
| 1002 | |
| 1003 | void Initialize(bool hasData, const PStreamTracerPointArray& seeds, int MaxId) |
| 1004 | { |
| 1005 | AssertGe(MaxId, 0); |
| 1006 | int numSeeds = static_cast<int>(seeds.size()); |
| 1007 | this->HasData.resize(this->NumProcs); |
| 1008 | std::fill(this->HasData.begin(), this->HasData.end(), 0); |
| 1009 | { |
| 1010 | const int self_hasdata = hasData ? 1 : 0; |
| 1011 | this->Controller->AllGather(&self_hasdata, this->HasData.data(), 1); |
| 1012 | } |
| 1013 | |
| 1014 | for (int i = 0; i < NumProcs; i++) |
| 1015 | { |
| 1016 | if (this->HasData[i]) |
| 1017 | { |
| 1018 | this->Leader = i; |
| 1019 | break; |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | std::vector<int> processMap0(MaxId + 1, -1); |
| 1024 | for (int i = 0; i < numSeeds; i++) |
| 1025 | { |
| 1026 | int rank = seeds[i]->GetRank(); |
| 1027 | int id = seeds[i]->GetId(); |
| 1028 | if (rank < 0 && this->Locator) |
| 1029 | { |
| 1030 | rank = this->Locator->InCurrentProcess(seeds[i]->GetSeed()) ? this->Rank : -1; |