Skip to content

Commit 16287fc

Browse files
committed
Do not resize to 0 in windows
1 parent 9e384e7 commit 16287fc

File tree

6 files changed

+20
-9
lines changed

6 files changed

+20
-9
lines changed

highs/ipm/hipo/auxiliary/Auxiliary.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ 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+
211220
Clock::Clock() { start(); }
212221
void Clock::start() { t0 = std::chrono::high_resolution_clock::now(); }
213222
double Clock::stop() const {

highs/ipm/hipo/auxiliary/Auxiliary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ 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);
3132

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

highs/ipm/hipo/factorhighs/CliqueStack.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
#include <cassert>
44
#include <cstring>
55

6+
#include "ipm/hipo/auxiliary/Auxiliary.h"
7+
68
namespace hipo {
79

810
void CliqueStack::init(Int64 stack_size) {
11+
stack_size = sizeAtLeastOne(stack_size);
12+
913
stack_.resize(stack_size, 0.0);
1014
top_ = 0;
1115
workspace_ = nullptr;

highs/ipm/hipo/factorhighs/FormatHandler.h

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

91-
const Int64 extra_space = 10;
92-
9391
} // namespace hipo
9492

9593
#endif

highs/ipm/hipo/factorhighs/HybridHybridFormatHandler.cpp

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

32-
// extra_space is not needed, but if I remove it Windows in debug freezes...
33-
// who knows what's happening
34-
3532
// frontal_ is actually allocated just the first time, then the memory is
3633
// reused from the previous factorisations and just initialised.
3734
}
3835

3936
void HybridHybridFormatHandler::initClique() {
40-
clique_.resize(S_->cliqueSize(sn_));
37+
Int64 clique_size = S_->cliqueSize(sn_);
38+
clique_size = sizeAtLeastOne(clique_size);
39+
clique_.resize(clique_size);
4140
clique_ptr_ = clique_.data();
4241
}
4342

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() - extra_space;
148+
Int64 SnCol_ind = sn_columns_[sn].size();
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)