include_superlu.hpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // ------------------------------------------------------------------------
  16. //
  17. // This file includes portions of SuperLU 5.2 software,
  18. // licensed under the following conditions.
  19. //
  20. // Copyright (c) 2003, The Regents of the University of California, through
  21. // Lawrence Berkeley National Laboratory (subject to receipt of any required
  22. // approvals from U.S. Dept. of Energy)
  23. //
  24. // All rights reserved.
  25. //
  26. // Redistribution and use in source and binary forms, with or without
  27. // modification, are permitted provided that the following conditions are met:
  28. //
  29. // (1) Redistributions of source code must retain the above copyright notice,
  30. // this list of conditions and the following disclaimer.
  31. // (2) Redistributions in binary form must reproduce the above copyright notice,
  32. // this list of conditions and the following disclaimer in the documentation
  33. // and/or other materials provided with the distribution.
  34. // (3) Neither the name of Lawrence Berkeley National Laboratory, U.S. Dept. of
  35. // Energy nor the names of its contributors may be used to endorse or promote
  36. // products derived from this software without specific prior written permission.
  37. //
  38. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  39. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  40. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  41. // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  42. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  45. // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  46. // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  47. // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  48. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49. //
  50. // ------------------------------------------------------------------------
  51. #if defined(ARMA_USE_SUPERLU)
  52. #if defined(ARMA_USE_SUPERLU_HEADERS) || defined(ARMA_SUPERLU_INCLUDE_DIR)
  53. // Since we need to suport float, double, cx_float and cx_double,
  54. // as well as preserve the sanity of the user,
  55. // we cannot simply include all the SuperLU headers due to their messy state
  56. // (duplicate definitions, pollution of global namespace, bizarro defines).
  57. // As such we are forced to include only a subset of the headers
  58. // and manually specify a few SuperLU structures and function prototypes.
  59. //
  60. // CAVEAT:
  61. // This code requires SuperLU version 5.2,
  62. // and assumes that newer 5.x versions will have no API changes.
  63. namespace arma
  64. {
  65. namespace superlu
  66. {
  67. // slu_*defs.h has int typedefed to int_t.
  68. // I'll just write it as int for simplicity, where I can, but supermatrix.h needs int_t.
  69. typedef int int_t;
  70. // Include supermatrix.h. This gives us SuperMatrix.
  71. // Put it in the slu namespace.
  72. // For versions of SuperLU I am familiar with, supermatrix.h does not include any other files.
  73. // Therefore, putting it in the superlu namespace is reasonably safe.
  74. // This same reasoning is true for superlu_enum_consts.h.
  75. #if defined(ARMA_SUPERLU_INCLUDE_DIR)
  76. #define ARMA_SLU_STR(x) x
  77. #define ARMA_SLU_STR2(x) ARMA_SLU_STR(x)
  78. #define ARMA_SLU_SUPERMATRIX_H ARMA_SLU_STR2(ARMA_SUPERLU_INCLUDE_DIR)ARMA_SLU_STR2(supermatrix.h)
  79. #define ARMA_SLU_SUPERLU_ENUM_CONSTS_H ARMA_SLU_STR2(ARMA_SUPERLU_INCLUDE_DIR)ARMA_SLU_STR2(superlu_enum_consts.h)
  80. #else
  81. #define ARMA_SLU_SUPERMATRIX_H supermatrix.h
  82. #define ARMA_SLU_SUPERLU_ENUM_CONSTS_H superlu_enum_consts.h
  83. #endif
  84. #include ARMA_INCFILE_WRAP(ARMA_SLU_SUPERMATRIX_H)
  85. #include ARMA_INCFILE_WRAP(ARMA_SLU_SUPERLU_ENUM_CONSTS_H)
  86. #undef ARMA_SLU_SUPERMATRIX_H
  87. #undef ARMA_SLU_SUPERLU_ENUM_CONSTS_H
  88. typedef struct
  89. {
  90. int* panel_histo;
  91. double* utime;
  92. float* ops;
  93. int TinyPivots;
  94. int RefineSteps;
  95. int expansions;
  96. } SuperLUStat_t;
  97. typedef struct
  98. {
  99. fact_t Fact;
  100. yes_no_t Equil;
  101. colperm_t ColPerm;
  102. trans_t Trans;
  103. IterRefine_t IterRefine;
  104. double DiagPivotThresh;
  105. yes_no_t SymmetricMode;
  106. yes_no_t PivotGrowth;
  107. yes_no_t ConditionNumber;
  108. rowperm_t RowPerm;
  109. int ILU_DropRule;
  110. double ILU_DropTol;
  111. double ILU_FillFactor;
  112. norm_t ILU_Norm;
  113. double ILU_FillTol;
  114. milu_t ILU_MILU;
  115. double ILU_MILU_Dim;
  116. yes_no_t ParSymbFact;
  117. yes_no_t ReplaceTinyPivot;
  118. yes_no_t SolveInitialized;
  119. yes_no_t RefineInitialized;
  120. yes_no_t PrintStat;
  121. int nnzL, nnzU;
  122. int num_lookaheads;
  123. yes_no_t lookahead_etree;
  124. yes_no_t SymPattern;
  125. } superlu_options_t;
  126. typedef struct
  127. {
  128. float for_lu;
  129. float total_needed;
  130. } mem_usage_t;
  131. typedef struct e_node
  132. {
  133. int size;
  134. void* mem;
  135. } ExpHeader;
  136. typedef struct
  137. {
  138. int size;
  139. int used;
  140. int top1;
  141. int top2;
  142. void* array;
  143. } LU_stack_t;
  144. typedef struct
  145. {
  146. int* xsup;
  147. int* supno;
  148. int* lsub;
  149. int* xlsub;
  150. void* lusup;
  151. int* xlusup;
  152. void* ucol;
  153. int* usub;
  154. int* xusub;
  155. int nzlmax;
  156. int nzumax;
  157. int nzlumax;
  158. int n;
  159. LU_space_t MemModel;
  160. int num_expansions;
  161. ExpHeader* expanders;
  162. LU_stack_t stack;
  163. } GlobalLU_t;
  164. }
  165. }
  166. #else
  167. // Not using any SuperLU headers, so define all required enums and structs.
  168. //
  169. // CAVEAT:
  170. // This code requires SuperLU version 5.2,
  171. // and assumes that newer 5.x versions will have no API changes.
  172. namespace arma
  173. {
  174. namespace superlu
  175. {
  176. typedef int int_t;
  177. typedef enum
  178. {
  179. SLU_NC,
  180. SLU_NCP,
  181. SLU_NR,
  182. SLU_SC,
  183. SLU_SCP,
  184. SLU_SR,
  185. SLU_DN,
  186. SLU_NR_loc
  187. } Stype_t;
  188. typedef enum
  189. {
  190. SLU_S,
  191. SLU_D,
  192. SLU_C,
  193. SLU_Z
  194. } Dtype_t;
  195. typedef enum
  196. {
  197. SLU_GE,
  198. SLU_TRLU,
  199. SLU_TRUU,
  200. SLU_TRL,
  201. SLU_TRU,
  202. SLU_SYL,
  203. SLU_SYU,
  204. SLU_HEL,
  205. SLU_HEU
  206. } Mtype_t;
  207. typedef struct
  208. {
  209. Stype_t Stype;
  210. Dtype_t Dtype;
  211. Mtype_t Mtype;
  212. int_t nrow;
  213. int_t ncol;
  214. void* Store;
  215. } SuperMatrix;
  216. typedef struct
  217. {
  218. int* panel_histo;
  219. double* utime;
  220. float* ops;
  221. int TinyPivots;
  222. int RefineSteps;
  223. int expansions;
  224. } SuperLUStat_t;
  225. typedef enum {NO, YES} yes_no_t;
  226. typedef enum {DOFACT, SamePattern, SamePattern_SameRowPerm, FACTORED} fact_t;
  227. typedef enum {NOROWPERM, LargeDiag, MY_PERMR} rowperm_t;
  228. typedef enum {NATURAL, MMD_ATA, MMD_AT_PLUS_A, COLAMD,
  229. METIS_AT_PLUS_A, PARMETIS, ZOLTAN, MY_PERMC} colperm_t;
  230. typedef enum {NOTRANS, TRANS, CONJ} trans_t;
  231. typedef enum {NOREFINE, SLU_SINGLE=1, SLU_DOUBLE, SLU_EXTRA} IterRefine_t;
  232. typedef enum {SYSTEM, USER} LU_space_t;
  233. typedef enum {ONE_NORM, TWO_NORM, INF_NORM} norm_t;
  234. typedef enum {SILU, SMILU_1, SMILU_2, SMILU_3} milu_t;
  235. typedef struct
  236. {
  237. fact_t Fact;
  238. yes_no_t Equil;
  239. colperm_t ColPerm;
  240. trans_t Trans;
  241. IterRefine_t IterRefine;
  242. double DiagPivotThresh;
  243. yes_no_t SymmetricMode;
  244. yes_no_t PivotGrowth;
  245. yes_no_t ConditionNumber;
  246. rowperm_t RowPerm;
  247. int ILU_DropRule;
  248. double ILU_DropTol;
  249. double ILU_FillFactor;
  250. norm_t ILU_Norm;
  251. double ILU_FillTol;
  252. milu_t ILU_MILU;
  253. double ILU_MILU_Dim;
  254. yes_no_t ParSymbFact;
  255. yes_no_t ReplaceTinyPivot;
  256. yes_no_t SolveInitialized;
  257. yes_no_t RefineInitialized;
  258. yes_no_t PrintStat;
  259. int nnzL, nnzU;
  260. int num_lookaheads;
  261. yes_no_t lookahead_etree;
  262. yes_no_t SymPattern;
  263. } superlu_options_t;
  264. typedef struct
  265. {
  266. float for_lu;
  267. float total_needed;
  268. } mem_usage_t;
  269. typedef struct
  270. {
  271. int_t nnz;
  272. void* nzval;
  273. int_t* rowind;
  274. int_t* colptr;
  275. } NCformat;
  276. typedef struct
  277. {
  278. int_t lda;
  279. void* nzval;
  280. } DNformat;
  281. typedef struct e_node
  282. {
  283. int size;
  284. void* mem;
  285. } ExpHeader;
  286. typedef struct
  287. {
  288. int size;
  289. int used;
  290. int top1;
  291. int top2;
  292. void* array;
  293. } LU_stack_t;
  294. typedef struct
  295. {
  296. int* xsup;
  297. int* supno;
  298. int* lsub;
  299. int* xlsub;
  300. void* lusup;
  301. int* xlusup;
  302. void* ucol;
  303. int* usub;
  304. int* xusub;
  305. int nzlmax;
  306. int nzumax;
  307. int nzlumax;
  308. int n;
  309. LU_space_t MemModel;
  310. int num_expansions;
  311. ExpHeader* expanders;
  312. LU_stack_t stack;
  313. } GlobalLU_t;
  314. }
  315. }
  316. #endif
  317. #endif