Skip to content

Commit 8961b97

Browse files
committed
feature passthrough and add example
1 parent 99b4c75 commit 8961b97

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

examples/cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(CPP_EXAMPLES
88
example_socp
99
example_sdp
1010
example_faer
11+
example_mkl_pardiso
1112
example_json
1213
example_print_stream
1314
example_callback
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include "utils.h"
2+
3+
#include <Clarabel>
4+
#include <Eigen/Eigen>
5+
#include <vector>
6+
7+
using namespace clarabel;
8+
using namespace std;
9+
using namespace Eigen;
10+
11+
// NB: this example requires that the solver be built with -DCLARABEL_FEATURE_FAER_SPARSE
12+
13+
int main(void)
14+
{
15+
16+
#ifndef FEATURE_PARDISO_MKL
17+
printf("This example requires MKL Pardiso support.\n");
18+
return 1;
19+
#else
20+
21+
22+
/* From dense matrix:
23+
* [[6., 0.],
24+
* [0., 4.]]
25+
*/
26+
MatrixXd P_dense(2, 2);
27+
P_dense <<
28+
6., 0.,
29+
0., 4.;
30+
31+
SparseMatrix<double> P = P_dense.sparseView();
32+
P.makeCompressed();
33+
34+
Vector<double, 2> q = { -1., -4. };
35+
36+
MatrixXd A_dense(5, 2);
37+
A_dense <<
38+
1., -2., // <-- LHS of equality constraint (lower bound)
39+
1., 0., // <-- LHS of inequality constraint (upper bound)
40+
0., 1., // <-- LHS of inequality constraint (upper bound)
41+
-1., 0., // <-- LHS of inequality constraint (lower bound)
42+
0., -1.; // <-- LHS of inequality constraint (lower bound)
43+
44+
SparseMatrix<double> A = A_dense.sparseView();
45+
A.makeCompressed();
46+
47+
Vector<double, 5> b = { 0., 1., 1., 1., 1. };
48+
49+
vector<SupportedConeT<double>> cones
50+
{
51+
ZeroConeT<double>(1),
52+
NonnegativeConeT<double>(4),
53+
};
54+
55+
// Settings
56+
DefaultSettings<double> settings = DefaultSettings<double>::default_settings();
57+
settings.direct_solve_method = ClarabelDirectSolveMethods::PARDISO_MKL;
58+
//set the number of threads
59+
settings.max_threads = 16;
60+
61+
// Build solver
62+
DefaultSolver<double> solver(P, q, A, b, cones, settings);
63+
64+
// Solve
65+
solver.solve();
66+
67+
// Get solution
68+
DefaultSolution<double> solution = solver.solution();
69+
utils::print_solution(solution);
70+
71+
return 0;
72+
73+
#endif // FEATURE_FAER_SPARSE
74+
}

rust_wrapper/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ sdp-r = ["sdp", "clarabel/sdp-r"]
2828

2929
serde = ["dep:serde", "clarabel/serde"]
3030
faer-sparse = ["clarabel/faer-sparse"]
31+
pardiso-mkl = ["clarabel/pardiso-mkl"]
32+
pardiso-panua = ["clarabel/pardiso-panua"]
33+
pardiso = ["clarabel/pardiso"] #chooses both

0 commit comments

Comments
 (0)