LAPACK  3.10.1 LAPACK: Linear Algebra PACKage

## ◆ main()

 int main ( int argc, char ** argv )

Definition at line 40 of file example_DGESV_colmajor.c.

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