1 /* 2 Copyright (c) 2011, Intel Corporation. All rights reserved. 3 Copyright (C) 2011 Gael Guennebaud <gael.guennebaud (at) inria.fr> 4 5 Redistribution and use in source and binary forms, with or without modification, 6 are permitted provided that the following conditions are met: 7 8 * Redistributions of source code must retain the above copyright notice, this 9 list of conditions and the following disclaimer. 10 * Redistributions in binary form must reproduce the above copyright notice, 11 this list of conditions and the following disclaimer in the documentation 12 and/or other materials provided with the distribution. 13 * Neither the name of Intel Corporation nor the names of its contributors may 14 be used to endorse or promote products derived from this software without 15 specific prior written permission. 16 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28 ******************************************************************************** 29 * Content : Documentation on the use of Intel MKL through Eigen 30 ******************************************************************************** 31 */ 32 33 namespace Eigen { 34 35 /** \page TopicUsingIntelMKL Using Intel Math Kernel Library from Eigen 36 37 \section TopicUsingIntelMKL_Intro Eigen and Intel Math Kernel Library (Intel MKL) 38 39 Since Eigen version 3.1 and later, users can benefit from built-in Intel MKL optimizations with an installed copy of Intel MKL 10.3 (or later). 40 <a href="http://eigen.tuxfamily.org/Counter/redirect_to_mkl.php"> Intel MKL </a> provides highly optimized multi-threaded mathematical routines forx86-compatible architectures. 41 Intel MKL is available on Linux, Mac and Windows for both Intel64 and IA32 architectures. 42 43 \warning Be aware that Intel MKL is a proprietary software. It is the responsibility of the users to buy MKL licenses for their products. Moreover, the license of the user product has to allow linking to proprietary software that excludes any unmodified versions of the GPL. As a consequence, this also means that Eigen has to be used through the LGPL3+ license. 44 45 Using Intel MKL through Eigen is easy: 46 -# define the \c EIGEN_USE_MKL_ALL macro before including any Eigen's header 47 -# link your program to MKL libraries (see the <a href="http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor/">MKL linking advisor</a>) 48 -# on a 64bits system, you must use the LP64 interface (not the ILP64 one) 49 50 When doing so, a number of Eigen's algorithms are silently substituted with calls to Intel MKL routines. 51 These substitutions apply only for \b Dynamic \b or \b large enough objects with one of the following four standard scalar types: \c float, \c double, \c complex<float>, and \c complex<double>. 52 Operations on other scalar types or mixing reals and complexes will continue to use the built-in algorithms. 53 54 In addition you can coarsely select choose which parts will be substituted by defining one or multiple of the following macros: 55 56 <table class="manual"> 57 <tr><td>\c EIGEN_USE_BLAS </td><td>Enables the use of external BLAS level 2 and 3 routines (currently works with Intel MKL only)</td></tr> 58 <tr class="alt"><td>\c EIGEN_USE_LAPACKE </td><td>Enables the use of external Lapack routines via the <a href="http://www.netlib.org/lapack/lapacke.html">Intel Lapacke</a> C interface to Lapack (currently works with Intel MKL only)</td></tr> 59 <tr><td>\c EIGEN_USE_LAPACKE_STRICT </td><td>Same as \c EIGEN_USE_LAPACKE but algorithm of lower robustness are disabled. This currently concerns only JacobiSVD which otherwise would be replaced by \c gesvd that is less robust than Jacobi rotations.</td></tr> 60 <tr class="alt"><td>\c EIGEN_USE_MKL_VML </td><td>Enables the use of Intel VML (vector operations)</td></tr> 61 <tr><td>\c EIGEN_USE_MKL_ALL </td><td>Defines \c EIGEN_USE_BLAS, \c EIGEN_USE_LAPACKE, and \c EIGEN_USE_MKL_VML </td></tr> 62 </table> 63 64 Finally, the PARDISO sparse solver shipped with Intel MKL can be used through the \ref PardisoLU, \ref PardisoLLT and \ref PardisoLDLT classes of the \ref PARDISOSupport_Module. 65 66 67 \section TopicUsingIntelMKL_SupportedFeatures List of supported features 68 69 The breadth of Eigen functionality covered by Intel MKL is listed in the table below. 70 <table class="manual"> 71 <tr><th>Functional domain</th><th>Code example</th><th>MKL routines</th></tr> 72 <tr><td>Matrix-matrix operations \n \c EIGEN_USE_BLAS </td><td>\code 73 m1*m2.transpose(); 74 m1.selfadjointView<Lower>()*m2; 75 m1*m2.triangularView<Upper>(); 76 m1.selfadjointView<Lower>().rankUpdate(m2,1.0); 77 \endcode</td><td>\code 78 ?gemm 79 ?symm/?hemm 80 ?trmm 81 dsyrk/ssyrk 82 \endcode</td></tr> 83 <tr class="alt"><td>Matrix-vector operations \n \c EIGEN_USE_BLAS </td><td>\code 84 m1.adjoint()*b; 85 m1.selfadjointView<Lower>()*b; 86 m1.triangularView<Upper>()*b; 87 \endcode</td><td>\code 88 ?gemv 89 ?symv/?hemv 90 ?trmv 91 \endcode</td></tr> 92 <tr><td>LU decomposition \n \c EIGEN_USE_LAPACKE \n \c EIGEN_USE_LAPACKE_STRICT </td><td>\code 93 v1 = m1.lu().solve(v2); 94 \endcode</td><td>\code 95 ?getrf 96 \endcode</td></tr> 97 <tr class="alt"><td>Cholesky decomposition \n \c EIGEN_USE_LAPACKE \n \c EIGEN_USE_LAPACKE_STRICT </td><td>\code 98 v1 = m2.selfadjointView<Upper>().llt().solve(v2); 99 \endcode</td><td>\code 100 ?potrf 101 \endcode</td></tr> 102 <tr><td>QR decomposition \n \c EIGEN_USE_LAPACKE \n \c EIGEN_USE_LAPACKE_STRICT </td><td>\code 103 m1.householderQr(); 104 m1.colPivHouseholderQr(); 105 \endcode</td><td>\code 106 ?geqrf 107 ?geqp3 108 \endcode</td></tr> 109 <tr class="alt"><td>Singular value decomposition \n \c EIGEN_USE_LAPACKE </td><td>\code 110 JacobiSVD<MatrixXd> svd; 111 svd.compute(m1, ComputeThinV); 112 \endcode</td><td>\code 113 ?gesvd 114 \endcode</td></tr> 115 <tr><td>Eigen-value decompositions \n \c EIGEN_USE_LAPACKE \n \c EIGEN_USE_LAPACKE_STRICT </td><td>\code 116 EigenSolver<MatrixXd> es(m1); 117 ComplexEigenSolver<MatrixXcd> ces(m1); 118 SelfAdjointEigenSolver<MatrixXd> saes(m1+m1.transpose()); 119 GeneralizedSelfAdjointEigenSolver<MatrixXd> 120 gsaes(m1+m1.transpose(),m2+m2.transpose()); 121 \endcode</td><td>\code 122 ?gees 123 ?gees 124 ?syev/?heev 125 ?syev/?heev, 126 ?potrf 127 \endcode</td></tr> 128 <tr class="alt"><td>Schur decomposition \n \c EIGEN_USE_LAPACKE \n \c EIGEN_USE_LAPACKE_STRICT </td><td>\code 129 RealSchur<MatrixXd> schurR(m1); 130 ComplexSchur<MatrixXcd> schurC(m1); 131 \endcode</td><td>\code 132 ?gees 133 \endcode</td></tr> 134 <tr><td>Vector Math \n \c EIGEN_USE_MKL_VML </td><td>\code 135 v2=v1.array().sin(); 136 v2=v1.array().asin(); 137 v2=v1.array().cos(); 138 v2=v1.array().acos(); 139 v2=v1.array().tan(); 140 v2=v1.array().exp(); 141 v2=v1.array().log(); 142 v2=v1.array().sqrt(); 143 v2=v1.array().square(); 144 v2=v1.array().pow(1.5); 145 \endcode</td><td>\code 146 v?Sin 147 v?Asin 148 v?Cos 149 v?Acos 150 v?Tan 151 v?Exp 152 v?Ln 153 v?Sqrt 154 v?Sqr 155 v?Powx 156 \endcode</td></tr> 157 </table> 158 In the examples, m1 and m2 are dense matrices and v1 and v2 are dense vectors. 159 160 161 \section TopicUsingIntelMKL_Links Links 162 - Intel MKL can be purchased and downloaded <a href="http://eigen.tuxfamily.org/Counter/redirect_to_mkl.php">here</a>. 163 - Intel MKL is also bundled with <a href="http://software.intel.com/en-us/articles/intel-composer-xe/">Intel Composer XE</a>. 164 165 166 */ 167 168 }