-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathexample_pardiso_mkl.cpp
More file actions
88 lines (64 loc) · 2.29 KB
/
example_pardiso_mkl.cpp
File metadata and controls
88 lines (64 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "utils.h"
#include <clarabel.hpp>
#include <Eigen/Eigen>
#include <vector>
using namespace clarabel;
using namespace std;
using namespace Eigen;
// NB: this example requires that the solver be built with -DCLARABEL_FEATURE_FAER_SPARSE
int main(void)
{
#ifndef FEATURE_PARDISO_MKL
printf("This example requires MKL Pardiso support.\n");
return 1;
#else
/* From dense matrix:
* [[6., 0.],
* [0., 4.]]
*/
MatrixXd P_dense(2, 2);
P_dense <<
6., 0.,
0., 4.;
SparseMatrix<double> P = P_dense.sparseView();
P.makeCompressed();
Vector<double, 2> q = { -1., -4. };
MatrixXd A_dense(5, 2);
A_dense <<
1., -2., // <-- LHS of equality constraint (lower bound)
1., 0., // <-- LHS of inequality constraint (upper bound)
0., 1., // <-- LHS of inequality constraint (upper bound)
-1., 0., // <-- LHS of inequality constraint (lower bound)
0., -1.; // <-- LHS of inequality constraint (lower bound)
SparseMatrix<double> A = A_dense.sparseView();
A.makeCompressed();
Vector<double, 5> b = { 0., 1., 1., 1., 1. };
vector<SupportedConeT<double>> cones
{
ZeroConeT<double>(1),
NonnegativeConeT<double>(4),
};
// Settings
DefaultSettings<double> settings = DefaultSettings<double>::default_settings();
//settings.direct_solve_method = ClarabelDirectSolveMethods::PARDISO_PANUA;
settings.direct_solve_method = ClarabelDirectSolveMethods::PARDISO_MKL;
settings.pardiso_verbose = true;
settings.pardiso_iparm[1] = 0; // tries minimum degree ordering instead of default
//set the number of threads
settings.max_threads = 16;
// Build solver
DefaultSolver<double> solver(P, q, A, b, cones, settings);
// Solve
solver.solve();
// Get solution
DefaultSolution<double> solution = solver.solution();
utils::print_solution(solution);
DefaultInfo<double> info = solver.info();
printf("primal residual = %e\n", info.res_primal);
printf("dual residual = %e\n", info.res_dual);
printf("# of threads = %d\n", info.linsolver.threads);
printf("KKT nonzeros = %d\n", info.linsolver.nnzA);
printf("factor nonzeros = %d\n", info.linsolver.nnzL);
return 0;
#endif // FEATURE_FAER_SPARSE
}