1 module lin_sys;
2 
3 nothrow @nogc extern(C):
4 
5 import types;
6 import glob_opts;
7 import constants;
8 import qdldl_interface;  // Include only this solver in the same directory
9 
10 string[2] LINSYS_SOLVER_NAME = [
11   "qdldl", "mkl pardiso"
12  ];
13 
14 version(ENABLE_MKL_PARDISO){
15 //# include "pardiso_interface.h"
16 //# include "pardiso_loader.h"
17 import pardiso_interface;
18 import pardiso_loader;
19 } /* ifdef ENABLE_MKL_PARDISO */
20 
21 // Load linear system solver shared library
22 c_int load_linsys_solver(linsys_solver_type linsys_solver) {
23   switch (linsys_solver) {
24   case cast(linsys_solver_type)QDLDL_SOLVER:
25 
26     // We do not load  QDLDL solver. We have the source.
27     return 0;
28 
29 version(ENABLE_MKL_PARDISO){
30   case cast(linsys_solver_type)MKL_PARDISO_SOLVER:
31 
32     // Load Pardiso library
33     return lh_load_pardiso(OSQP_NULL);
34 
35 } /* ifdef ENABLE_MKL_PARDISO */
36   default: // QDLDL
37     return 0;
38   }
39 }
40 
41 // Unload linear system solver shared library
42 c_int unload_linsys_solver(linsys_solver_type linsys_solver) {
43   switch (linsys_solver) {
44   case cast(linsys_solver_type)QDLDL_SOLVER:
45 
46     // We do not load QDLDL solver. We have the source.
47     return 0;
48 
49 version(ENABLE_MKL_PARDISO){
50   case cast(linsys_solver_type)MKL_PARDISO_SOLVER:
51 
52     // Unload Pardiso library
53     return lh_unload_pardiso();
54 
55 } /* ifdef ENABLE_MKL_PARDISO */
56   default: //  QDLDL
57     return 0;
58   }
59 }
60 
61 // Initialize linear system solver structure
62 // NB: Only the upper triangular part of P is stuffed!
63 c_int init_linsys_solver(LinSysSolver          **s,
64                          const csc              *P,
65                          const csc              *A,
66                          c_float                 sigma,
67                          const c_float          *rho_vec,
68                          linsys_solver_type      linsys_solver,
69                          c_int                   polish) {
70 
71   version (EMBEDDED){
72     return 0; // test it
73   }
74   else {
75 
76     switch (linsys_solver) 
77     {
78       case cast(linsys_solver_type)QDLDL_SOLVER:
79         return init_linsys_solver_qdldl(cast(qdldl_solver **)s, P, A, sigma, rho_vec, polish);
80 
81       version(ENABLE_MKL_PARDISO){
82         case cast(linsys_solver_type)MKL_PARDISO_SOLVER:
83           return init_linsys_solver_pardiso(cast(pardiso_solver **)s, P, A, sigma, rho_vec, polish);
84       } /* ifdef ENABLE_MKL_PARDISO */
85       default: // QDLDL
86         return init_linsys_solver_qdldl(cast(qdldl_solver **)s, P, A, sigma, rho_vec, polish);
87     }
88   } // !EMBEDDED
89 }