pardiso_interface.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef PARDISO_H
  2. #define PARDISO_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "lin_alg.h"
  7. #include "kkt.h"
  8. /**
  9. * Pardiso solver structure
  10. *
  11. * NB: If we use Pardiso, we suppose that EMBEDDED is not enabled
  12. */
  13. typedef struct pardiso pardiso_solver;
  14. struct pardiso {
  15. enum linsys_solver_type type;
  16. /**
  17. * @name Functions
  18. * @{
  19. */
  20. c_int (*solve)(struct pardiso * self, c_float * b);
  21. void (*free)(struct pardiso * self); ///< Free workspace (only if desktop)
  22. c_int (*update_matrices)(struct pardiso * self, const csc *P, const csc *A); ///< Update solver matrices
  23. c_int (*update_rho_vec)(struct pardiso * self, const c_float * rho_vec); ///< Update rho_vec parameter
  24. c_int nthreads;
  25. /** @} */
  26. /**
  27. * @name Attributes
  28. * @{
  29. */
  30. // Attributes
  31. csc *KKT; ///< KKT matrix (in CSR format!)
  32. c_int *KKT_i; ///< KKT column indices in 1-indexing for Pardiso
  33. c_int *KKT_p; ///< KKT row pointers in 1-indexing for Pardiso
  34. c_float *bp; ///< workspace memory for solves (rhs)
  35. c_float *sol; ///< solution to the KKT system
  36. c_float *rho_inv_vec; ///< parameter vector
  37. c_float sigma; ///< scalar parameter
  38. c_int polish; ///< polishing flag
  39. c_int n; ///< number of QP variables
  40. c_int m; ///< number of QP constraints
  41. // Pardiso variables
  42. void *pt[64]; ///< internal solver memory pointer pt
  43. c_int iparm[64]; ///< Pardiso control parameters
  44. c_int nKKT; ///< dimension of the linear system
  45. c_int mtype; ///< matrix type (-2 for real and symmetric indefinite)
  46. c_int nrhs; ///< number of right-hand sides (1 for our needs)
  47. c_int maxfct; ///< maximum number of factors (1 for our needs)
  48. c_int mnum; ///< indicates matrix for the solution phase (1 for our needs)
  49. c_int phase; ///< control the execution phases of the solver
  50. c_int error; ///< the error indicator (0 for no error)
  51. c_int msglvl; ///< Message level information (0 for no output)
  52. c_int idum; ///< dummy integer
  53. c_float fdum; ///< dummy float
  54. // These are required for matrix updates
  55. c_int * Pdiag_idx, Pdiag_n; ///< index and number of diagonal elements in P
  56. c_int * PtoKKT, * AtoKKT; ///< Index of elements from P and A to KKT matrix
  57. c_int * rhotoKKT; ///< Index of rho places in KKT matrix
  58. /** @} */
  59. };
  60. /**
  61. * Initialize Pardiso Solver
  62. *
  63. * @param s Pointer to a private structure
  64. * @param P Cost function matrix (upper triangular form)
  65. * @param A Constraints matrix
  66. * @param sigma Algorithm parameter. If polish, then sigma = delta.
  67. * @param rho_vec Algorithm parameter. If polish, then rho_vec = OSQP_NULL.
  68. * @param polish Flag whether we are initializing for polish or not
  69. * @return Exitflag for error (0 if no errors)
  70. */
  71. c_int init_linsys_solver_pardiso(pardiso_solver ** sp, const csc * P, const csc * A, c_float sigma, const c_float * rho_vec, c_int polish);
  72. /**
  73. * Solve linear system and store result in b
  74. * @param s Linear system solver structure
  75. * @param b Right-hand side
  76. * @return Exitflag
  77. */
  78. c_int solve_linsys_pardiso(pardiso_solver * s, c_float * b);
  79. /**
  80. * Update linear system solver matrices
  81. * @param s Linear system solver structure
  82. * @param P Matrix P
  83. * @param A Matrix A
  84. * @return Exitflag
  85. */
  86. c_int update_linsys_solver_matrices_pardiso(pardiso_solver * s, const csc *P, const csc *A);
  87. /**
  88. * Update rho parameter in linear system solver structure
  89. * @param s Linear system solver structure
  90. * @param rho_vec new rho_vec value
  91. * @return exitflag
  92. */
  93. c_int update_linsys_solver_rho_vec_pardiso(pardiso_solver * s, const c_float * rho_vec);
  94. /**
  95. * Free linear system solver
  96. * @param s linear system solver object
  97. */
  98. void free_linsys_solver_pardiso(pardiso_solver * s);
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. #endif