matrix_coop.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*************************************************************************
  2. * *
  3. * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. *
  4. * All rights reserved. Email: [email protected] Web: www.q12.org *
  5. * *
  6. * This library is free software; you can redistribute it and/or *
  7. * modify it under the terms of EITHER: *
  8. * (1) The GNU Lesser General Public License as published by the Free *
  9. * Software Foundation; either version 2.1 of the License, or (at *
  10. * your option) any later version. The text of the GNU Lesser *
  11. * General Public License is included with this library in the *
  12. * file LICENSE.TXT. *
  13. * (2) The BSD-style license that is included with this library in *
  14. * the file LICENSE-BSD.TXT. *
  15. * *
  16. * This library is distributed in the hope that it will be useful, *
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
  19. * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
  20. * *
  21. *************************************************************************/
  22. #ifndef _ODE_MATRIX_COOP_H_
  23. #define _ODE_MATRIX_COOP_H_
  24. #include <ode/common.h>
  25. #include <ode/cooperative.h>
  26. #include <ode/threading.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /**
  31. * @defgroup matrix_coop Matrix Cooperative Algorithms
  32. *
  33. * Cooperative algorithms operating on matrices and vectors.
  34. *
  35. * @ingroup coop
  36. */
  37. /**
  38. * @brief Estimates resource requirements for a @c dCooperativelyFactorLDLT call
  39. *
  40. * The function updates the contents of @a requirements to also suffice for calling
  41. * @c dCooperativelyFactorLDLT with the given parameters.
  42. *
  43. * Note: The requirements that could have already been in the @a requirements parameter
  44. * are never decreased.
  45. *
  46. * @param requirements The ResourceRequirements object to update
  47. * @param maximalAllowedThreadCount Maximal value of allowedThreadCount parameter that is going to be used
  48. * @param maximalRowCount Maximal value of rowCount parameter that is going to be used
  49. * @ingroup matrix_coop
  50. * @see dCooperativelyFactorLDLT
  51. * @see dResourceRequirementsCreate
  52. */
  53. ODE_API void dEstimateCooperativelyFactorLDLTResourceRequirements(dResourceRequirementsID requirements,
  54. unsigned maximalAllowedThreadCount, unsigned maximalRowCount);
  55. /**
  56. * @brief Cooperatively factorizes a matrix `A' into L*D*L'
  57. *
  58. * The function factorizes a matrix `A' into L*D*L', where `L' is lower triangular with ones on
  59. * the diagonal, and `D' is diagonal.
  60. * @a A is a rowCount*rowCount matrix stored by rows, with a leading dimension of @a rowCount rounded
  61. * up at least to 4 elements. `L; is written into the strict lower triangle of @a A
  62. * (the ones are not written) and the reciprocal of the diagonal elements of `D' are written into @a d.
  63. *
  64. * The @a resources must have had been allocated from a ResourceRequirements object
  65. * estimated in @c dEstimateCooperativelyFactorLDLTResourceRequirements.
  66. *
  67. * The operation is performed cooperatively by up to @a allowedThreadCount threads
  68. * from thread pool available in @a resources. The threading must must not be simultaneously
  69. * used (via other @c dResourceContainerID instances) in other calls that employ its features.
  70. *
  71. * @param resources The resources allocated for the function
  72. * @param allowedThreadCount Maximum thread count to use (the actual thread count could be less, depending on other parameters)
  73. * @param A The `A' matrix
  74. * @param d The `d' vector
  75. * @param rowCount The row count in @a A and @a d
  76. * @param rowskip The actual number of elements to be added to skip to next row in @a A
  77. * @ingroup matrix_coop
  78. * @see dEstimateCooperativelyFactorLDLTResourceRequirements
  79. * @see dResourceContainerAcquire
  80. * @see dCooperativelySolveLDLT
  81. */
  82. ODE_API void dCooperativelyFactorLDLT(dResourceContainerID resources, unsigned allowedThreadCount,
  83. dReal *A, dReal *d, unsigned rowCount, unsigned rowSkip);
  84. /**
  85. * @brief Estimates resource requirements for a @c dCooperativelySolveLDLT call
  86. *
  87. * The function updates the contents of @a requirements to also suffice for calling
  88. * @c dCooperativelySolveLDLT with the given parameters.
  89. *
  90. * Note: The requirements that could have already been in the @a requirements parameter
  91. * are never decreased.
  92. *
  93. * @param requirements The ResourceRequirements object to update
  94. * @param maximalAllowedThreadCount Maximal value of allowedThreadCount parameter that is going to be used
  95. * @param maximalRowCount Maximal value of rowCount parameter that is going to be used
  96. * @ingroup matrix_coop
  97. * @see dCooperativelySolveLDLT
  98. * @see dResourceRequirementsCreate
  99. */
  100. ODE_API void dEstimateCooperativelySolveLDLTResourceRequirements(dResourceRequirementsID requirements,
  101. unsigned maximalAllowedThreadCount, unsigned maximalRowCount);
  102. /**
  103. * @brief Cooperatively solves L*D*L'*x=b
  104. *
  105. * Given `L', a rowCount*rowCount lower triangular matrix with ones on the diagonal,
  106. * and `d', a rowCount*1 vector of the reciprocal diagonal elements of a rowCount*rowCount matrix
  107. * D, the function solves L*D*L'*x=b where `x' and `b' are rowCount*1.
  108. * The leading dimension of @a L is @a rowSkip. The resulting vector `x' overwrites @a b.
  109. *
  110. * The @a resources must have had been allocated from a ResourceRequirements object
  111. * estimated in @c dEstimateCooperativelySolveLDLTResourceRequirements.
  112. *
  113. * The operation is performed cooperatively by up to @a allowedThreadCount threads
  114. * from thread pool available in @a resources. The threading must must not be simultaneously
  115. * used (via other @c dResourceContainerID instances) in other calls that employ its features.
  116. *
  117. * @param resources The resources allocated for the function
  118. * @param allowedThreadCount Maximum thread count to use (the actual thread count could be less, depending on other parameters)
  119. * @param L The `L' matrix
  120. * @param d The `d' vector
  121. * @param b The `b' vector; also the result is stored here
  122. * @param rowCount The row count in @a L, @a d and @a b
  123. * @param rowskip The actual number of elements to be added to skip to next row in @a L
  124. * @ingroup matrix_coop
  125. * @see dEstimateCooperativelySolveLDLTResourceRequirements
  126. * @see dResourceContainerAcquire
  127. * @see dCooperativelyFactorLDLT
  128. */
  129. ODE_API void dCooperativelySolveLDLT(dResourceContainerID resources, unsigned allowedThreadCount,
  130. const dReal *L, const dReal *d, dReal *b, unsigned rowCount, unsigned rowSkip);
  131. /**
  132. * @brief Estimates resource requirements for a @c dCooperativelySolveL1Straight call
  133. *
  134. * The function updates the contents of @a requirements to also suffice for calling
  135. * @c dCooperativelySolveL1Straight with the given parameters.
  136. *
  137. * Note: The requirements that could have already been in the @a requirements parameter
  138. * are never decreased.
  139. *
  140. * @param requirements The ResourceRequirements object to update
  141. * @param maximalAllowedThreadCount Maximal value of allowedThreadCount parameter that is going to be used
  142. * @param maximalRowCount Maximal value of rowCount parameter that is going to be used
  143. * @ingroup matrix_coop
  144. * @see dCooperativelySolveL1Straight
  145. * @see dResourceRequirementsCreate
  146. */
  147. ODE_API void dEstimateCooperativelySolveL1StraightResourceRequirements(dResourceRequirementsID requirements,
  148. unsigned maximalAllowedThreadCount, unsigned maximalRowCount);
  149. /**
  150. * @brief Cooperatively solves L*x=b
  151. *
  152. * The function solves L*x=b, where `L' is rowCount*rowCount lower triangular with ones on the diagonal,
  153. * and `x', `b' are rowCount*1. The leading dimension of @a L is @a rowSkip.
  154. * @a b is overwritten with `x'.
  155. *
  156. * The @a resources must have had been allocated from a ResourceRequirements object
  157. * estimated in @c dEstimateCooperativelySolveL1StraightResourceRequirements.
  158. *
  159. * The operation is performed cooperatively by up to @a allowedThreadCount threads
  160. * from thread pool available in @a resources. The threading must must not be simultaneously
  161. * used (via other @c dResourceContainerID instances) in other calls that employ its features.
  162. *
  163. * @param resources The resources allocated for the function
  164. * @param allowedThreadCount Maximum thread count to use (the actual thread count could be less, depending on other parameters)
  165. * @param L The `L' matrix
  166. * @param b The `b' vector; also the result is stored here
  167. * @param rowCount The row count in @a L and @a b
  168. * @param rowskip The actual number of elements to be added to skip to next row in @a L
  169. * @ingroup matrix_coop
  170. * @see dEstimateCooperativelySolveL1StraightResourceRequirements
  171. * @see dResourceContainerAcquire
  172. * @see dCooperativelyFactorLDLT
  173. */
  174. ODE_API void dCooperativelySolveL1Straight(dResourceContainerID resources, unsigned allowedThreadCount,
  175. const dReal *L, dReal *b, unsigned rowCount, unsigned rowSkip);
  176. /**
  177. * @brief Estimates resource requirements for a @c dCooperativelySolveL1Transposed call
  178. *
  179. * The function updates the contents of @a requirements to also suffice for calling
  180. * @c dCooperativelySolveL1Transposed with the given parameters.
  181. *
  182. * Note: The requirements that could have already been in the @a requirements parameter
  183. * are never decreased.
  184. *
  185. * @param requirements The ResourceRequirements object to update
  186. * @param maximalAllowedThreadCount Maximal value of allowedThreadCount parameter that is going to be used
  187. * @param maximalRowCount Maximal value of rowCount parameter that is going to be used
  188. * @ingroup matrix_coop
  189. * @see dCooperativelySolveL1Transposed
  190. * @see dResourceRequirementsCreate
  191. */
  192. ODE_API void dEstimateCooperativelySolveL1TransposedResourceRequirements(dResourceRequirementsID requirements,
  193. unsigned maximalAllowedThreadCount, unsigned maximalRowCount);
  194. /**
  195. * @brief Cooperatively solves L'*x=b
  196. *
  197. * The function solves L'*x=b, where `L' is rowCount*rowCount lower triangular with ones on the diagonal,
  198. * and `x', b are rowCount*1. The leading dimension of @a L is @a rowSkip.
  199. * @a b is overwritten with `x'.
  200. *
  201. * The @a resources must have had been allocated from a ResourceRequirements object
  202. * estimated in @c dEstimateCooperativelySolveL1TransposedResourceRequirements.
  203. *
  204. * The operation is performed cooperatively by up to @a allowedThreadCount threads
  205. * from thread pool available in @a resources. The threading must must not be simultaneously
  206. * used (via other @c dResourceContainerID instances) in other calls that employ its features.
  207. *
  208. * @param resources The resources allocated for the function
  209. * @param allowedThreadCount Maximum thread count to use (the actual thread count could be less, depending on other parameters)
  210. * @param L The `L' matrix
  211. * @param b The `b' vector; also the result is stored here
  212. * @param rowCount The row count in @a L and @a b
  213. * @param rowskip The actual number of elements to be added to skip to next row in @a L
  214. * @ingroup matrix_coop
  215. * @see dEstimateCooperativelySolveL1TransposedResourceRequirements
  216. * @see dResourceContainerAcquire
  217. * @see dCooperativelyFactorLDLT
  218. */
  219. ODE_API void dCooperativelySolveL1Transposed(dResourceContainerID resources, unsigned allowedThreadCount,
  220. const dReal *L, dReal *b, unsigned rowCount, unsigned rowSkip);
  221. /**
  222. * @brief Estimates resource requirements for a @c dCooperativelyScaleVector call
  223. *
  224. * The function updates the contents of @a requirements to also suffice for calling
  225. * @c dCooperativelyScaleVector with the given parameters.
  226. *
  227. * Note: The requirements that could have already been in the @a requirements parameter
  228. * are never decreased.
  229. *
  230. * @param requirements The ResourceRequirements object to update
  231. * @param maximalAllowedThreadCount Maximal value of allowedThreadCount parameter that is going to be used
  232. * @param maximalElementCount Maximal value of elementCount parameter that is going to be used
  233. * @ingroup matrix_coop
  234. * @see dCooperativelyScaleVector
  235. * @see dResourceRequirementsCreate
  236. */
  237. ODE_API void dEstimateCooperativelyScaleVectorResourceRequirements(dResourceRequirementsID requirements,
  238. unsigned maximalAllowedThreadCount, unsigned maximalElementCount);
  239. /**
  240. * @brief Multiplies elements of one vector by corresponding element of another one
  241. *
  242. * In matlab syntax, the operation performed is: dataVector(1:elementCount) = dataVector(1:elementCount) .* scaleVector(1:elementCount)
  243. *
  244. * The @a resources must have had been allocated from a ResourceRequirements object
  245. * estimated in @c dEstimateCooperativelyScaleVectorResourceRequirements.
  246. *
  247. * The operation is performed cooperatively by up to @a allowedThreadCount threads
  248. * from thread pool available in @a resources. The threading must must not be simultaneously
  249. * used (via other @c dResourceContainerID instances) in other calls that employ its features.
  250. *
  251. * @param resources The resources allocated for the function
  252. * @param allowedThreadCount Maximum thread count to use (the actual thread count could be less, depending on other parameters)
  253. * @param dataVector The vector to be scaled in place
  254. * @param scaleVector The scale vector
  255. * @param elementCount The number of elements in @a dataVector and @a scaleVector
  256. * @ingroup matrix_coop
  257. * @see dEstimateCooperativelyScaleVectorResourceRequirements
  258. * @see dResourceContainerAcquire
  259. * @see dCooperativelyFactorLDLT
  260. */
  261. ODE_API void dCooperativelyScaleVector(dResourceContainerID resources, unsigned allowedThreadCount,
  262. dReal *dataVector, const dReal *scaleVector, unsigned elementCount);
  263. #ifdef __cplusplus
  264. } // extern "C"
  265. #endif
  266. #endif // #ifndef _ODE_MATRIX_COOP_H_