Skip to content

Commit 519b0be

Browse files
committed
Add auto detection for Metis integer type
1 parent b333866 commit 519b0be

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

highs/ipm/hipo/auxiliary/AutoDetect.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#include "AutoDetect.h"
22

3+
#include <stdint.h>
4+
5+
#define IDXTYPEWIDTH 64
6+
#include "metis.h"
7+
38
namespace hipo {
49

510
extern "C" {
@@ -63,4 +68,34 @@ std::string getBlasIntegerModelString() {
6368
}
6469
}
6570

71+
int getMetisIntegerType() {
72+
idx_t options[METIS_NOPTIONS];
73+
for (int i = 0; i < METIS_NOPTIONS; ++i) options[i] = -1;
74+
75+
// if Metis is using 32-bit internally, this should set ptype to 0 and objtype
76+
// to 1, which should trigger an error. If it uses 64-bit then everything
77+
// should be fine.
78+
options[METIS_OPTION_PTYPE] = 1;
79+
80+
idx_t n = 3;
81+
idx_t ptr[4] = {0, 2, 4, 6};
82+
idx_t rows[6] = {1, 2, 0, 2, 0, 1};
83+
idx_t perm[3], iperm[3];
84+
85+
idx_t status = METIS_NodeND(&n, ptr, rows, NULL, options, perm, iperm);
86+
87+
int metis_int = 0;
88+
if (status == METIS_OK) {
89+
if (perm[0] != 0 || perm[1] != 1 || perm[2] != 2)
90+
metis_int = -1;
91+
else
92+
metis_int = 64;
93+
} else if (status == METIS_ERROR_INPUT) {
94+
metis_int = 32;
95+
} else {
96+
metis_int = -1;
97+
}
98+
99+
return metis_int;
100+
}
66101
} // namespace hipo

highs/ipm/hipo/auxiliary/AutoDetect.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ enum class BlasIntegerModel { not_set, unknown, lp64, ilp64 };
99
BlasIntegerModel getBlasIntegerModel();
1010
std::string getBlasIntegerModelString();
1111

12-
12+
// Detect Metis integer type
13+
int getMetisIntegerType();
1314

1415
} // namespace hipo
1516

highs/ipm/hipo/factorhighs/Analyse.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,9 +1074,6 @@ void Analyse::reorderChildren() {
10741074
// frontal size
10751075
const Int64 fr = col_count_[sn_start_[sn]];
10761076

1077-
// very unlikely to happen
1078-
if (fr > int32_limit) return;
1079-
10801077
// compute storage based on format used
10811078
computeStorage(fr, sz, frontal_entries[sn], clique_entries[sn]);
10821079

highs/ipm/hipo/ipm/Solver.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <cmath>
55
#include <iostream>
66

7+
#include "ipm/hipo/auxiliary/AutoDetect.h"
78
#include "ipm/hipo/auxiliary/Log.h"
89
#include "parallel/HighsParallel.h"
910

@@ -44,6 +45,8 @@ void Solver::solve() {
4445
return;
4546
}
4647

48+
if (checkMetis()) return;
49+
4750
// iterate object needs to be initialised before potentially interrupting
4851
it_.reset(new Iterate(model_, regul_));
4952

@@ -1082,6 +1085,21 @@ bool Solver::checkInterrupt() {
10821085
return terminate;
10831086
}
10841087

1088+
bool Solver::checkMetis() {
1089+
Int metis_int = getMetisIntegerType();
1090+
if (metis_int == 32) {
1091+
logH_.printe("Metis should be compiled with 64-bit integers\n");
1092+
info_.status = kStatusError;
1093+
return true;
1094+
} else if (metis_int < 0) {
1095+
logH_.printe("Something went wrong checking Metis\n");
1096+
info_.status = kStatusError;
1097+
return true;
1098+
}
1099+
1100+
return false;
1101+
}
1102+
10851103
void Solver::printHeader() const {
10861104
if (iter_ % 20 == 0) {
10871105
std::stringstream log_stream;

highs/ipm/hipo/ipm/Solver.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ class Solver {
321321
// ===================================================================================
322322
bool checkInterrupt();
323323

324+
// ===================================================================================
325+
// Check if Metis uses the correct integer type
326+
// ===================================================================================
327+
bool checkMetis();
328+
324329
// ===================================================================================
325330
// Check if the current status has various properties.
326331
// ===================================================================================

0 commit comments

Comments
 (0)