Skip to content

Commit c9ffdb9

Browse files
committed
Matrix is formed with Int, factorisation uses Int64
1 parent a654587 commit c9ffdb9

24 files changed

+212
-202
lines changed

highs/io/HighsIO.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,20 @@ void highsLogHeader(const HighsLogOptions& log_options,
2929
githash_text.c_str(), kHighsCopyrightStatement.c_str());
3030

3131
#ifdef HIPO
32+
std::string blas_model =
33+
hipo::getIntegerModelString(hipo::getBlasIntegerModel());
34+
3235
#ifdef BLAS_LIBRARIES
33-
highsLogUser(
34-
log_options, HighsLogType::kInfo, "Using blas: %s - %s\n", BLAS_LIBRARIES,
35-
hipo::getIntegerModelString(hipo::getBlasIntegerModel()).c_str());
36+
highsLogUser(log_options, HighsLogType::kInfo, "Using blas: %s - %s\n",
37+
BLAS_LIBRARIES, blas_model.c_str());
38+
#else
39+
#ifdef HIPO_USES_OPENBLAS
40+
highsLogUser(log_options, HighsLogType::kInfo, "Using blas: OpenBLAS - %s\n",
41+
blas_model.c_str());
3642
#else
37-
highsLogUser(
38-
log_options, HighsLogType::kInfo, "Using blas: unknown - %s\n",
39-
hipo::getIntegerModelString(hipo::getBlasIntegerModel()).c_str());
43+
highsLogUser(log_options, HighsLogType::kInfo, "Using blas: unknown - %s\n",
44+
blas_model.c_str());
45+
#endif
4046
#endif
4147
#endif
4248
}

highs/ipm/IpxWrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,9 +1521,9 @@ HighsStatus reportHipoStatus(const HighsOptions& options,
15211521
else if (status == hipo::kStatusError) {
15221522
highsLogUser(options.log_options, HighsLogType::kError,
15231523
"Hipo: Internal error\n");
1524-
} else if (status == hipo::kStatusOoM) {
1524+
} else if (status == hipo::kStatusOverflow) {
15251525
highsLogUser(options.log_options, HighsLogType::kError,
1526-
"Hipo: Out of memory\n");
1526+
"Hipo: Integer overflow\n");
15271527
} else if (status == hipo::kStatusErrorAnalyse) {
15281528
highsLogUser(options.log_options, HighsLogType::kError,
15291529
"Hipo: Error in analyse phase\n");

highs/ipm/hipo/auxiliary/AutoDetect.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
#include <stdint.h>
44

5-
#define IDXTYPEWIDTH 64
5+
// declare Metis with 32-bit integers for the test
6+
#define IDXTYPEWIDTH 32
67
#include "metis.h"
78

89
// Weird tricks to detect the integer type width used by BLAS and Metis.
910
// These are technically undefined behaviour, because they rely on using a
10-
// function declaration that involves int64_t, while the actual implementation
11-
// may use a different type. Their behaviour may depend on the endianness of the
12-
// CPU (?).
11+
// function declaration that involves a certain integer type, while the actual
12+
// implementation may use a different one. Their behaviour may depend on the
13+
// endianness of the CPU (?).
1314

1415
namespace hipo {
1516

@@ -80,10 +81,9 @@ IntegerModel getMetisIntegerModel() {
8081
idx_t options[METIS_NOPTIONS];
8182
for (int i = 0; i < METIS_NOPTIONS; ++i) options[i] = -1;
8283

83-
// if Metis is using 32-bit internally, this should set ptype to 0 and
84-
// objtype to 1, which should trigger an error. If it uses 64-bit then
85-
// everything should be fine.
86-
options[METIS_OPTION_PTYPE] = 1;
84+
// if 32 bits are used, this sets iptype to 2, otherwise it sets objtype to
85+
// a wrong value
86+
options[METIS_OPTION_IPTYPE] = 2;
8787

8888
idx_t n = 3;
8989
idx_t ptr[4] = {0, 2, 4, 6};
@@ -96,9 +96,9 @@ IntegerModel getMetisIntegerModel() {
9696
if (perm[0] != 0 || perm[1] != 1 || perm[2] != 2)
9797
metis_model = IntegerModel::unknown;
9898
else
99-
metis_model = IntegerModel::ilp64;
99+
metis_model = IntegerModel::lp64;
100100
} else if (status == METIS_ERROR_INPUT) {
101-
metis_model = IntegerModel::lp64;
101+
metis_model = IntegerModel::ilp64;
102102
} else {
103103
metis_model = IntegerModel::unknown;
104104
}

highs/ipm/hipo/auxiliary/Auxiliary.cpp

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,12 @@
44

55
namespace hipo {
66

7-
void counts2Ptr(std::vector<Int64>& ptr, std::vector<Int64>& w) {
8-
// Given the column counts in the vector w (of size n),
9-
// compute the column pointers in the vector ptr (of size n+1),
10-
// and copy the first n pointers back into w.
11-
12-
Int64 temp_nz{};
13-
Int64 n = w.size();
14-
for (Int64 j = 0; j < n; ++j) {
15-
ptr[j] = temp_nz;
16-
temp_nz += w[j];
17-
w[j] = ptr[j];
18-
}
19-
ptr[n] = temp_nz;
20-
}
21-
22-
void inversePerm(const std::vector<Int64>& perm, std::vector<Int64>& iperm) {
7+
void inversePerm(const std::vector<Int>& perm, std::vector<Int>& iperm) {
238
// Given the permutation perm, produce the inverse permutation iperm.
249
// perm[i] : i-th entry to use in the new order.
2510
// iperm[i]: where entry i is located in the new order.
2611

27-
for (Int64 i = 0; i < perm.size(); ++i) {
12+
for (Int i = 0; i < perm.size(); ++i) {
2813
iperm[perm[i]] = i;
2914
}
3015
}
@@ -41,56 +26,56 @@ void subtreeSize(const std::vector<Int64>& parent, std::vector<Int64>& sizes) {
4126
}
4227
}
4328

44-
void transpose(const std::vector<Int64>& ptr, const std::vector<Int64>& rows,
45-
std::vector<Int64>& ptrT, std::vector<Int64>& rowsT) {
29+
void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
30+
std::vector<Int>& ptrT, std::vector<Int>& rowsT) {
4631
// Compute the transpose of the matrix and return it in rowsT and ptrT
4732

48-
Int64 n = ptr.size() - 1;
33+
Int n = ptr.size() - 1;
4934

50-
std::vector<Int64> work(n);
35+
std::vector<Int> work(n);
5136

5237
// count the entries in each row into work
53-
for (Int64 i = 0; i < ptr.back(); ++i) {
38+
for (Int i = 0; i < ptr.back(); ++i) {
5439
++work[rows[i]];
5540
}
5641

5742
// sum row sums to obtain pointers
5843
counts2Ptr(ptrT, work);
5944

60-
for (Int64 j = 0; j < n; ++j) {
61-
for (Int64 el = ptr[j]; el < ptr[j + 1]; ++el) {
62-
Int64 i = rows[el];
45+
for (Int j = 0; j < n; ++j) {
46+
for (Int el = ptr[j]; el < ptr[j + 1]; ++el) {
47+
Int i = rows[el];
6348

6449
// entry (i,j) becomes entry (j,i)
65-
Int64 pos = work[i]++;
50+
Int pos = work[i]++;
6651
rowsT[pos] = j;
6752
}
6853
}
6954
}
7055

71-
void transpose(const std::vector<Int64>& ptr, const std::vector<Int64>& rows,
72-
const std::vector<double>& val, std::vector<Int64>& ptrT,
73-
std::vector<Int64>& rowsT, std::vector<double>& valT) {
56+
void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
57+
const std::vector<double>& val, std::vector<Int>& ptrT,
58+
std::vector<Int>& rowsT, std::vector<double>& valT) {
7459
// Compute the transpose of the matrix and return it in rowsT, ptrT and valT
7560

76-
Int64 n = ptr.size() - 1;
61+
Int n = ptr.size() - 1;
7762

78-
std::vector<Int64> work(n);
63+
std::vector<Int> work(n);
7964

8065
// count the entries in each row into work
81-
for (Int64 i = 0; i < ptr.back(); ++i) {
66+
for (Int i = 0; i < ptr.back(); ++i) {
8267
++work[rows[i]];
8368
}
8469

8570
// sum row sums to obtain pointers
8671
counts2Ptr(ptrT, work);
8772

88-
for (Int64 j = 0; j < n; ++j) {
89-
for (Int64 el = ptr[j]; el < ptr[j + 1]; ++el) {
90-
Int64 i = rows[el];
73+
for (Int j = 0; j < n; ++j) {
74+
for (Int el = ptr[j]; el < ptr[j + 1]; ++el) {
75+
Int i = rows[el];
9176

9277
// entry (i,j) becomes entry (j,i)
93-
Int64 pos = work[i]++;
78+
Int pos = work[i]++;
9479
rowsT[pos] = j;
9580
valT[pos] = val[el];
9681
}
@@ -140,7 +125,7 @@ void reverseLinkedList(std::vector<Int64>& head, std::vector<Int64>& next) {
140125
}
141126

142127
void dfsPostorder(Int64 node, Int64& start, std::vector<Int64>& head,
143-
const std::vector<Int64>& next, std::vector<Int64>& order) {
128+
const std::vector<Int64>& next, std::vector<Int>& order) {
144129
// Perform depth first search starting from root node and order the nodes
145130
// starting from the value start. head and next contain the linked list of
146131
// children.

highs/ipm/hipo/auxiliary/Auxiliary.h

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,49 @@
1111

1212
namespace hipo {
1313

14-
void counts2Ptr(std::vector<Int64>& ptr, std::vector<Int64>& w);
15-
void inversePerm(const std::vector<Int64>& perm, std::vector<Int64>& iperm);
14+
void inversePerm(const std::vector<Int>& perm, std::vector<Int>& iperm);
1615
void subtreeSize(const std::vector<Int64>& parent, std::vector<Int64>& sizes);
17-
void transpose(const std::vector<Int64>& ptr, const std::vector<Int64>& rows,
18-
std::vector<Int64>& ptrT, std::vector<Int64>& rowsT);
19-
void transpose(const std::vector<Int64>& ptr, const std::vector<Int64>& rows,
20-
const std::vector<double>& val, std::vector<Int64>& ptrT,
21-
std::vector<Int64>& rowsT, std::vector<double>& valT);
16+
void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
17+
std::vector<Int>& ptrT, std::vector<Int>& rowsT);
18+
void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
19+
const std::vector<double>& val, std::vector<Int>& ptrT,
20+
std::vector<Int>& rowsT, std::vector<double>& valT);
2221
void childrenLinkedList(const std::vector<Int64>& parent,
2322
std::vector<Int64>& head, std::vector<Int64>& next);
2423
void reverseLinkedList(std::vector<Int64>& head, std::vector<Int64>& next);
2524
void dfsPostorder(Int64 node, Int64& start, std::vector<Int64>& head,
26-
const std::vector<Int64>& next, std::vector<Int64>& order);
25+
const std::vector<Int64>& next, std::vector<Int>& order);
2726
void processEdge(Int64 j, Int64 i, const std::vector<Int64>& first,
2827
std::vector<Int64>& maxfirst, std::vector<Int64>& delta,
2928
std::vector<Int64>& prevleaf, std::vector<Int64>& ancestor);
3029
Int64 getDiagStart(Int64 n, Int64 k, Int64 nb, Int64 n_blocks,
3130
std::vector<Int64>& start, bool triang = false);
3231

3332
template <typename T>
34-
void permuteVector(std::vector<T>& v, const std::vector<Int64>& perm) {
33+
void counts2Ptr(std::vector<T>& ptr, std::vector<T>& w) {
34+
// Given the column counts in the vector w (of size n),
35+
// compute the column pointers in the vector ptr (of size n+1),
36+
// and copy the first n pointers back into w.
37+
38+
T temp_nz{};
39+
T n = w.size();
40+
for (T j = 0; j < n; ++j) {
41+
ptr[j] = temp_nz;
42+
temp_nz += w[j];
43+
w[j] = ptr[j];
44+
}
45+
ptr[n] = temp_nz;
46+
}
47+
48+
template <typename T>
49+
void permuteVector(std::vector<T>& v, const std::vector<Int>& perm) {
3550
// Permute vector v according to permutation perm.
3651
std::vector<T> temp_v(v);
3752
for (Int64 i = 0; i < v.size(); ++i) v[i] = temp_v[perm[i]];
3853
}
3954

4055
template <typename T>
41-
void permuteVectorInverse(std::vector<T>& v, const std::vector<Int64>& iperm) {
56+
void permuteVectorInverse(std::vector<T>& v, const std::vector<Int>& iperm) {
4257
// Permute vector v according to inverse permutation iperm.
4358
std::vector<T> temp_v(v);
4459
for (Int64 i = 0; i < v.size(); ++i) v[iperm[i]] = temp_v[i];

highs/ipm/hipo/auxiliary/IntConfig.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ namespace hipo {
99
// Generic integer type from HiGHS
1010
typedef HighsInt Int;
1111

12-
// Integer type for indices of matrices in HiPO and factorisation
12+
// Integer type for factorisation
1313
typedef int64_t Int64;
1414

15-
// The matrix (AS or NE) size must fit into Int.
16-
// Type Int64 is used only for the nonzeros of the matrix and during the
17-
// factorisation.
15+
// The matrix (AS or NE) is formed using Int, so it must have fewer than
16+
// kHighsIInf nonzero entries. Metis works with the same type as Int, so it must
17+
// be compiled accordingly.
1818
//
19-
// For NE, AS, factorisations:
20-
// - ptr and rows are std::vector<Index>.
21-
// - ptr can be accessed with Int, rows and val must be accessed with Index.
22-
// - rows[i] can be stored as Int, ptr[i] must be stored as Index.
19+
// The factorisation uses Int64 everywhere, apart from where it interfaces with
20+
// the matrix stored using Int.
21+
// BLAS is 32-bit, so the vectors used by BLAS must be addressable with 32-bit
22+
// integers.
2323
//
2424

2525
} // namespace hipo

0 commit comments

Comments
 (0)