File indexing completed on 2025-01-18 10:00:11
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "gloo/barrier.h"
0012
0013 namespace gloo {
0014
0015 class BarrierAllToAll : public Barrier {
0016 public:
0017 explicit BarrierAllToAll(const std::shared_ptr<Context>& context)
0018 : Barrier(context) {
0019
0020 auto slot = this->context_->nextSlot();
0021 for (auto i = 0; i < this->contextSize_; i++) {
0022
0023 if (i == this->contextRank_) {
0024 continue;
0025 }
0026
0027 auto& pair = this->getPair(i);
0028 auto sdata = std::unique_ptr<int>(new int);
0029 auto sbuf = pair->createSendBuffer(slot, sdata.get(), sizeof(int));
0030 sendBuffersData_.push_back(std::move(sdata));
0031 sendBuffers_.push_back(std::move(sbuf));
0032 auto rdata = std::unique_ptr<int>(new int);
0033 auto rbuf = pair->createRecvBuffer(slot, rdata.get(), sizeof(int));
0034 recvBuffersData_.push_back(std::move(rdata));
0035 recvBuffers_.push_back(std::move(rbuf));
0036 }
0037 }
0038
0039 void run() {
0040
0041 for (auto& buffer : sendBuffers_) {
0042 buffer->send();
0043 }
0044
0045 for (auto& buffer : recvBuffers_) {
0046 buffer->waitRecv();
0047 }
0048 }
0049
0050 protected:
0051 std::vector<std::unique_ptr<int>> sendBuffersData_;
0052 std::vector<std::unique_ptr<transport::Buffer>> sendBuffers_;
0053 std::vector<std::unique_ptr<int>> recvBuffersData_;
0054 std::vector<std::unique_ptr<transport::Buffer>> recvBuffers_;
0055 };
0056
0057 }