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

Function GenerateAllocations

Filters/Sources/vtkPartitionedDataSetSource.cxx:42–77  ·  view source on GitHub ↗

* Generate allocations for the given ranks taking in consideration that: * * - Some ranks might not accept any partitions * - Some ranks might accept a finite amount of partitions. * - Some ranks might accept a any multiplicity of partitions. * */

Source from the content-addressed store, hash-verified

40 *
41 */
42std::vector<int> GenerateAllocations(const std::vector<int>& allocs, const int numPartitions)
43{
44 std::vector<int> partsPerRank(allocs);
45
46 const int partsAllocated = std::accumulate(allocs.begin(), allocs.end(), 0,
47 [](int a, int b) { return (b == NUM_PARTITIONS::MULTIPLE_PARTITIONS) ? a : a + b; });
48
49 const int partsToAlloc = std::max(numPartitions - partsAllocated, 0);
50
51 if (partsToAlloc > 0)
52 {
53 // Make a vector with iters of partitions to be alloc
54 std::vector<std::vector<int>::iterator> ranksToAllocIters;
55 auto it = partsPerRank.begin();
56 while (partsPerRank.end() !=
57 (it = find(partsPerRank.begin(), partsPerRank.end(), NUM_PARTITIONS::MULTIPLE_PARTITIONS)))
58 {
59 *it = 0; // Initialize to 0
60 ranksToAllocIters.push_back(it);
61 }
62
63 // Schedule blocks in a round-robin fashion
64 const size_t ranksToAllocSize = ranksToAllocIters.size();
65 for (size_t i = 0; i < static_cast<size_t>(partsToAlloc); ++i)
66 {
67 ++(*ranksToAllocIters[i % ranksToAllocSize]);
68 }
69 }
70
71 if (std::accumulate(partsPerRank.begin(), partsPerRank.end(), 0) != numPartitions)
72 {
73 vtkLogF(ERROR, "GenerateAllocations generated partitions != given numPartitions");
74 }
75
76 return partsPerRank;
77}
78
79// returns [start, end].
80std::pair<int, int> GetRange(const int rank, const std::vector<int>& parts)

Callers 1

RequestDataMethod · 0.85

Calls 6

maxFunction · 0.50
findFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected