MCPcopy Create free account
hub / github.com/Kitware/VTK / Reduce

Method Reduce

Filters/ParallelStatistics/vtkPContingencyStatistics.cxx:392–451  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

390
391//------------------------------------------------------------------------------
392bool vtkPContingencyStatistics::Reduce(vtkIdType& xySizeTotal, char* xyPacked_g,
393 vtkStdString& xyPacked_l, vtkIdType& kcSizeTotal, vtkIdType* kcValues_g,
394 std::vector<vtkIdType>& kcValues_l)
395{
396 // First, unpack the packet of strings
397 std::vector<vtkStdString> xyValues_g;
398 StringBufferToStringVector(std::string(xyPacked_g, xySizeTotal), xyValues_g);
399
400 // Second, check consistency: we must have the same number of xy and kc entries
401 if (vtkIdType(xyValues_g.size()) != kcSizeTotal)
402 {
403 vtkErrorMacro("Reduction error on process "
404 << this->Controller->GetCommunicator()->GetLocalProcessId()
405 << ": inconsistent number of (x,y) and (k,c) pairs: " << xyValues_g.size() << " <> "
406 << kcSizeTotal << ".");
407
408 return true;
409 }
410
411 // Third, reduce to the global contingency table
412 typedef std::map<std::string, vtkIdType> Distribution;
413 typedef std::map<std::string, Distribution> Bidistribution;
414 std::map<vtkIdType, Bidistribution> contingencyTable;
415 vtkIdType i = 0;
416 for (std::vector<vtkStdString>::iterator vit = xyValues_g.begin(); vit != xyValues_g.end();
417 vit += 2, i += 2)
418 {
419 contingencyTable[kcValues_g[i]][*vit][*(vit + 1)] += kcValues_g[i + 1];
420 }
421
422 // Fourth, prepare send buffers of (global) xy and kc values
423 std::vector<std::string> xyValues_l;
424 kcValues_l.clear();
425 for (std::map<vtkIdType, Bidistribution>::iterator ait = contingencyTable.begin();
426 ait != contingencyTable.end(); ++ait)
427 {
428 Bidistribution bidi = ait->second;
429 for (Bidistribution::iterator bit = bidi.begin(); bit != bidi.end(); ++bit)
430 {
431 Distribution di = bit->second;
432 for (Distribution::iterator dit = di.begin(); dit != di.end(); ++dit)
433 {
434 // Push back x and y to list of strings
435 xyValues_l.push_back(bit->first); // x
436 xyValues_l.push_back(dit->first); // y
437
438 // Push back (X,Y) index and #(x,y) to list of strings
439 kcValues_l.push_back(ait->first); // k
440 kcValues_l.push_back(dit->second); // c
441 }
442 }
443 }
444 StringVectorToStringBuffer(xyValues_l, xyPacked_l);
445
446 // Last, update xy and kc buffer sizes (which have changed because of the reduction)
447 xySizeTotal = static_cast<vtkIdType>(xyPacked_l.size());
448 kcSizeTotal = static_cast<vtkIdType>(kcValues_l.size());
449

Callers 1

LearnMethod · 0.95

Calls 10

stringClass · 0.50
sizeMethod · 0.45
GetLocalProcessIdMethod · 0.45
GetCommunicatorMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected