* 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. * */
| 40 | * |
| 41 | */ |
| 42 | std::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]. |
| 80 | std::pair<int, int> GetRange(const int rank, const std::vector<int>& parts) |