LAPACK 3.11.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 39 of file example_DGESV_rowmajor.c.

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