You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

example_user.c 3.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "lapacke.h"
  4. /* Auxiliary routines prototypes */
  5. extern void print_matrix( char* desc, lapack_int m, lapack_int n, double* a, lapack_int lda );
  6. extern void print_int_vector( char* desc, lapack_int n, lapack_int* a );
  7. /* Parameters */
  8. #define N 5
  9. #define NRHS 3
  10. #define LDA N
  11. #define LDB NRHS
  12. /* Main program */
  13. int main() {
  14. /* Locals */
  15. lapack_int n = N, nrhs = NRHS, lda = LDA, ldb = LDB, info;
  16. /* Local arrays */
  17. lapack_int ipiv[N];
  18. double a[LDA*N] = {
  19. 6.80, -6.05, -0.45, 8.32, -9.67,
  20. -2.11, -3.30, 2.58, 2.71, -5.14,
  21. 5.66, 5.36, -2.70, 4.35, -7.26,
  22. 5.97, -4.44, 0.27, -7.17, 6.08,
  23. 8.23, 1.08, 9.04, 2.14, -6.87
  24. };
  25. double b[LDB*N] = {
  26. 4.02, -1.56, 9.81,
  27. 6.19, 4.00, -4.09,
  28. -8.22, -8.67, -4.57,
  29. -7.57, 1.75, -8.61,
  30. -3.03, 2.86, 8.99
  31. };
  32. double aNorm;
  33. double rcond;
  34. char ONE_NORM = '1';
  35. lapack_int NROWS = n;
  36. lapack_int NCOLS = n;
  37. lapack_int LEADING_DIMENSION_A = n;
  38. /* Print Entry Matrix */
  39. print_matrix( "Entry Matrix A", n, n, a, lda );
  40. /* Print Right Rand Side */
  41. print_matrix( "Right Rand Side", n, nrhs, b, ldb );
  42. printf( "\n" );
  43. /* Executable statements */
  44. printf( "LAPACKE_dgecon Example Program Results\n" );
  45. aNorm = LAPACKE_dlange(LAPACK_ROW_MAJOR, ONE_NORM, NROWS, NCOLS, a, LEADING_DIMENSION_A);
  46. info = LAPACKE_dgetrf(LAPACK_ROW_MAJOR, NROWS, NCOLS, a, LEADING_DIMENSION_A, ipiv);
  47. info = LAPACKE_dgecon(LAPACK_ROW_MAJOR, ONE_NORM, n, a, LEADING_DIMENSION_A, aNorm, &rcond); // aNorm should be 35.019999999999996
  48. double work[4*N];
  49. int iwork[N];
  50. //info = LAPACKE_dgecon_work(LAPACK_ROW_MAJOR, ONE_NORM, n, a, LEADING_DIMENSION_A, aNorm, &rcond, work, iwork); // aNorm should be 35.019999999999996
  51. //dgecon_( &ONE_NORM, &n, a, &LEADING_DIMENSION_A, &aNorm, &rcond, work, iwork, &info );
  52. /* Check for the exact singularity */
  53. if (info == 0)
  54. {
  55. printf("LAPACKE_dgecon completed SUCCESSFULLY...\n");
  56. }
  57. else if ( info < 0 )
  58. {
  59. printf( "Element %d of A had an illegal value\n", -info );
  60. exit( 1 );
  61. }
  62. else
  63. {
  64. printf( "Unrecognized value of INFO = %d\n", info );
  65. exit( 1 );
  66. }
  67. /* Print solution */
  68. printf("LAPACKE_dlange / One-norm of A = %lf\n", aNorm);
  69. printf("LAPACKE_dgecon / RCOND of A = %f\n", rcond);
  70. exit( 0 );
  71. } /* End of LAPACKE_dgesv Example */
  72. /* Auxiliary routine: printing a matrix */
  73. void print_matrix( char* desc, lapack_int m, lapack_int n, double* a, lapack_int lda ) {
  74. lapack_int i, j;
  75. printf( "\n %s\n", desc );
  76. for( i = 0; i < m; i++ ) {
  77. for( j = 0; j < n; j++ ) printf( " %6.2f", a[i*lda+j] );
  78. printf( "\n" );
  79. }
  80. }
  81. /* Auxiliary routine: printing a vector of integers */
  82. void print_int_vector( char* desc, lapack_int n, lapack_int* a ) {
  83. lapack_int j;
  84. printf( "\n %s\n", desc );
  85. for( j = 0; j < n; j++ ) printf( " %6i", a[j] );
  86. printf( "\n" );
  87. }