fully populated matrix
| 281 | |
| 282 | // fully populated matrix |
| 283 | static void CreateGroupMerge(TMergePlan* plan, EAllToAllMode mode, const TVector<TVector<int>>& hostGroup) { |
| 284 | int hostCount = hostGroup[0].ysize(); |
| 285 | int groupTypeCount = hostGroup.ysize(); |
| 286 | |
| 287 | plan->Init(hostCount); |
| 288 | |
| 289 | TVector<int> gcount; |
| 290 | gcount.resize(groupTypeCount, 0); |
| 291 | for (int hostId = 0; hostId < hostCount; ++hostId) { |
| 292 | for (int groupType = 0; groupType < groupTypeCount; ++groupType) { |
| 293 | int val = hostGroup[groupType][hostId]; |
| 294 | gcount[groupType] = Max(gcount[groupType], val + 1); |
| 295 | } |
| 296 | } |
| 297 | for (int hostId = 1; hostId < hostCount; ++hostId) { |
| 298 | bool isIncrement = true; |
| 299 | for (int groupType = 0; groupType < groupTypeCount; ++groupType) { |
| 300 | int prev = hostGroup[groupType][hostId - 1]; |
| 301 | int cur = hostGroup[groupType][hostId]; |
| 302 | if (isIncrement) { |
| 303 | if (cur == prev + 1) { |
| 304 | isIncrement = false; |
| 305 | } else { |
| 306 | Y_ABORT_UNLESS(cur == 0, "ib_hosts, wrapped to non-zero"); |
| 307 | Y_ABORT_UNLESS(prev == gcount[groupType] - 1, "ib_hosts, structure is irregular"); |
| 308 | isIncrement = true; |
| 309 | } |
| 310 | } else { |
| 311 | Y_ABORT_UNLESS(prev == cur, "ib_hosts, structure is irregular"); |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | TVector<TCoverInterval> hostCoverage; |
| 317 | for (int i = 0; i < hostCount; ++i) { |
| 318 | hostCoverage.push_back(TCoverInterval(i, i + 1)); |
| 319 | } |
| 320 | |
| 321 | int baseIter = 0; |
| 322 | for (int groupType = hostGroup.ysize() - 1; groupType >= 0; --groupType) { |
| 323 | Y_ASSERT(hostGroup[groupType].ysize() == hostCount); |
| 324 | TVector<TVector<int>> hh; |
| 325 | hh.resize(gcount[groupType]); |
| 326 | for (int rank = 0; rank < hostGroup[groupType].ysize(); ++rank) { |
| 327 | int groupId = hostGroup[groupType][rank]; |
| 328 | hh[groupId].push_back(rank); |
| 329 | } |
| 330 | int newIter = 0; |
| 331 | for (int groupId = 0; groupId < hh.ysize(); ++groupId) { |
| 332 | int nn = AllToAll(plan, baseIter, 0, mode, hh[groupId], &hostCoverage); // seems to be fastest |
| 333 | if (newIter == 0) { |
| 334 | newIter = nn; |
| 335 | } else { |
| 336 | Y_ABORT_UNLESS(newIter == nn, "groups should be of same size"); |
| 337 | } |
| 338 | } |
| 339 | baseIter = newIter; |
| 340 | } |