LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
int main ( int  argc,
char **  argv 
)

Definition at line 42 of file example_DGESV_colmajor.c.

42  {
43 
44  /* Locals */
45  lapack_int n, nrhs, lda, ldb, info;
46  int i, j;
47  /* Local arrays */
48  double *A, *b;
49  lapack_int *ipiv;
50 
51  /* Default Value */
52  n = 5; nrhs = 1;
53 
54  /* Arguments */
55  for( i = 1; i < argc; i++ ) {
56  if( strcmp( argv[i], "-n" ) == 0 ) {
57  n = atoi(argv[i+1]);
58  i++;
59  }
60  if( strcmp( argv[i], "-nrhs" ) == 0 ) {
61  nrhs = atoi(argv[i+1]);
62  i++;
63  }
64  }
65 
66  /* Initialization */
67  lda=n, ldb=n;
68  A = (double *)malloc(n*n*sizeof(double)) ;
69  if (A==NULL){ printf("error of memory allocation\n"); exit(0); }
70  b = (double *)malloc(n*nrhs*sizeof(double)) ;
71  if (b==NULL){ printf("error of memory allocation\n"); exit(0); }
72  ipiv = (lapack_int *)malloc(n*sizeof(lapack_int)) ;
73  if (ipiv==NULL){ printf("error of memory allocation\n"); exit(0); }
74 
75  for( i = 0; i < n; i++ ) {
76  for( j = 0; j < n; j++ ) A[i+j*lda] = ((double) rand()) / ((double) RAND_MAX) - 0.5;
77  }
78 
79  for(i=0;i<n*nrhs;i++)
80  b[i] = ((double) rand()) / ((double) RAND_MAX) - 0.5;
81 
82  /* Print Entry Matrix */
83  print_matrix_colmajor( "Entry Matrix A", n, n, A, lda );
84  /* Print Right Rand Side */
85  print_matrix_colmajor( "Right Rand Side b", n, nrhs, b, ldb );
86  printf( "\n" );
87 
88  /* Executable statements */
89  printf( "LAPACKE_dgesv (row-major, high-level) Example Program Results\n" );
90  /* Solve the equations A*X = B */
91  info = LAPACKE_dgesv( LAPACK_COL_MAJOR, n, nrhs, A, lda, ipiv,
92  b, ldb );
93 
94  /* Check for the exact singularity */
95  if( info > 0 ) {
96  printf( "The diagonal element of the triangular factor of A,\n" );
97  printf( "U(%i,%i) is zero, so that A is singular;\n", info, info );
98  printf( "the solution could not be computed.\n" );
99  exit( 1 );
100  }
101  if (info <0) exit( 1 );
102  /* Print solution */
103  print_matrix_colmajor( "Solution", n, nrhs, b, ldb );
104  /* Print details of LU factorization */
105  print_matrix_colmajor( "Details of LU factorization", n, n, A, lda );
106  /* Print pivot indices */
107  print_vector( "Pivot indices", n, ipiv );
108  exit( 0 );
109 } /* End of LAPACKE_dgesv Example */
void print_vector(char *desc, lapack_int n, lapack_int *vec)
lapack_int LAPACKE_dgesv(int matrix_layout, lapack_int n, lapack_int nrhs, double *a, lapack_int lda, lapack_int *ipiv, double *b, lapack_int ldb)
Definition: lapacke_dgesv.c:36
void print_matrix_colmajor(char *desc, lapack_int m, lapack_int n, double *mat, lapack_int ldm)
#define LAPACK_COL_MAJOR
Definition: lapacke.h:120
#define lapack_int
Definition: lapacke.h:47

Here is the call graph for this function: