1 /* 2 Copyright (c) 2011, Intel Corporation. All rights reserved. 3 4 Redistribution and use in source and binary forms, with or without modification, 5 are permitted provided that the following conditions are met: 6 7 * Redistributions of source code must retain the above copyright notice, this 8 list of conditions and the following disclaimer. 9 * Redistributions in binary form must reproduce the above copyright notice, 10 this list of conditions and the following disclaimer in the documentation 11 and/or other materials provided with the distribution. 12 * Neither the name of Intel Corporation nor the names of its contributors may 13 be used to endorse or promote products derived from this software without 14 specific prior written permission. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27 ******************************************************************************** 28 * Content : Eigen bindings to Intel(R) MKL 29 * LU decomposition with partial pivoting based on LAPACKE_?getrf function. 30 ******************************************************************************** 31 */ 32 33 #ifndef EIGEN_PARTIALLU_LAPACK_H 34 #define EIGEN_PARTIALLU_LAPACK_H 35 36 #include "Eigen/src/Core/util/MKL_support.h" 37 38 namespace Eigen { 39 40 namespace internal { 41 42 /** \internal Specialization for the data types supported by MKL */ 43 44 #define EIGEN_MKL_LU_PARTPIV(EIGTYPE, MKLTYPE, MKLPREFIX) \ 45 template<int StorageOrder> \ 46 struct partial_lu_impl<EIGTYPE, StorageOrder, lapack_int> \ 47 { \ 48 /* \internal performs the LU decomposition in-place of the matrix represented */ \ 49 static lapack_int blocked_lu(lapack_int rows, lapack_int cols, EIGTYPE* lu_data, lapack_int luStride, lapack_int* row_transpositions, lapack_int& nb_transpositions, lapack_int maxBlockSize=256) \ 50 { \ 51 EIGEN_UNUSED_VARIABLE(maxBlockSize);\ 52 lapack_int matrix_order, first_zero_pivot; \ 53 lapack_int m, n, lda, *ipiv, info; \ 54 EIGTYPE* a; \ 55 /* Set up parameters for ?getrf */ \ 56 matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \ 57 lda = luStride; \ 58 a = lu_data; \ 59 ipiv = row_transpositions; \ 60 m = rows; \ 61 n = cols; \ 62 nb_transpositions = 0; \ 63 \ 64 info = LAPACKE_##MKLPREFIX##getrf( matrix_order, m, n, (MKLTYPE*)a, lda, ipiv ); \ 65 \ 66 for(int i=0;i<m;i++) { ipiv[i]--; if (ipiv[i]!=i) nb_transpositions++; } \ 67 \ 68 eigen_assert(info >= 0); \ 69 /* something should be done with nb_transpositions */ \ 70 \ 71 first_zero_pivot = info; \ 72 return first_zero_pivot; \ 73 } \ 74 }; 75 76 EIGEN_MKL_LU_PARTPIV(double, double, d) 77 EIGEN_MKL_LU_PARTPIV(float, float, s) 78 EIGEN_MKL_LU_PARTPIV(dcomplex, MKL_Complex16, z) 79 EIGEN_MKL_LU_PARTPIV(scomplex, MKL_Complex8, c) 80 81 } // end namespace internal 82 83 } // end namespace Eigen 84 85 #endif // EIGEN_PARTIALLU_LAPACK_H 86