Skip to content

Commit 85f7353

Browse files
committed
Modernize code
Signed-off-by: cyy <cyyever@outlook.com>
1 parent 3135b0b commit 85f7353

49 files changed

Lines changed: 168 additions & 202 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

gloo/algorithm.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Algorithm::Algorithm(const std::shared_ptr<Context>& context)
2121
contextSize_(context_->size) {}
2222

2323
// Have to provide implementation for pure virtual destructor.
24-
Algorithm::~Algorithm() noexcept(false) {}
24+
Algorithm::~Algorithm() noexcept(false) = default;
2525

2626
std::unique_ptr<transport::Pair>& Algorithm::getPair(int i) {
2727
return context_->getPair(i);

gloo/algorithm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const ReductionFunction<T>* ReductionFunction<T>::max =
100100
template <typename T>
101101
class LocalOp {
102102
public:
103-
virtual ~LocalOp() noexcept(false) {}
103+
virtual ~LocalOp() noexcept(false) = default;
104104
virtual void runAsync() = 0;
105105
virtual void wait() = 0;
106106

gloo/allgather_ring.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ class AllgatherRing : public Algorithm {
5252
rightPair_->createRecvBuffer(notificationSlot, &dummy_, sizeof(dummy_));
5353
}
5454

55-
virtual ~AllgatherRing() {}
55+
~AllgatherRing() override = default;
5656

57-
void run() {
57+
void run() override {
5858
// Short circuit if there is only a single process or the output is empty.
5959
if (this->contextSize_ == 1 || count_ == 0) {
6060
return;

gloo/allreduce.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ void allreduce(const detail::AllreduceOptionsImpl& opts) {
110110

111111
// Assert the size of all inputs and outputs is identical.
112112
const size_t totalBytes = opts.elements * opts.elementSize;
113-
for (size_t i = 0; i < out.size(); i++) {
114-
GLOO_ENFORCE_EQ(out[i]->size, totalBytes);
113+
for (const auto& i : out) {
114+
GLOO_ENFORCE_EQ(i->size, totalBytes);
115115
}
116-
for (size_t i = 0; i < in.size(); i++) {
117-
GLOO_ENFORCE_EQ(in[i]->size, totalBytes);
116+
for (const auto& i : in) {
117+
GLOO_ENFORCE_EQ(i->size, totalBytes);
118118
}
119119

120120
// Initialize local reduction and broadcast functions.
@@ -560,8 +560,7 @@ void bcube(
560560
}
561561

562562
// Wait for send and receive operations to complete.
563-
for (size_t i = 0; i < group.ranks.size(); i++) {
564-
const auto peer = group.ranks[i];
563+
for (unsigned long peer : group.ranks) {
565564
if (peer == context->rank) {
566565
continue;
567566
}
@@ -640,8 +639,7 @@ void bcube(
640639
}
641640

642641
// Wait for operations to complete.
643-
for (size_t i = 0; i < group.ranks.size(); i++) {
644-
const auto peer = group.ranks[i];
642+
for (unsigned long peer : group.ranks) {
645643
if (peer == context->rank) {
646644
continue;
647645
}

gloo/allreduce.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@ struct AllreduceOptionsImpl {
4242
};
4343

4444
explicit AllreduceOptionsImpl(const std::shared_ptr<Context>& context)
45-
: context(context),
46-
timeout(context->getTimeout()),
47-
algorithm(UNSPECIFIED) {}
45+
: context(context), timeout(context->getTimeout()) {}
4846

4947
std::shared_ptr<Context> context;
5048

5149
// End-to-end timeout for this operation.
5250
std::chrono::milliseconds timeout;
5351

5452
// Algorithm selection.
55-
Algorithm algorithm;
53+
Algorithm algorithm{UNSPECIFIED};
5654

5755
// Input and output buffers.
5856
// The output is used as input if input is not specified.

gloo/allreduce_bcube.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class AllreduceBcube : public Algorithm {
345345
#define DEBUG_PRINT_RECV(stage)
346346
#endif
347347

348-
void run() {
348+
void run() override {
349349
if (totalNumElems_ == 0) {
350350
return;
351351
}

gloo/allreduce_halving_doubling.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,7 @@ class AllreduceHalvingDoubling : public Algorithm {
8282
sendOffsets_(steps_),
8383
recvOffsets_(steps_),
8484
sendCounts_(steps_, 0),
85-
recvCounts_(steps_, 0),
86-
sendCountToLargerBlock_(0),
87-
offsetToMyBinaryBlock_(0),
88-
myBinaryBlockSize_(0),
89-
stepsWithinBlock_(0),
90-
rankInBinaryBlock_(0),
91-
nextSmallerBlockSize_(0),
92-
nextLargerBlockSize_(0) {
85+
recvCounts_(steps_, 0) {
9386
if (count_ == 0 || this->contextSize_ == 1) {
9487
return;
9588
}
@@ -222,7 +215,7 @@ class AllreduceHalvingDoubling : public Algorithm {
222215
}
223216
}
224217

225-
void run() {
218+
void run() override {
226219
if (count_ == 0) {
227220
return;
228221
}
@@ -394,7 +387,7 @@ class AllreduceHalvingDoubling : public Algorithm {
394387

395388
std::vector<size_t> sendCounts_;
396389
std::vector<size_t> recvCounts_;
397-
size_t sendCountToLargerBlock_;
390+
size_t sendCountToLargerBlock_{0};
398391

399392
int dummy_;
400393
std::vector<std::unique_ptr<transport::Buffer>> sendNotificationBufs_;
@@ -404,12 +397,12 @@ class AllreduceHalvingDoubling : public Algorithm {
404397
// binary blocks and keep track of which block each process is in, as well as
405398
// the adjoining larger and smaller blocks (with which communication will be
406399
// required)
407-
uint32_t offsetToMyBinaryBlock_;
408-
uint32_t myBinaryBlockSize_;
409-
uint32_t stepsWithinBlock_;
410-
uint32_t rankInBinaryBlock_;
411-
uint32_t nextSmallerBlockSize_;
412-
uint32_t nextLargerBlockSize_;
400+
uint32_t offsetToMyBinaryBlock_{0};
401+
uint32_t myBinaryBlockSize_{0};
402+
uint32_t stepsWithinBlock_{0};
403+
uint32_t rankInBinaryBlock_{0};
404+
uint32_t nextSmallerBlockSize_{0};
405+
uint32_t nextLargerBlockSize_{0};
413406

414407
int slotOffset_;
415408
};

gloo/allreduce_local.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "gloo/allreduce_local.h"
1010

11-
#include <string.h>
11+
#include <cstring>
1212

1313
namespace gloo {
1414

gloo/allreduce_local.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class AllreduceLocal : public Algorithm {
2222
const int count,
2323
const ReductionFunction<T>* fn = ReductionFunction<T>::sum);
2424

25-
virtual ~AllreduceLocal() = default;
25+
~AllreduceLocal() override = default;
2626

27-
virtual void run() override;
27+
void run() override;
2828

2929
protected:
3030
std::vector<T*> ptrs_;

gloo/allreduce_ring.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class AllreduceRing : public Algorithm {
5757
rightPair->createRecvBuffer(notificationSlot, &dummy_, sizeof(dummy_));
5858
}
5959

60-
virtual ~AllreduceRing() {
60+
~AllreduceRing() override {
6161
if (inbox_ != nullptr) {
6262
free(inbox_);
6363
}
@@ -66,7 +66,7 @@ class AllreduceRing : public Algorithm {
6666
}
6767
}
6868

69-
void run() {
69+
void run() override {
7070
if (count_ == 0) {
7171
return;
7272
}

0 commit comments

Comments
 (0)