On this page i will show you how to include LAPACK into your project using C++ and Visual Studio. Before we can get started make sure to obtain the following items.

▶LAPACK In order to use the library you must either get the source code, or the precompiled binaries for your system. To save some time just get the DLL and LIB. If you're programming on a Win32 platform, click ▷here. |

▶BLAS Since LAPACK makes use of BLAS internally, you will also need the BLAS binaries. The file you just downloaded contains both. |

▶Documentation LAPACK (and BLAS for that matter) functionality is included into a project by declaring the corresponding Fortran function header. In order to do that you need to know what the function you're looking for looks like in LAPACK. Assuming your program provides single precision data consider the following ▷overview. The procedure is simple. Select a function, following the link and try to understand the description. |

Example

extern "C" { //SUBROUTINE SGESV(N, NRHS, A, LDA, IPIV, B, LDB, INFO) void sgesv_( int* n, int* nrhs, float* a, int* lda, int* ipiv, float* b, int* ldb, int* info); }

That's it! The function sgesv_([...]) will now call the respective LAPACK function. The arguments may look a little cryptic at first but it shouldn't be too much of a problem with the documentation at hand. Despite being fully functional the current implementation is clearly not very user friendly. At the expense of a slightly higher funtion overhead you should consider writing a wrapper function for an easier and more intuitive access.

/** On exit A will contain the factors L and U, b will contain x. */ DC_VALUE MA_API ma_sgesv(GE_Matrix& _A, GE_Matrix& _b){ int t_info; int* t_p = new int[_A.m_cols]; sgesv_( &_A.m_cols, // Number of rows in A &_b.m_cols, // Number of columns in b _A.m_data, // A &_A.m_rows, // LDA - Number of columns in A t_p, // P _b.m_data, // b &_b.m_rows, // LDB - Number of columns in b &t_info); // Info delete[] t_p; if(t_info == 0) return DC_OK; return DC_ERROR; }

The

## No comments:

## Post a Comment