------------------------------------------------------------------------------
| 106 | |
| 107 | //------------------------------------------------------------------------------ |
| 108 | void vtkPExtractDataArraysOverTime::ReorganizeData(vtkMultiBlockDataSet* dataset) |
| 109 | { |
| 110 | // 1. Send all blocks to 0. |
| 111 | // 2. Rank 0 then reorganizes blocks. This is done as follows: |
| 112 | // i. If blocks form different ranks have same names, then we check if they |
| 113 | // are referring to the same global-id. If so, the tables are merged |
| 114 | // into one. If not, we the tables separately, with their names |
| 115 | // uniquified with rank number. |
| 116 | // 3. Rank 0 send info about number blocks and their names to everyone |
| 117 | // 4. Satellites, then, simply initialize their output to and make it match |
| 118 | // the structure reported by rank 0. |
| 119 | |
| 120 | const int myRank = this->Controller->GetLocalProcessId(); |
| 121 | const int numRanks = this->Controller->GetNumberOfProcesses(); |
| 122 | if (myRank != 0) |
| 123 | { |
| 124 | std::vector<vtkSmartPointer<vtkDataObject>> recvBuffer; |
| 125 | this->Controller->Gather(dataset, recvBuffer, 0); |
| 126 | |
| 127 | vtkMultiProcessStream stream; |
| 128 | this->Controller->Broadcast(stream, 0); |
| 129 | |
| 130 | dataset->Initialize(); |
| 131 | while (!stream.Empty()) |
| 132 | { |
| 133 | std::string name; |
| 134 | stream >> name; |
| 135 | |
| 136 | auto idx = dataset->GetNumberOfBlocks(); |
| 137 | dataset->SetBlock(idx, nullptr); |
| 138 | dataset->GetMetaData(idx)->Set(vtkCompositeDataSet::NAME(), name.c_str()); |
| 139 | } |
| 140 | } |
| 141 | else |
| 142 | { |
| 143 | std::vector<vtkSmartPointer<vtkDataObject>> recvBuffer; |
| 144 | this->Controller->Gather(dataset, recvBuffer, 0); |
| 145 | |
| 146 | assert(static_cast<int>(recvBuffer.size()) == numRanks); |
| 147 | |
| 148 | recvBuffer[myRank] = dataset; |
| 149 | |
| 150 | std::map<std::string, std::map<int, vtkSmartPointer<vtkTable>>> collection; |
| 151 | for (int rank = 0; rank < numRanks; ++rank) |
| 152 | { |
| 153 | if (auto mb = vtkMultiBlockDataSet::SafeDownCast(recvBuffer[rank])) |
| 154 | { |
| 155 | for (unsigned int cc = 0, max = mb->GetNumberOfBlocks(); cc < max; ++cc) |
| 156 | { |
| 157 | const char* name = mb->GetMetaData(cc)->Get(vtkCompositeDataSet::NAME()); |
| 158 | vtkTable* subblock = vtkTable::SafeDownCast(mb->GetBlock(cc)); |
| 159 | if (name && subblock) |
| 160 | { |
| 161 | collection[name][rank] = subblock; |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | } |
no test coverage detected