Skip to content

Commit 4226e10

Browse files
committed
back to extra space
1 parent 16287fc commit 4226e10

File tree

7 files changed

+33
-37
lines changed

7 files changed

+33
-37
lines changed

highs/ipm/hipo/auxiliary/Auxiliary.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,6 @@ Int64 getDiagStart(Int n, Int k, Int nb, Int n_blocks,
208208
return result;
209209
}
210210

211-
Int64 sizeAtLeastOne(Int64 size) {
212-
// When resizing vectors on windows, if the size is 0, there can be problems
213-
// later on accessing the entry at address 0. So always allocate at least one
214-
// byte.
215-
216-
if (0 == size) ++size;
217-
return size;
218-
}
219-
220211
Clock::Clock() { start(); }
221212
void Clock::start() { t0 = std::chrono::high_resolution_clock::now(); }
222213
double Clock::stop() const {

highs/ipm/hipo/auxiliary/Auxiliary.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void processEdge(Int j, Int i, const std::vector<Int>& first,
2828
std::vector<Int>& prevleaf, std::vector<Int>& ancestor);
2929
Int64 getDiagStart(Int n, Int k, Int nb, Int n_blocks,
3030
std::vector<Int64>& start, bool triang = false);
31-
Int64 sizeAtLeastOne(Int64 size);
3231

3332
template <typename T>
3433
void counts2Ptr(std::vector<T>& ptr, std::vector<T>& w) {

highs/ipm/hipo/factorhighs/CliqueStack.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
#include <cassert>
44
#include <cstring>
55

6-
#include "ipm/hipo/auxiliary/Auxiliary.h"
7-
86
namespace hipo {
97

108
void CliqueStack::init(Int64 stack_size) {
11-
stack_size = sizeAtLeastOne(stack_size);
12-
13-
stack_.resize(stack_size, 0.0);
149
top_ = 0;
1510
workspace_ = nullptr;
1611
worksize_ = 0;
12+
empty_ = false;
13+
14+
stack_.resize(stack_size, 0.0);
1715
}
1816

1917
double* CliqueStack::setup(Int64 clique_size, bool& reallocation) {
@@ -22,23 +20,25 @@ double* CliqueStack::setup(Int64 clique_size, bool& reallocation) {
2220
assert(!workspace_ && !worksize_);
2321
reallocation = false;
2422

25-
// This should not trigger reallocation, because the resize in init is done
26-
// with the maximum possible size of the stack.
27-
if (top_ + clique_size > stack_.size()) {
28-
reallocation = true;
29-
stack_.resize(top_ + clique_size, 0.0);
30-
}
23+
if (stack_.size() > 0) {
24+
// This should not trigger reallocation, because the resize in init is done
25+
// with the maximum possible size of the stack.
26+
if (top_ + clique_size > stack_.size()) {
27+
reallocation = true;
28+
stack_.resize(top_ + clique_size, 0.0);
29+
}
3130

32-
workspace_ = &stack_[top_];
33-
worksize_ = clique_size;
31+
workspace_ = &stack_[top_];
32+
worksize_ = clique_size;
3433

35-
// initialize workspace to zero
36-
std::memset(workspace_, 0, worksize_ * sizeof(double));
34+
// initialize workspace to zero
35+
std::memset(workspace_, 0, worksize_ * sizeof(double));
36+
}
3737

3838
return workspace_;
3939
}
4040

41-
bool CliqueStack::empty() const { return stack_.empty(); }
41+
bool CliqueStack::empty() const { return empty_; }
4242

4343
const double* CliqueStack::getChild(Int& child_sn) const {
4444
// Get the top of the stack, in terms of supernode ID of the child and pointer
@@ -63,14 +63,16 @@ void CliqueStack::popChild() {
6363
void CliqueStack::pushWork(Int sn) {
6464
// Put the content of the workspace at the top of the stack
6565

66-
// stack_[top_] has lower address than workspace, so no need to resize.
67-
// workspace_ and stack_[top_] do not overlap, so use memcpy
68-
std::memcpy(&stack_[top_], workspace_, worksize_ * sizeof(double));
66+
if (stack_.size() > 0) {
67+
// stack_[top_] has lower address than workspace, so no need to resize.
68+
// workspace_ and stack_[top_] do not overlap, so use memcpy
69+
std::memcpy(&stack_[top_], workspace_, worksize_ * sizeof(double));
6970

70-
top_ += worksize_;
71+
top_ += worksize_;
7172

72-
// keep track of supernodes pushed
73-
sn_pushed_.push({sn, worksize_});
73+
// keep track of supernodes pushed
74+
sn_pushed_.push({sn, worksize_});
75+
}
7476

7577
worksize_ = 0;
7678
workspace_ = nullptr;

highs/ipm/hipo/factorhighs/CliqueStack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class CliqueStack {
3333
std::vector<double> stack_;
3434
double* workspace_;
3535
Int64 worksize_;
36+
bool empty_ = true;
3637

3738
// pairs (sn, size) of supernodes that got pushed
3839
std::stack<std::pair<Int, Int64>> sn_pushed_{};

highs/ipm/hipo/factorhighs/FormatHandler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class FormatHandler {
8888
virtual void extremeEntries() {}
8989
};
9090

91+
const Int64 extra_space_frontal = 1;
92+
9193
} // namespace hipo
9294

9395
#endif

highs/ipm/hipo/factorhighs/HybridHybridFormatHandler.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ void HybridHybridFormatHandler::initFrontal() {
2525
const Int n_blocks = (sn_size_ - 1) / nb_ + 1;
2626
diag_start_.resize(n_blocks);
2727
Int64 frontal_size = getDiagStart(ldf_, sn_size_, nb_, n_blocks, diag_start_);
28-
frontal_size = sizeAtLeastOne(frontal_size);
28+
frontal_size += extra_space_frontal;
2929
frontal_.resize(frontal_size);
3030
std::memset(frontal_.data(), 0, frontal_size * sizeof(double));
3131

32+
// NB: extra_space_frontal is not strictly needed. However, it removes some
33+
// weird problem on windows in debug. Who knows what's happening...
34+
3235
// frontal_ is actually allocated just the first time, then the memory is
3336
// reused from the previous factorisations and just initialised.
3437
}
3538

3639
void HybridHybridFormatHandler::initClique() {
37-
Int64 clique_size = S_->cliqueSize(sn_);
38-
clique_size = sizeAtLeastOne(clique_size);
39-
clique_.resize(clique_size);
40+
clique_.resize(S_->cliqueSize(sn_));
4041
clique_ptr_ = clique_.data();
4142
}
4243

highs/ipm/hipo/factorhighs/HybridSolveHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void HybridSolveHandler::backwardSolve(std::vector<double>& x) const {
145145

146146
// index to access snColumns[sn]
147147
// initialised with the total number of entries of snColumns[sn]
148-
Int64 SnCol_ind = sn_columns_[sn].size();
148+
Int64 SnCol_ind = sn_columns_[sn].size() - extra_space_frontal;
149149

150150
// go through blocks of columns for this supernode in reverse order
151151
for (Int j = n_blocks - 1; j >= 0; --j) {

0 commit comments

Comments
 (0)