You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

example_ZGESV_rowmajor.c 6.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*******************************************************************************
  2. * Copyright (C) 2009-2011 Intel Corporation. All Rights Reserved.
  3. * The information and material ("Material") provided below is owned by Intel
  4. * Corporation or its suppliers or licensors, and title to such Material remains
  5. * with Intel Corporation or its suppliers or licensors. The Material contains
  6. * proprietary information of Intel or its suppliers and licensors. The Material
  7. * is protected by worldwide copyright laws and treaty provisions. No part of
  8. * the Material may be copied, reproduced, published, uploaded, posted,
  9. * transmitted, or distributed in any way without Intel's prior express written
  10. * permission. No license under any patent, copyright or other intellectual
  11. * property rights in the Material is granted to or conferred upon you, either
  12. * expressly, by implication, inducement, estoppel or otherwise. Any license
  13. * under such intellectual property rights must be express and approved by Intel
  14. * in writing.
  15. *
  16. ********************************************************************************
  17. */
  18. /*
  19. LAPACKE_zgesv Example.
  20. ======================
  21. The program computes the solution to the system of linear
  22. equations with a square matrix A and multiple
  23. right-hand sides B, where A is the coefficient matrix:
  24. ( 1.23, -5.50) ( 7.91, -5.38) ( -9.80, -4.86) ( -7.32, 7.57)
  25. ( -2.14, -1.12) ( -9.92, -0.79) ( -9.18, -1.12) ( 1.37, 0.43)
  26. ( -4.30, -7.10) ( -6.47, 2.52) ( -6.51, -2.67) ( -5.86, 7.38)
  27. ( 1.27, 7.29) ( 8.90, 6.92) ( -8.82, 1.25) ( 5.41, 5.37)
  28. and B is the right-hand side matrix:
  29. ( 8.33, -7.32) ( -6.11, -3.81)
  30. ( -6.18, -4.80) ( 0.14, -7.71)
  31. ( -5.71, -2.80) ( 1.41, 3.40)
  32. ( -1.60, 3.08) ( 8.54, -4.05)
  33. Description.
  34. ============
  35. The routine solves for X the system of linear equations A*X = B,
  36. where A is an n-by-n matrix, the columns of matrix B are individual
  37. right-hand sides, and the columns of X are the corresponding
  38. solutions.
  39. The LU decomposition with partial pivoting and row interchanges is
  40. used to factor A as A = P*L*U, where P is a permutation matrix, L
  41. is unit lower triangular, and U is upper triangular. The factored
  42. form of A is then used to solve the system of equations A*X = B.
  43. Example Program Results.
  44. ========================
  45. LAPACKE_zgesv (row-major, high-level) Example Program Results
  46. Solution
  47. ( -1.09, -0.18) ( 1.28, 1.21)
  48. ( 0.97, 0.52) ( -0.22, -0.97)
  49. ( -0.20, 0.19) ( 0.53, 1.36)
  50. ( -0.59, 0.92) ( 2.22, -1.00)
  51. Details of LU factorization
  52. ( -4.30, -7.10) ( -6.47, 2.52) ( -6.51, -2.67) ( -5.86, 7.38)
  53. ( 0.49, 0.47) ( 12.26, -3.57) ( -7.87, -0.49) ( -0.98, 6.71)
  54. ( 0.25, -0.15) ( -0.60, -0.37) (-11.70, -4.64) ( -1.35, 1.38)
  55. ( -0.83, -0.32) ( 0.05, 0.58) ( 0.93, -0.50) ( 2.66, 7.86)
  56. Pivot indices
  57. 3 3 3 4
  58. */
  59. #include <stdlib.h>
  60. #include <stdio.h>
  61. #include "lapacke.h"
  62. /* Auxiliary routines prototypes */
  63. extern void print_matrix( char* desc, lapack_int m, lapack_int n, lapack_complex_double* a, lapack_int lda );
  64. extern void print_int_vector( char* desc, lapack_int n, lapack_int* a );
  65. /* Parameters */
  66. #define N 4
  67. #define NRHS 2
  68. #define LDA N
  69. #define LDB NRHS
  70. /* Main program */
  71. int main() {
  72. /* Locals */
  73. lapack_int n = N, nrhs = NRHS, lda = LDA, ldb = LDB, info;
  74. /* Local arrays */
  75. lapack_int ipiv[N];
  76. lapack_complex_double a[LDA*N];
  77. lapack_complex_double b[LDB*N];
  78. a[0] = lapack_make_complex_double( 1.23, -5.50);
  79. a[1] = lapack_make_complex_double( 7.91, -5.38);
  80. a[2] = lapack_make_complex_double(-9.80, -4.86);
  81. a[3] = lapack_make_complex_double(-7.32, 7.57);
  82. a[4] = lapack_make_complex_double(-2.14, -1.12);
  83. a[5] = lapack_make_complex_double(-9.92, -0.79);
  84. a[6] = lapack_make_complex_double(-9.18, -1.12);
  85. a[7] = lapack_make_complex_double( 1.37, 0.43);
  86. a[8] = lapack_make_complex_double(-4.30, -7.10);
  87. a[9] = lapack_make_complex_double(-6.47, 2.52);
  88. a[10] = lapack_make_complex_double(-6.51, -2.67);
  89. a[11] = lapack_make_complex_double(-5.86, 7.38);
  90. a[12] = lapack_make_complex_double( 1.27, 7.29);
  91. a[13] = lapack_make_complex_double( 8.90, 6.92);
  92. a[14] = lapack_make_complex_double(-8.82, 1.25);
  93. a[15] = lapack_make_complex_double( 5.41, 5.37);
  94. b[0] = lapack_make_complex_double( 8.33, -7.32);
  95. b[1] = lapack_make_complex_double(-6.11, -3.81);
  96. b[2] = lapack_make_complex_double(-6.18, -4.80);
  97. b[3] = lapack_make_complex_double( 0.14, -7.71);
  98. b[4] = lapack_make_complex_double(-5.71, -2.80);
  99. b[5] = lapack_make_complex_double( 1.41, 3.40);
  100. b[6] = lapack_make_complex_double(-1.60, 3.08);
  101. b[7] = lapack_make_complex_double( 8.54, -4.05);
  102. /* Print Entry Matrix */
  103. print_matrix( "Entry Matrix A", n, n, a, lda );
  104. /* Print Right Rand Side */
  105. print_matrix( "Right Rand Side", n, nrhs, b, ldb );
  106. printf( "\n" );
  107. /* Executable statements */
  108. printf( "LAPACKE_zgesv (row-major, high-level) Example Program Results\n" );
  109. /* Solve the equations A*X = B */
  110. info = LAPACKE_zgesv( LAPACK_ROW_MAJOR, n, nrhs, a, lda, ipiv, b, ldb );
  111. /* Check for the exact singularity */
  112. if( info > 0 ) {
  113. printf( "The diagonal element of the triangular factor of A,\n" );
  114. printf( "U(%i,%i) is zero, so that A is singular;\n", info, info );
  115. printf( "the solution could not be computed.\n" );
  116. exit( 1 );
  117. }
  118. /* Print solution */
  119. print_matrix( "Solution", n, nrhs, b, ldb );
  120. /* Print details of LU factorization */
  121. print_matrix( "Details of LU factorization", n, n, a, lda );
  122. /* Print pivot indices */
  123. print_int_vector( "Pivot indices", n, ipiv );
  124. exit( 0 );
  125. } /* End of LAPACKE_zgesv Example */
  126. /* Auxiliary routine: printing a matrix */
  127. void print_matrix( char* desc, lapack_int m, lapack_int n, lapack_complex_double* a, lapack_int lda ) {
  128. lapack_int i, j;
  129. printf( "\n %s\n", desc );
  130. for( i = 0; i < m; i++ ) {
  131. for( j = 0; j < n; j++ )
  132. printf( " (%6.2f,%6.2f)", lapack_complex_double_real(a[i*lda+j]), lapack_complex_double_imag(a[i*lda+j]) );
  133. printf( "\n" );
  134. }
  135. }
  136. /* Auxiliary routine: printing a vector of integers */
  137. void print_int_vector( char* desc, lapack_int n, lapack_int* a ) {
  138. lapack_int j;
  139. printf( "\n %s\n", desc );
  140. for( j = 0; j < n; j++ ) printf( " %6i", a[j] );
  141. printf( "\n" );
  142. }