diff options
author | julie <julielangou@users.noreply.github.com> | 2013-02-15 21:54:15 +0000 |
---|---|---|
committer | julie <julielangou@users.noreply.github.com> | 2013-02-15 21:54:15 +0000 |
commit | 17c30cf73ea465c059c53de2aad3a79844bd2296 (patch) | |
tree | 8d28d43364f837f1257e43e81d814b7ede4ec589 /lapacke | |
parent | 01c8946882461657ab83c3a1a753ec6cc0b6964f (diff) | |
download | lapack-17c30cf73ea465c059c53de2aad3a79844bd2296.tar.gz lapack-17c30cf73ea465c059c53de2aad3a79844bd2296.tar.bz2 lapack-17c30cf73ea465c059c53de2aad3a79844bd2296.zip |
Update and add examples
Diffstat (limited to 'lapacke')
-rw-r--r-- | lapacke/example/CMakeLists.txt | 13 | ||||
-rw-r--r-- | lapacke/example/Makefile | 44 | ||||
-rw-r--r-- | lapacke/example/example_DGELS_colmajor.c | 96 | ||||
-rw-r--r-- | lapacke/example/example_DGELS_rowmajor.c | 96 | ||||
-rw-r--r-- | lapacke/example/example_DGESV_colmajor.c | 113 | ||||
-rw-r--r-- | lapacke/example/example_DGESV_rowmajor.c | 171 | ||||
-rw-r--r-- | lapacke/example/example_user.c | 97 | ||||
-rw-r--r-- | lapacke/example/lapacke_example_aux.c | 32 | ||||
-rw-r--r-- | lapacke/example/lapacke_example_aux.h | 9 |
9 files changed, 554 insertions, 117 deletions
diff --git a/lapacke/example/CMakeLists.txt b/lapacke/example/CMakeLists.txt index 9e00c94e..bf6b33df 100644 --- a/lapacke/example/CMakeLists.txt +++ b/lapacke/example/CMakeLists.txt @@ -1,8 +1,17 @@ -add_executable(xexample_DGESV_rowmajor example_DGESV_rowmajor.c) -add_executable(xexample_ZGESV_rowmajor example_ZGESV_rowmajor.c) +add_executable(xexample_DGESV_rowmajor example_DGESV_rowmajor.c lapacke_example_aux.c lapacke_example_aux.h) +add_executable(xexample_DGESV_colmajor example_DGESV_colmajor.c lapacke_example_aux.c lapacke_example_aux.h) +add_executable(xexample_DGELS_rowmajor example_DGELS_rowmajor.c lapacke_example_aux.c lapacke_example_aux.h) +add_executable(xexample_DGELS_colmajor example_DGELS_colmajor.c lapacke_example_aux.c lapacke_example_aux.h) +add_executable(xexample_ZGESV_rowmajor example_ZGESV_rowmajor.c lapacke_example_aux.c lapacke_example_aux.h) target_link_libraries(xexample_DGESV_rowmajor lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}) +target_link_libraries(xexample_DGESV_colmajor lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}) +target_link_libraries(xexample_DGELS_rowmajor lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}) +target_link_libraries(xexample_DGELS_colmajor lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}) target_link_libraries(xexample_ZGESV_rowmajor lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}) add_test(example_DGESV_rowmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGESV_rowmajor) +add_test(example_DGESV_colmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGESV_colmajor) +add_test(example_DGELS_rowmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGELS_rowmajor) +add_test(example_DGELS_colmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGELS_colmajor) add_test(example_ZGESV_rowmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_ZGESV_rowmajor) diff --git a/lapacke/example/Makefile b/lapacke/example/Makefile index 62064503..784bdce3 100644 --- a/lapacke/example/Makefile +++ b/lapacke/example/Makefile @@ -1,19 +1,45 @@ include ../../make.inc -all: xexample_DGESV_rowmajor xexample_ZGESV_rowmajor +all: xexample_DGESV_rowmajor \ + xexample_DGESV_colmajor \ + xexample_DGELS_rowmajor \ + xexample_DGELS_colmajor \ + xexample_ZGESV_rowmajor + +LIBRAIRIES= ../../$(LAPACKELIB) ../../$(LAPACKLIB) $(BLASLIB) -xexample_DGESV_rowmajor: example_DGESV_rowmajor.o ../../$(LAPACKLIB) ../../$(LAPACKELIB) - $(LOADER) $(LOADOPTS) example_DGESV_rowmajor.o \ - ../../$(LAPACKELIB) ../../$(LAPACKLIB) $(BLASLIB) -o $@ +# Double Precision Examples +xexample_DGESV_rowmajor: example_DGESV_rowmajor.o lapacke_example_aux.o $(LIBRAIRIES) + $(LOADER) $(LOADOPTS) example_DGESV_rowmajor.o lapacke_example_aux.o \ + $(LIBRAIRIES) -o $@ ./$@ -xexample_ZGESV_rowmajor: example_ZGESV_rowmajor.o ../../$(LAPACKLIB) ../../$(LAPACKELIB) - $(LOADER) $(LOADOPTS) example_ZGESV_rowmajor.o \ - ../../$(LAPACKELIB) ../../$(LAPACKLIB) $(BLASLIB) -o $@ +xexample_DGESV_colmajor: example_DGESV_colmajor.o lapacke_example_aux.o $(LIBRAIRIES) + $(LOADER) $(LOADOPTS) example_DGESV_colmajor.o lapacke_example_aux.o \ + $(LIBRAIRIES) -o $@ + ./$@ + +xexample_DGELS_rowmajor: example_DGELS_rowmajor.o lapacke_example_aux.o $(LIBRAIRIES) + $(LOADER) $(LOADOPTS) example_DGELS_rowmajor.o lapacke_example_aux.o \ + $(LIBRAIRIES) -o $@ + ./$@ + +xexample_DGELS_colmajor: example_DGELS_colmajor.o lapacke_example_aux.o $(LIBRAIRIES) + $(LOADER) $(LOADOPTS) example_DGELS_colmajor.o lapacke_example_aux.o \ + $(LIBRAIRIES) -o $@ + ./$@ + + + + +# Double Complex Precision Examples +xexample_ZGESV_rowmajor: example_ZGESV_rowmajor.o lapacke_example_aux.o $(LIBRAIRIES) + $(LOADER) $(LOADOPTS) example_ZGESV_rowmajor.o lapacke_example_aux.o \ + $(LIBRAIRIES) -o $@ ./$@ .c.o: - $(CC) -c $(CFLAGS) -I ../include -o $@ $< + $(CC) -c $(CFLAGS) -I. -I ../include -o $@ $< clean: - rm -f *.o xexample_DGESV_rowmajor xexample_ZGESV_rowmajor
\ No newline at end of file + rm -f *.o x*
\ No newline at end of file diff --git a/lapacke/example/example_DGELS_colmajor.c b/lapacke/example/example_DGELS_colmajor.c new file mode 100644 index 00000000..01394f9f --- /dev/null +++ b/lapacke/example/example_DGELS_colmajor.c @@ -0,0 +1,96 @@ +/* + LAPACKE Example : Calling DGELS using col-major order + ===================================================== + + The program computes the solution to the system of linear + equations with a square matrix A and multiple + right-hand sides B, where A is the coefficient matrix + and b is the right-hand side matrix: + + Description + =========== + + In this example, we wish solve the least squares problem min_x || B - Ax || + for two right-hand sides using the LAPACK routine DGELS. For input we will + use the 5-by-3 matrix + + ( 1 1 1 ) + ( 2 3 4 ) + A = ( 3 5 2 ) + ( 4 2 5 ) + ( 5 4 3 ) + and the 5-by-2 matrix + + ( -10 -3 ) + ( 12 14 ) + B = ( 14 12 ) + ( 16 16 ) + ( 18 16 ) + We will first store the input matrix as a static C two-dimensional array, + which is stored in col-major order, and let LAPACKE handle the work space + array allocation. The LAPACK base name for this function is gels, and we + will use double precision (d), so the LAPACKE function name is LAPACKE_dgels. + + lda=5 and ldb=5. The output for each right hand side is stored in b as + consecutive vectors of length 3. The correct answer for this problem is + the 3-by-2 matrix + + ( 2 1 ) + ( 1 1 ) + ( 1 2 ) + + A complete C program for this example is given below. Note that when the arrays + are passed to the LAPACK routine, they must be dereferenced, since LAPACK is + expecting arrays of type double *, not double **. + + + LAPACKE Interface + ================= + + LAPACKE_dgels (col-major, high-level) Example Program Results + + -- LAPACKE Example routine (version 3.5.0) -- + -- LAPACK is a software package provided by Univ. of Tennessee, -- + -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- + February 2012 + +*/ +/* Calling DGELS using col-major order */ + +/* Includes */ +#include <stdio.h> +#include <lapacke.h> +#include "lapacke_example_aux.h" + +/* Main program */ +int main (int argc, const char * argv[]) +{ + /* Locals */ + double A[5][3] = {1,2,3,4,5,1,3,5,2,4,1,4,2,5,3}; + double b[5][2] = {-10,12,14,16,18,-3,14,12,16,16}; + lapack_int info,m,n,lda,ldb,nrhs; + int i,j; + + /* Initialization */ + m = 5; + n = 3; + nrhs = 2; + lda = 5; + ldb = 5; + + /* Print Entry Matrix */ + print_matrix_colmajor( "Entry Matrix A", m, n, *A, lda ); + /* Print Right Rand Side */ + print_matrix_colmajor( "Right Hand Side b", n, nrhs, *b, ldb ); + printf( "\n" ); + + /* Executable statements */ + printf( "LAPACKE_dgels (col-major, high-level) Example Program Results\n" ); + /* Solve least squares problem*/ + info = LAPACKE_dgels(LAPACK_COL_MAJOR,'N',m,n,nrhs,*A,lda,*b,ldb); + + /* Print Solution */ + print_matrix_colmajor( "Solution", n, nrhs, *b, ldb ); + printf( "\n" ); + exit( 0 ); +} /* End of LAPACKE_dgels Example */
\ No newline at end of file diff --git a/lapacke/example/example_DGELS_rowmajor.c b/lapacke/example/example_DGELS_rowmajor.c new file mode 100644 index 00000000..034c0196 --- /dev/null +++ b/lapacke/example/example_DGELS_rowmajor.c @@ -0,0 +1,96 @@ +/* + LAPACKE Example : Calling DGELS using row-major order + ===================================================== + + The program computes the solution to the system of linear + equations with a square matrix A and multiple + right-hand sides B, where A is the coefficient matrix + and b is the right-hand side matrix: + + Description + =========== + + In this example, we wish solve the least squares problem min_x || B - Ax || + for two right-hand sides using the LAPACK routine DGELS. For input we will + use the 5-by-3 matrix + + ( 1 1 1 ) + ( 2 3 4 ) + A = ( 3 5 2 ) + ( 4 2 5 ) + ( 5 4 3 ) + and the 5-by-2 matrix + + ( -10 -3 ) + ( 12 14 ) + B = ( 14 12 ) + ( 16 16 ) + ( 18 16 ) + We will first store the input matrix as a static C two-dimensional array, + which is stored in row-major order, and let LAPACKE handle the work space + array allocation. The LAPACK base name for this function is gels, and we + will use double precision (d), so the LAPACKE function name is LAPACKE_dgels. + + thus lda=3 and ldb=2. The output for each right hand side is stored in b as + consecutive vectors of length 3. The correct answer for this problem is + the 3-by-2 matrix + + ( 2 1 ) + ( 1 1 ) + ( 1 2 ) + + A complete C program for this example is given below. Note that when the arrays + are passed to the LAPACK routine, they must be dereferenced, since LAPACK is + expecting arrays of type double *, not double **. + + + LAPACKE Interface + ================= + + LAPACKE_dgels (row-major, high-level) Example Program Results + + -- LAPACKE Example routine (version 3.5.0) -- + -- LAPACK is a software package provided by Univ. of Tennessee, -- + -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- + February 2012 + +*/ +/* Calling DGELS using row-major order */ + +/* Includes */ +#include <stdio.h> +#include <lapacke.h> +#include "lapacke_example_aux.h" + +/* Main program */ +int main (int argc, const char * argv[]) +{ + /* Locals */ + double A[5][3] = {1,1,1,2,3,4,3,5,2,4,2,5,5,4,3}; + double b[5][2] = {-10,-3,12,14,14,12,16,16,18,16}; + lapack_int info,m,n,lda,ldb,nrhs; + int i,j; + + /* Initialization */ + m = 5; + n = 3; + nrhs = 2; + lda = 3; + ldb = 2; + + /* Print Entry Matrix */ + print_matrix_rowmajor( "Entry Matrix A", m, n, *A, lda ); + /* Print Right Rand Side */ + print_matrix_rowmajor( "Right Hand Side b", n, nrhs, *b, ldb ); + printf( "\n" ); + + /* Executable statements */ + printf( "LAPACKE_dgels (row-major, high-level) Example Program Results\n" ); + /* Solve least squares problem*/ + info = LAPACKE_dgels(LAPACK_ROW_MAJOR,'N',m,n,nrhs,*A,lda,*b,ldb); + + /* Print Solution */ + print_matrix_rowmajor( "Solution", n, nrhs, *b, ldb ); + printf( "\n" ); + exit( 0 ); +} /* End of LAPACKE_dgels Example */
\ No newline at end of file diff --git a/lapacke/example/example_DGESV_colmajor.c b/lapacke/example/example_DGESV_colmajor.c new file mode 100644 index 00000000..20b3f662 --- /dev/null +++ b/lapacke/example/example_DGESV_colmajor.c @@ -0,0 +1,113 @@ +/* + LAPACKE_dgesv Example + ===================== + + The program computes the solution to the system of linear + equations with a square matrix A and multiple + right-hand sides B, where A is the coefficient matrix + and b is the right-hand side matrix: + + Description + =========== + + The routine solves for X the system of linear equations A*X = B, + where A is an n-by-n matrix, the columns of matrix B are individual + right-hand sides, and the columns of X are the corresponding + solutions. + + The LU decomposition with partial pivoting and row interchanges is + used to factor A as A = P*L*U, where P is a permutation matrix, L + is unit lower triangular, and U is upper triangular. The factored + form of A is then used to solve the system of equations A*X = B. + + LAPACKE Interface + ================= + + LAPACKE_dgesv (col-major, high-level) Example Program Results + + -- LAPACKE Example routine (version 3.5.0) -- + -- LAPACK is a software package provided by Univ. of Tennessee, -- + -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- + February 2012 + +*/ +/* Includes */ +#include <stdlib.h> +#include <stdio.h> +#include "lapacke.h" +#include "lapacke_example_aux.h" + +/* Main program */ +int main(int argc, char **argv) { + + /* Locals */ + lapack_int n, nrhs, lda, ldb, info; + int i, j; + double t1,t2,elapsed; + struct timeval tp; + int rtn; + double normr, normb; + /* Local arrays */ + double *A, *b, *Acopy, *bcopy; + lapack_int *ipiv; + + /* Default Value */ + n = 5; nrhs = 1; + + /* Arguments */ + for( i = 1; i < argc; i++ ) { + if( strcmp( argv[i], "-n" ) == 0 ) { + n = atoi(argv[i+1]); + i++; + } + if( strcmp( argv[i], "-nrhs" ) == 0 ) { + nrhs = atoi(argv[i+1]); + i++; + } + } + + /* Initialization */ + lda=n, ldb=n; + A = (double *)malloc(n*n*sizeof(double)) ; + if (A==NULL){ printf("error of memory allocation\n"); exit(0); } + b = (double *)malloc(n*nrhs*sizeof(double)) ; + if (b==NULL){ printf("error of memory allocation\n"); exit(0); } + ipiv = (lapack_int *)malloc(n*sizeof(lapack_int)) ; + if (ipiv==NULL){ printf("error of memory allocation\n"); exit(0); } + + for( i = 0; i < n; i++ ) { + for( j = 0; j < n; j++ ) A[i+j*lda] = ((double) rand()) / ((double) RAND_MAX) - 0.5; + } + + for(i=0;i<n*nrhs;i++) + b[i] = ((double) rand()) / ((double) RAND_MAX) - 0.5; + + /* Print Entry Matrix */ + print_matrix_colmajor( "Entry Matrix A", n, n, A, lda ); + /* Print Right Rand Side */ + print_matrix_colmajor( "Right Rand Side b", n, nrhs, b, ldb ); + printf( "\n" ); + + /* Executable statements */ + printf( "LAPACKE_dgesv (row-major, high-level) Example Program Results\n" ); + /* Solve the equations A*X = B */ + info = LAPACKE_dgesv( LAPACK_COL_MAJOR, n, nrhs, A, lda, ipiv, + b, ldb ); + + /* Check for the exact singularity */ + if( info > 0 ) { + printf( "The diagonal element of the triangular factor of A,\n" ); + printf( "U(%i,%i) is zero, so that A is singular;\n", info, info ); + printf( "the solution could not be computed.\n" ); + exit( 1 ); + } + if (info <0) exit( 1 ); + /* Print solution */ + print_matrix_colmajor( "Solution", n, nrhs, b, ldb ); + /* Print details of LU factorization */ + print_matrix_colmajor( "Details of LU factorization", n, n, A, lda ); + /* Print pivot indices */ + print_vector( "Pivot indices", n, ipiv ); + exit( 0 ); +} /* End of LAPACKE_dgesv Example */ + diff --git a/lapacke/example/example_DGESV_rowmajor.c b/lapacke/example/example_DGESV_rowmajor.c index a932e809..b4d3bef8 100644 --- a/lapacke/example/example_DGESV_rowmajor.c +++ b/lapacke/example/example_DGESV_rowmajor.c @@ -1,44 +1,14 @@ -/******************************************************************************* -* Copyright (C) 2009-2011 Intel Corporation. All Rights Reserved. -* The information and material ("Material") provided below is owned by Intel -* Corporation or its suppliers or licensors, and title to such Material remains -* with Intel Corporation or its suppliers or licensors. The Material contains -* proprietary information of Intel or its suppliers and licensors. The Material -* is protected by worldwide copyright laws and treaty provisions. No part of -* the Material may be copied, reproduced, published, uploaded, posted, -* transmitted, or distributed in any way without Intel's prior express written -* permission. No license under any patent, copyright or other intellectual -* property rights in the Material is granted to or conferred upon you, either -* expressly, by implication, inducement, estoppel or otherwise. Any license -* under such intellectual property rights must be express and approved by Intel -* in writing. -* -******************************************************************************** -*/ /* - LAPACKE_dgesv Example. - ====================== + LAPACKE_dgesv Example + ===================== The program computes the solution to the system of linear equations with a square matrix A and multiple - right-hand sides B, where A is the coefficient matrix: - - 6.80 -6.05 -0.45 8.32 -9.67 - -2.11 -3.30 2.58 2.71 -5.14 - 5.66 5.36 -2.70 4.35 -7.26 - 5.97 -4.44 0.27 -7.17 6.08 - 8.23 1.08 9.04 2.14 -6.87 - - and B is the right-hand side matrix: - - 4.02 -1.56 9.81 - 6.19 4.00 -4.09 - -8.22 -8.67 -4.57 - -7.57 1.75 -8.61 - -3.03 2.86 8.99 - - Description. - ============ + right-hand sides B, where A is the coefficient matrix + and b is the right-hand side matrix: + + Description + =========== The routine solves for X the system of linear equations A*X = B, where A is an n-by-n matrix, the columns of matrix B are individual @@ -50,71 +20,76 @@ is unit lower triangular, and U is upper triangular. The factored form of A is then used to solve the system of equations A*X = B. - Example Program Results. - ======================== - - LAPACKE_dgesv (row-major, high-level) Example Program Results + LAPACKE Interface + ================= - Solution - -0.80 -0.39 0.96 - -0.70 -0.55 0.22 - 0.59 0.84 1.90 - 1.32 -0.10 5.36 - 0.57 0.11 4.04 + LAPACKE_dgesv (row-major, high-level) Example Program Results - Details of LU factorization - 8.23 1.08 9.04 2.14 -6.87 - 0.83 -6.94 -7.92 6.55 -3.99 - 0.69 -0.67 -14.18 7.24 -5.19 - 0.73 0.75 0.02 -13.82 14.19 - -0.26 0.44 -0.59 -0.34 -3.43 + -- LAPACKE Example routine (version 3.5.0) -- + -- LAPACK is a software package provided by Univ. of Tennessee, -- + -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- + February 2012 - Pivot indices - 5 5 3 4 5 */ #include <stdlib.h> #include <stdio.h> -#include "lapacke.h" - -/* Auxiliary routines prototypes */ -extern void print_matrix( char* desc, lapack_int m, lapack_int n, double* a, lapack_int lda ); -extern void print_int_vector( char* desc, lapack_int n, lapack_int* a ); - -/* Parameters */ -#define N 5 -#define NRHS 3 -#define LDA N -#define LDB NRHS +#include <lapacke.h> +#include "lapacke_example_aux.h" /* Main program */ -int main() { +int main(int argc, char **argv) { + /* Locals */ - lapack_int n = N, nrhs = NRHS, lda = LDA, ldb = LDB, info; + lapack_int n, nrhs, lda, ldb, info; + int i, j; + double t1,t2,elapsed; + struct timeval tp; + int rtn; + double normr, normb; /* Local arrays */ - lapack_int ipiv[N]; - double a[LDA*N] = { - 6.80, -6.05, -0.45, 8.32, -9.67, - -2.11, -3.30, 2.58, 2.71, -5.14, - 5.66, 5.36, -2.70, 4.35, -7.26, - 5.97, -4.44, 0.27, -7.17, 6.08, - 8.23, 1.08, 9.04, 2.14, -6.87 - }; - double b[LDB*N] = { - 4.02, -1.56, 9.81, - 6.19, 4.00, -4.09, - -8.22, -8.67, -4.57, - -7.57, 1.75, -8.61, - -3.03, 2.86, 8.99 - }; + double *A, *b, *Acopy, *bcopy; + lapack_int *ipiv; + + /* Default Value */ + n = 5; nrhs = 1; + + /* Arguments */ + for( i = 1; i < argc; i++ ) { + if( strcmp( argv[i], "-n" ) == 0 ) { + n = atoi(argv[i+1]); + i++; + } + if( strcmp( argv[i], "-nrhs" ) == 0 ) { + nrhs = atoi(argv[i+1]); + i++; + } + } + + /* Initialization */ + lda=n, ldb=nrhs; + A = (double *)malloc(n*n*sizeof(double)) ; + if (A==NULL){ printf("error of memory allocation\n"); exit(0); } + b = (double *)malloc(n*nrhs*sizeof(double)) ; + if (b==NULL){ printf("error of memory allocation\n"); exit(0); } + ipiv = (lapack_int *)malloc(n*sizeof(lapack_int)) ; + if (ipiv==NULL){ printf("error of memory allocation\n"); exit(0); } + + for( i = 0; i < n; i++ ) { + for( j = 0; j < n; j++ ) A[i*lda+j] = ((double) rand()) / ((double) RAND_MAX) - 0.5; + } + + for(i=0;i<n*nrhs;i++) + b[i] = ((double) rand()) / ((double) RAND_MAX) - 0.5; + /* Print Entry Matrix */ - print_matrix( "Entry Matrix A", n, n, a, lda ); + print_matrix_rowmajor( "Entry Matrix A", n, n, A, lda ); /* Print Right Rand Side */ - print_matrix( "Right Rand Side", n, nrhs, b, ldb ); + print_matrix_rowmajor( "Right Rand Side b", n, nrhs, b, ldb ); printf( "\n" ); /* Executable statements */ printf( "LAPACKE_dgesv (row-major, high-level) Example Program Results\n" ); /* Solve the equations A*X = B */ - info = LAPACKE_dgesv( LAPACK_ROW_MAJOR, n, nrhs, a, lda, ipiv, + info = LAPACKE_dgesv( LAPACK_ROW_MAJOR, n, nrhs, A, lda, ipiv, b, ldb ); /* Check for the exact singularity */ if( info > 0 ) { @@ -123,29 +98,13 @@ int main() { printf( "the solution could not be computed.\n" ); exit( 1 ); } + if (info <0) exit( 1 ); /* Print solution */ - print_matrix( "Solution", n, nrhs, b, ldb ); + print_matrix_rowmajor( "Solution", n, nrhs, b, ldb ); /* Print details of LU factorization */ - print_matrix( "Details of LU factorization", n, n, a, lda ); + print_matrix_rowmajor( "Details of LU factorization", n, n, A, lda ); /* Print pivot indices */ - print_int_vector( "Pivot indices", n, ipiv ); + print_vector( "Pivot indices", n, ipiv ); exit( 0 ); } /* End of LAPACKE_dgesv Example */ -/* Auxiliary routine: printing a matrix */ -void print_matrix( char* desc, lapack_int m, lapack_int n, double* a, lapack_int lda ) { - lapack_int i, j; - printf( "\n %s\n", desc ); - for( i = 0; i < m; i++ ) { - for( j = 0; j < n; j++ ) printf( " %6.2f", a[i*lda+j] ); - printf( "\n" ); - } -} - -/* Auxiliary routine: printing a vector of integers */ -void print_int_vector( char* desc, lapack_int n, lapack_int* a ) { - lapack_int j; - printf( "\n %s\n", desc ); - for( j = 0; j < n; j++ ) printf( " %6i", a[j] ); - printf( "\n" ); -} diff --git a/lapacke/example/example_user.c b/lapacke/example/example_user.c new file mode 100644 index 00000000..3fcccca3 --- /dev/null +++ b/lapacke/example/example_user.c @@ -0,0 +1,97 @@ +#include <stdlib.h> +#include <stdio.h> +#include "lapacke.h" + +/* Auxiliary routines prototypes */ +extern void print_matrix( char* desc, lapack_int m, lapack_int n, double* a, lapack_int lda ); +extern void print_int_vector( char* desc, lapack_int n, lapack_int* a ); + +/* Parameters */ +#define N 5 +#define NRHS 3 +#define LDA N +#define LDB NRHS + +/* Main program */ +int main() { + /* Locals */ + lapack_int n = N, nrhs = NRHS, lda = LDA, ldb = LDB, info; + /* Local arrays */ + lapack_int ipiv[N]; + double a[LDA*N] = { + 6.80, -6.05, -0.45, 8.32, -9.67, + -2.11, -3.30, 2.58, 2.71, -5.14, + 5.66, 5.36, -2.70, 4.35, -7.26, + 5.97, -4.44, 0.27, -7.17, 6.08, + 8.23, 1.08, 9.04, 2.14, -6.87 + }; + double b[LDB*N] = { + 4.02, -1.56, 9.81, + 6.19, 4.00, -4.09, + -8.22, -8.67, -4.57, + -7.57, 1.75, -8.61, + -3.03, 2.86, 8.99 + }; + + double aNorm; + double rcond; + char ONE_NORM = '1'; + lapack_int NROWS = n; + lapack_int NCOLS = n; + lapack_int LEADING_DIMENSION_A = n; + + /* Print Entry Matrix */ + print_matrix( "Entry Matrix A", n, n, a, lda ); + /* Print Right Rand Side */ + print_matrix( "Right Rand Side", n, nrhs, b, ldb ); + printf( "\n" ); + /* Executable statements */ + printf( "LAPACKE_dgecon Example Program Results\n" ); + aNorm = LAPACKE_dlange(LAPACK_ROW_MAJOR, ONE_NORM, NROWS, NCOLS, a, LEADING_DIMENSION_A); + info = LAPACKE_dgetrf(LAPACK_ROW_MAJOR, NROWS, NCOLS, a, LEADING_DIMENSION_A, ipiv); + info = LAPACKE_dgecon(LAPACK_ROW_MAJOR, ONE_NORM, n, a, LEADING_DIMENSION_A, aNorm, &rcond); // aNorm should be 35.019999999999996 + double work[4*N]; + int iwork[N]; + //info = LAPACKE_dgecon_work(LAPACK_ROW_MAJOR, ONE_NORM, n, a, LEADING_DIMENSION_A, aNorm, &rcond, work, iwork); // aNorm should be 35.019999999999996 + //dgecon_( &ONE_NORM, &n, a, &LEADING_DIMENSION_A, &aNorm, &rcond, work, iwork, &info ); + /* Check for the exact singularity */ + if (info == 0) + { + printf("LAPACKE_dgecon completed SUCCESSFULLY...\n"); + } + else if ( info < 0 ) + { + printf( "Element %d of A had an illegal value\n", -info ); + exit( 1 ); + } + else + { + printf( "Unrecognized value of INFO = %d\n", info ); + exit( 1 ); + } + + /* Print solution */ + printf("LAPACKE_dlange / One-norm of A = %lf\n", aNorm); + printf("LAPACKE_dgecon / RCOND of A = %f\n", rcond); + exit( 0 ); +} /* End of LAPACKE_dgesv Example */ + +/* Auxiliary routine: printing a matrix */ +void print_matrix( char* desc, lapack_int m, lapack_int n, double* a, lapack_int lda ) { + lapack_int i, j; + printf( "\n %s\n", desc ); + for( i = 0; i < m; i++ ) { + for( j = 0; j < n; j++ ) printf( " %6.2f", a[i*lda+j] ); + printf( "\n" ); + } +} + +/* Auxiliary routine: printing a vector of integers */ +void print_int_vector( char* desc, lapack_int n, lapack_int* a ) { + lapack_int j; + printf( "\n %s\n", desc ); + for( j = 0; j < n; j++ ) printf( " %6i", a[j] ); + printf( "\n" ); +} + +
\ No newline at end of file diff --git a/lapacke/example/lapacke_example_aux.c b/lapacke/example/lapacke_example_aux.c new file mode 100644 index 00000000..d659d6a4 --- /dev/null +++ b/lapacke/example/lapacke_example_aux.c @@ -0,0 +1,32 @@ +#include <lapacke.h> + +/* Auxiliary routine: printing a matrix */ +void print_matrix_rowmajor( char* desc, lapack_int m, lapack_int n, double* mat, lapack_int ldm ) { + lapack_int i, j; + printf( "\n %s\n", desc ); + + for( i = 0; i < m; i++ ) { + for( j = 0; j < n; j++ ) printf( " %6.2f", mat[i*ldm+j] ); + printf( "\n" ); + } +} + + +/* Auxiliary routine: printing a matrix */ +void print_matrix_colmajor( char* desc, lapack_int m, lapack_int n, double* mat, lapack_int ldm ) { + lapack_int i, j; + printf( "\n %s\n", desc ); + + for( i = 0; i < m; i++ ) { + for( j = 0; j < n; j++ ) printf( " %6.2f", mat[i+j*ldm] ); + printf( "\n" ); + } +} + +/* Auxiliary routine: printing a vector of integers */ +void print_vector( char* desc, lapack_int n, lapack_int* vec ) { + lapack_int j; + printf( "\n %s\n", desc ); + for( j = 0; j < n; j++ ) printf( " %6i", vec[j] ); + printf( "\n" ); +} diff --git a/lapacke/example/lapacke_example_aux.h b/lapacke/example/lapacke_example_aux.h new file mode 100644 index 00000000..f8335115 --- /dev/null +++ b/lapacke/example/lapacke_example_aux.h @@ -0,0 +1,9 @@ +#ifndef _LAPACKE_EXAMPLE_AUX_ +#define _LAPACKE_EXAMPLE_AUX_ + + +void print_matrix_rowmajor( char* desc, lapack_int m, lapack_int n, double* mat, lapack_int ldm ); +void print_matrix_colmajor( char* desc, lapack_int m, lapack_int n, double* mat, lapack_int ldm ); +void print_vector( char* desc, lapack_int n, lapack_int* vec ); + +#endif /* _LAPACKE_EXAMPLE_AUX_*/ |