osqp_rust_sys/src64/lin_sys/direct/pardiso/
pardiso_loader.rs

1extern "C" {
2    fn lh_unload_lib(libhandle: soHandle_t) -> c_int;
3    fn lh_load_lib(libname: *const ::std::os::raw::c_char) -> soHandle_t;
4    fn printf(_: *const ::std::os::raw::c_char, _: ...) -> ::std::os::raw::c_int;
5    fn lh_load_sym(h: soHandle_t, symName: *const ::std::os::raw::c_char) -> voidfun;
6}
7pub type c_int = ::std::os::raw::c_longlong;
8pub type c_float = ::std::os::raw::c_double;
9pub type soHandle_t = *mut ::std::os::raw::c_void;
10pub type mkl_get_mt_t = Option::<unsafe extern "C" fn() -> ::std::os::raw::c_int>;
11pub type voidfun = Option::<unsafe extern "C" fn() -> ()>;
12pub type mkl_set_ifl_t = Option::<unsafe extern "C" fn(::std::os::raw::c_int) -> ::std::os::raw::c_int>;
13pub type pardiso_t = Option::<
14    unsafe extern "C" fn(
15        *mut *mut ::std::os::raw::c_void,
16        *const c_int,
17        *const c_int,
18        *const c_int,
19        *const c_int,
20        *const c_int,
21        *const c_float,
22        *const c_int,
23        *const c_int,
24        *mut c_int,
25        *const c_int,
26        *mut c_int,
27        *const c_int,
28        *mut c_float,
29        *mut c_float,
30        *mut c_int,
31    ) -> (),
32>;
33pub const c_print: unsafe extern "C" fn(*const ::std::os::raw::c_char, ...) -> ::std::os::raw::c_int = printf;
34pub const OSQP_NULL: ::std::os::raw::c_int = 0 as ::std::os::raw::c_int;
35static mut Pardiso_handle: soHandle_t = OSQP_NULL as soHandle_t;
36static mut func_pardiso: pardiso_t = unsafe {
37    ::std::mem::transmute::<isize, pardiso_t>(OSQP_NULL as isize)
38};
39static mut func_mkl_set_interface_layer: mkl_set_ifl_t = unsafe {
40    ::std::mem::transmute::<isize, mkl_set_ifl_t>(OSQP_NULL as isize)
41};
42static mut func_mkl_get_max_threads: mkl_get_mt_t = unsafe {
43    ::std::mem::transmute::<isize, mkl_get_mt_t>(OSQP_NULL as isize)
44};
45#[no_mangle]
46pub unsafe extern "C" fn pardiso(
47    mut pt: *mut *mut ::std::os::raw::c_void,
48    mut maxfct: *const c_int,
49    mut mnum: *const c_int,
50    mut mtype: *const c_int,
51    mut phase: *const c_int,
52    mut n: *const c_int,
53    mut a: *const c_float,
54    mut ia: *const c_int,
55    mut ja: *const c_int,
56    mut perm: *mut c_int,
57    mut nrhs: *const c_int,
58    mut iparm: *mut c_int,
59    mut msglvl: *const c_int,
60    mut b: *mut c_float,
61    mut x: *mut c_float,
62    mut error: *mut c_int,
63) {
64    if func_pardiso.is_some() {
65        func_pardiso
66            .expect(
67                "non-null function pointer",
68            )(
69            pt,
70            maxfct,
71            mnum,
72            mtype,
73            phase,
74            n,
75            a,
76            ia,
77            ja,
78            perm,
79            nrhs,
80            iparm,
81            msglvl,
82            b,
83            x,
84            error,
85        );
86    } else {
87        printf(
88            b"ERROR in %s: \0" as *const u8 as *const ::std::os::raw::c_char,
89            (*::std::mem::transmute::<&[u8; 8], &[::std::os::raw::c_char; 8]>(b"pardiso\0"))
90                .as_ptr(),
91        );
92        printf(b"Pardiso not loaded correctly\0" as *const u8 as *const ::std::os::raw::c_char);
93        printf(b"\n\0" as *const u8 as *const ::std::os::raw::c_char);
94    };
95}
96#[no_mangle]
97pub unsafe extern "C" fn mkl_set_interface_layer(mut code: c_int) -> c_int {
98    return func_mkl_set_interface_layer
99        .expect("non-null function pointer")(code as ::std::os::raw::c_int) as c_int;
100}
101#[no_mangle]
102pub unsafe extern "C" fn mkl_get_max_threads() -> c_int {
103    return ::std::mem::transmute::<
104        _,
105        fn() -> ::std::os::raw::c_int,
106    >(func_mkl_get_max_threads.expect("non-null function pointer"))() as c_int;
107}
108#[no_mangle]
109pub unsafe extern "C" fn lh_load_pardiso(mut libname: *const ::std::os::raw::c_char) -> c_int {
110    if !libname.is_null() {
111        Pardiso_handle = lh_load_lib(libname);
112    } else {
113        Pardiso_handle = lh_load_lib(
114            b"libmkl_rt.dylib\0" as *const u8 as *const ::std::os::raw::c_char,
115        );
116    }
117    if Pardiso_handle.is_null() {
118        return 1 as ::std::os::raw::c_int as c_int;
119    }
120    func_pardiso = ::std::mem::transmute::<
121        voidfun,
122        pardiso_t,
123    >(lh_load_sym(Pardiso_handle, b"pardiso\0" as *const u8 as *const ::std::os::raw::c_char));
124    if func_pardiso.is_none() {
125        return 1 as ::std::os::raw::c_int as c_int;
126    }
127    func_mkl_set_interface_layer = ::std::mem::transmute::<
128        voidfun,
129        mkl_set_ifl_t,
130    >(
131        lh_load_sym(
132            Pardiso_handle,
133            b"MKL_Set_Interface_Layer\0" as *const u8 as *const ::std::os::raw::c_char,
134        ),
135    );
136    if func_mkl_set_interface_layer.is_none() {
137        return 1 as ::std::os::raw::c_int as c_int;
138    }
139    func_mkl_get_max_threads = ::std::mem::transmute::<
140        voidfun,
141        mkl_get_mt_t,
142    >(
143        lh_load_sym(
144            Pardiso_handle,
145            b"MKL_Get_Max_Threads\0" as *const u8 as *const ::std::os::raw::c_char,
146        ),
147    );
148    if func_mkl_get_max_threads.is_none() {
149        return 1 as ::std::os::raw::c_int as c_int;
150    }
151    return 0 as ::std::os::raw::c_int as c_int;
152}
153#[no_mangle]
154pub unsafe extern "C" fn lh_unload_pardiso() -> c_int {
155    if Pardiso_handle.is_null() {
156        return 0 as ::std::os::raw::c_int as c_int;
157    }
158    return lh_unload_lib(Pardiso_handle);
159}