Skip to content

Commit f8482af

Browse files
authored
Merge pull request #2706 from ERGO-Code/hipo-simplify
Various minor improvements to HiPO
2 parents 1571759 + 696cedb commit f8482af

22 files changed

+803
-929
lines changed

highs/ipm/hipo/auxiliary/Auxiliary.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ void printTest(const std::vector<T>& v, const std::string s) {
7171
out_file.close();
7272
}
7373

74+
template <typename T>
75+
void freeVector(std::vector<T> v) {
76+
// Give up memory allocated to v.
77+
// (technically shrink_to_fit does not guarantee to deallocate)
78+
v.clear();
79+
v.shrink_to_fit();
80+
}
81+
7482
class Clock {
7583
std::chrono::high_resolution_clock::time_point t0;
7684

highs/ipm/hipo/factorhighs/Analyse.cpp

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,70 +1295,40 @@ Int Analyse::run(Symbolic& S) {
12951295

12961296
if (!ready_) return kRetGeneric;
12971297

1298-
#if HIPO_TIMING_LEVEL >= 1
1299-
Clock clock_total;
1300-
#endif
1298+
HIPO_CLOCK_CREATE;
13011299

1302-
#if HIPO_TIMING_LEVEL >= 2
1303-
Clock clock_items;
1304-
#endif
1300+
HIPO_CLOCK_START(2);
13051301
if (getPermutation()) return kRetOrderingError;
1306-
#if HIPO_TIMING_LEVEL >= 2
1307-
data_.sumTime(kTimeAnalyseOrdering, clock_items.stop());
1308-
#endif
1302+
HIPO_CLOCK_STOP(2, data_, kTimeAnalyseMetis);
13091303

1310-
#if HIPO_TIMING_LEVEL >= 2
1311-
clock_items.start();
1312-
#endif
1304+
HIPO_CLOCK_START(2);
13131305
permute(iperm_);
13141306
eTree();
13151307
postorder();
1316-
#if HIPO_TIMING_LEVEL >= 2
1317-
data_.sumTime(kTimeAnalyseTree, clock_items.stop());
1318-
#endif
1308+
HIPO_CLOCK_STOP(2, data_, kTimeAnalyseTree);
13191309

1320-
#if HIPO_TIMING_LEVEL >= 2
1321-
clock_items.start();
1322-
#endif
1310+
HIPO_CLOCK_START(2);
13231311
colCount();
1324-
#if HIPO_TIMING_LEVEL >= 2
1325-
data_.sumTime(kTimeAnalyseCount, clock_items.stop());
1326-
#endif
1312+
HIPO_CLOCK_STOP(2, data_, kTimeAnalyseCount);
13271313

1328-
#if HIPO_TIMING_LEVEL >= 2
1329-
clock_items.start();
1330-
#endif
1314+
HIPO_CLOCK_START(2);
13311315
fundamentalSupernodes();
13321316
relaxSupernodes();
13331317
afterRelaxSn();
1334-
#if HIPO_TIMING_LEVEL >= 2
1335-
data_.sumTime(kTimeAnalyseSn, clock_items.stop());
1336-
#endif
1318+
HIPO_CLOCK_STOP(2, data_, kTimeAnalyseSn);
13371319

1338-
#if HIPO_TIMING_LEVEL >= 2
1339-
clock_items.start();
1340-
#endif
1320+
HIPO_CLOCK_START(2);
13411321
reorderChildren();
1342-
#if HIPO_TIMING_LEVEL >= 2
1343-
data_.sumTime(kTimeAnalyseReorder, clock_items.stop());
1344-
#endif
1322+
HIPO_CLOCK_STOP(2, data_, kTimeAnalyseReorder);
13451323

1346-
#if HIPO_TIMING_LEVEL >= 2
1347-
clock_items.start();
1348-
#endif
1324+
HIPO_CLOCK_START(2);
13491325
snPattern();
1350-
#if HIPO_TIMING_LEVEL >= 2
1351-
data_.sumTime(kTimeAnalysePattern, clock_items.stop());
1352-
#endif
1326+
HIPO_CLOCK_STOP(2, data_, kTimeAnalysePattern);
13531327

1354-
#if HIPO_TIMING_LEVEL >= 2
1355-
clock_items.start();
1356-
#endif
1328+
HIPO_CLOCK_START(2);
13571329
relativeIndCols();
13581330
relativeIndClique();
1359-
#if HIPO_TIMING_LEVEL >= 2
1360-
data_.sumTime(kTimeAnalyseRelInd, clock_items.stop());
1361-
#endif
1331+
HIPO_CLOCK_STOP(2, data_, kTimeAnalyseRelInd);
13621332

13631333
computeBlockStart();
13641334
computeCriticalPath();
@@ -1411,11 +1381,7 @@ Int Analyse::run(Symbolic& S) {
14111381
S.consecutive_sums_ = std::move(consecutive_sums_);
14121382
S.clique_block_start_ = std::move(clique_block_start_);
14131383

1414-
#if HIPO_TIMING_LEVEL >= 1
1415-
data_.sumTime(kTimeAnalyse, clock_total.stop());
1416-
#else
1417-
(void)data_; // to avoid an unused-private-field warning
1418-
#endif
1384+
HIPO_CLOCK_STOP(1, data_, kTimeAnalyse);
14191385

14201386
return kRetOk;
14211387
}

highs/ipm/hipo/factorhighs/CallAndTimeBlas.cpp

Lines changed: 22 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -19,98 +19,66 @@ namespace hipo {
1919

2020
void callAndTime_daxpy(Int n, double da, const double* dx, Int incx, double* dy,
2121
Int incy, DataCollector& data) {
22-
#if HIPO_TIMING_LEVEL >= 3
23-
Clock clock;
24-
#endif
22+
HIPO_CLOCK_CREATE;
2523
cblas_daxpy(n, da, dx, incx, dy, incy);
26-
#if HIPO_TIMING_LEVEL >= 3
27-
data.sumTime(kTimeBlas_axpy, clock.stop());
28-
#endif
24+
HIPO_CLOCK_STOP(3, data, kTimeBlas_axpy);
2925
}
3026

3127
void callAndTime_dcopy(Int n, const double* dx, Int incx, double* dy, Int incy,
3228
DataCollector& data) {
33-
#if HIPO_TIMING_LEVEL >= 3
34-
Clock clock;
35-
#endif
29+
HIPO_CLOCK_CREATE;
3630
cblas_dcopy(n, dx, incx, dy, incy);
37-
#if HIPO_TIMING_LEVEL >= 3
38-
data.sumTime(kTimeBlas_copy, clock.stop());
39-
#endif
31+
HIPO_CLOCK_STOP(3, data, kTimeBlas_copy);
4032
}
4133

4234
void callAndTime_dscal(Int n, const double da, double* dx, Int incx,
4335
DataCollector& data) {
44-
#if HIPO_TIMING_LEVEL >= 3
45-
Clock clock;
46-
#endif
36+
HIPO_CLOCK_CREATE;
4737
cblas_dscal(n, da, dx, incx);
48-
#if HIPO_TIMING_LEVEL >= 3
49-
data.sumTime(kTimeBlas_scal, clock.stop());
50-
#endif
38+
HIPO_CLOCK_STOP(3, data, kTimeBlas_scal);
5139
}
5240

5341
void callAndTime_dswap(Int n, double* dx, Int incx, double* dy, Int incy,
5442
DataCollector& data) {
55-
#if HIPO_TIMING_LEVEL >= 3
56-
Clock clock;
57-
#endif
43+
HIPO_CLOCK_CREATE;
5844
cblas_dswap(n, dx, incx, dy, incy);
59-
#if HIPO_TIMING_LEVEL >= 3
60-
data.sumTime(kTimeBlas_swap, clock.stop());
61-
#endif
45+
HIPO_CLOCK_STOP(3, data, kTimeBlas_swap);
6246
}
6347

6448
// level 2
6549

6650
void callAndTime_dgemv(char trans, Int m, Int n, double alpha, const double* A,
6751
Int lda, const double* x, Int incx, double beta,
6852
double* y, Int incy, DataCollector& data) {
69-
#if HIPO_TIMING_LEVEL >= 3
70-
Clock clock;
71-
#endif
53+
HIPO_CLOCK_CREATE;
7254
cblas_dgemv(CblasColMajor, TRANS(trans), m, n, alpha, A, lda, x, incx, beta,
7355
y, incy);
74-
#if HIPO_TIMING_LEVEL >= 3
75-
data.sumTime(kTimeBlas_gemv, clock.stop());
76-
#endif
56+
HIPO_CLOCK_STOP(3, data, kTimeBlas_gemv);
7757
}
7858

7959
void callAndTime_dtpsv(char uplo, char trans, char diag, Int n,
8060
const double* ap, double* x, Int incx,
8161
DataCollector& data) {
82-
#if HIPO_TIMING_LEVEL >= 3
83-
Clock clock;
84-
#endif
62+
HIPO_CLOCK_CREATE;
8563
cblas_dtpsv(CblasColMajor, UPLO(uplo), TRANS(trans), DIAG(diag), n, ap, x,
8664
incx);
87-
#if HIPO_TIMING_LEVEL >= 3
88-
data.sumTime(kTimeBlas_tpsv, clock.stop());
89-
#endif
65+
HIPO_CLOCK_STOP(3, data, kTimeBlas_tpsv);
9066
}
9167

9268
void callAndTime_dtrsv(char uplo, char trans, char diag, Int n, const double* A,
9369
Int lda, double* x, Int incx, DataCollector& data) {
94-
#if HIPO_TIMING_LEVEL >= 3
95-
Clock clock;
96-
#endif
70+
HIPO_CLOCK_CREATE;
9771
cblas_dtrsv(CblasColMajor, UPLO(uplo), TRANS(trans), DIAG(diag), n, A, lda, x,
9872
incx);
99-
#if HIPO_TIMING_LEVEL >= 3
100-
data.sumTime(kTimeBlas_trsv, clock.stop());
101-
#endif
73+
HIPO_CLOCK_STOP(3, data, kTimeBlas_trsv);
10274
}
10375

10476
void callAndTime_dger(Int m, Int n, double alpha, const double* x, Int incx,
10577
const double* y, Int incy, double* A, Int lda,
10678
DataCollector& data) {
107-
#if HIPO_TIMING_LEVEL >= 3
108-
Clock clock;
109-
#endif
79+
HIPO_CLOCK_CREATE;
11080
cblas_dger(CblasColMajor, m, n, alpha, x, incx, y, incy, A, lda);
111-
#if HIPO_TIMING_LEVEL >= 3
112-
data.sumTime(kTimeBlas_ger, clock.stop());
113-
#endif
81+
HIPO_CLOCK_STOP(3, data, kTimeBlas_ger);
11482
}
11583

11684
// level 3
@@ -119,40 +87,28 @@ void callAndTime_dgemm(char transa, char transb, Int m, Int n, Int k,
11987
double alpha, const double* A, Int lda, const double* B,
12088
Int ldb, double beta, double* C, Int ldc,
12189
DataCollector& data) {
122-
#if HIPO_TIMING_LEVEL >= 3
123-
Clock clock;
124-
#endif
90+
HIPO_CLOCK_CREATE;
12591
cblas_dgemm(CblasColMajor, TRANS(transa), TRANS(transb), m, n, k, alpha, A,
12692
lda, B, ldb, beta, C, ldc);
127-
#if HIPO_TIMING_LEVEL >= 3
128-
data.sumTime(kTimeBlas_gemm, clock.stop());
129-
#endif
93+
HIPO_CLOCK_STOP(3, data, kTimeBlas_gemm);
13094
}
13195

13296
void callAndTime_dsyrk(char uplo, char trans, Int n, Int k, double alpha,
13397
const double* A, Int lda, double beta, double* C,
13498
Int ldc, DataCollector& data) {
135-
#if HIPO_TIMING_LEVEL >= 3
136-
Clock clock;
137-
#endif
99+
HIPO_CLOCK_CREATE;
138100
cblas_dsyrk(CblasColMajor, UPLO(uplo), TRANS(trans), n, k, alpha, A, lda,
139101
beta, C, ldc);
140-
#if HIPO_TIMING_LEVEL >= 3
141-
data.sumTime(kTimeBlas_syrk, clock.stop());
142-
#endif
102+
HIPO_CLOCK_STOP(3, data, kTimeBlas_syrk);
143103
}
144104

145105
void callAndTime_dtrsm(char side, char uplo, char trans, char diag, Int m,
146106
Int n, double alpha, const double* A, Int lda, double* B,
147107
Int ldb, DataCollector& data) {
148-
#if HIPO_TIMING_LEVEL >= 3
149-
Clock clock;
150-
#endif
108+
HIPO_CLOCK_CREATE;
151109
cblas_dtrsm(CblasColMajor, SIDE(side), UPLO(uplo), TRANS(trans), DIAG(diag),
152110
m, n, alpha, A, lda, B, ldb);
153-
#if HIPO_TIMING_LEVEL >= 3
154-
data.sumTime(kTimeBlas_trsm, clock.stop());
155-
#endif
111+
HIPO_CLOCK_STOP(3, data, kTimeBlas_trsm);
156112
}
157113

158114
} // namespace hipo

highs/ipm/hipo/factorhighs/CliqueStack.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,21 @@ double* CliqueStack::setup(Int64 clique_size, bool& reallocation) {
2020
assert(!workspace_ && !worksize_);
2121
reallocation = false;
2222

23-
if (!stack_.empty()) {
23+
if (clique_size > 0) {
2424
// This should not trigger reallocation, because the resize in init is done
2525
// with the maximum possible size of the stack.
2626
if (top_ + clique_size > stack_.size()) {
2727
reallocation = true;
2828
stack_.resize(top_ + clique_size, 0.0);
2929
}
3030

31-
if (clique_size > 0) {
32-
// accessing stack[top] is valid only if the clique is not empty,
33-
// otherwise it may be out of bounds.
34-
workspace_ = &stack_[top_];
35-
worksize_ = clique_size;
31+
// accessing stack[top] is valid only if the clique is not empty,
32+
// otherwise it may be out of bounds.
33+
workspace_ = &stack_[top_];
34+
worksize_ = clique_size;
3635

37-
// initialize workspace to zero
38-
std::memset(workspace_, 0, worksize_ * sizeof(double));
39-
}
36+
// initialize workspace to zero
37+
std::memset(workspace_, 0, worksize_ * sizeof(double));
4038
}
4139

4240
return workspace_;
@@ -67,7 +65,7 @@ void CliqueStack::popChild() {
6765
void CliqueStack::pushWork(Int sn) {
6866
// Put the content of the workspace at the top of the stack
6967

70-
if (!stack_.empty()) {
68+
if (worksize_ > 0) {
7169
// stack_[top_] has lower address than workspace, so no need to resize.
7270
// workspace_ and stack_[top_] do not overlap, so use memcpy
7371
std::memcpy(&stack_[top_], workspace_, worksize_ * sizeof(double));

0 commit comments

Comments
 (0)