Skip to content

Commit ef07725

Browse files
committed
Fix errors in subsum.cpp
1 parent 196bec1 commit ef07725

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

example/subsum.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ constexpr auto total = 1u << tree_height;
1515
void update_max(std::atomic<int>& max_val, int const& value)
1616
{
1717
int old = max_val;
18-
while(old < value and not max_val.compare_exchange_weak(old, value));
18+
while(old < value && !max_val.compare_exchange_weak(old, value));
1919
}
2020

2121
int maxCrossingSum(std::vector<int>& vec, int l, int m, int r){
@@ -49,7 +49,7 @@ void maxSubArraySum(std::vector<int>& vec, int l, int r, std::atomic<int>& max_n
4949
// Base Case: Only one element
5050
if (l == r) {
5151
update_max(max_num, vec[l]);
52-
if(++counter == total){
52+
if(++counter == total*2-1){
5353
promise.set_value();
5454
}
5555
return ;
@@ -62,7 +62,7 @@ void maxSubArraySum(std::vector<int>& vec, int l, int r, std::atomic<int>& max_n
6262
tp.silent_async([&, m=m, r=r](){ maxSubArraySum(vec, m+1, r, max_num, tp, counter, promise); });
6363

6464
update_max(max_num, maxCrossingSum(vec, l, m, r));
65-
if(++counter == total){
65+
if(++counter == total*2-1){
6666
promise.set_value();
6767
}
6868
}
@@ -82,7 +82,7 @@ auto subsum(std::vector<int>& vec){
8282
}
8383
auto end = std::chrono::high_resolution_clock::now();
8484
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
85-
//std::cout << result << '\n';
85+
//std::cout << counter << '\n';
8686
return elapsed.count();
8787
}
8888

0 commit comments

Comments
 (0)