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