| September 18, 2008 12:00 AM PDT | |
|
Page Contents:
Intel® Math Kernel Library use with C and Fortran languages. Calling LAPACK, BLAS, and CBLAS routines from C language environments. The Intel Math Kernel Library is provided in C and Fortran environments. Not all of the Intel® MKL sub-libraries support both environments. In order to use these sub-libraries in both environments some "rules" need to be observed.
How to Call BLAS Functions that Return the Complex Values in C/C++ Code Calling complex BLAS function that return complex values from C must be handled carefully. The problem arises because these are Fortran functions, and the return values are handled quite differently for the two languages (C and Fortran) for complex values. While the Fortran language prohibits calling functions as subroutines, or vice versa, if you understand how a particular Fortran implementation returns function values you can make the appropriate call from C. (The Fortran standard defines C interoperability features, but these are not used by Intel® MKL.) A Fortran function that returns a complex value returns its result in a variable passed as the first parameter in the calling sequence - a feature that can be exploited by the C programmer. The following example, for cdotc(), shows how this works. The function from Fortran is called as: result = cdotc( n, x, 1, y, 1 )From C this would look like: cdotc( &result, &n, x, &one, y, &one ) where the hidden parameter is exposed. Note: Intel® MKL has both upper case and lower case entry points in the BLAS so either all upper case or all lower case names are acceptable. Using this form the several level 1 BLAS functions that return complex values can be called from C, and thus, from C++. However, it is still easier to use the cblas interface. For instance, to call the same function using the cblas interface, the user would use: cblas_cdotu( n, x, 1, y, 1, &result )Note: The complex value comes back expressly in this case. Example 1: Calling a Complex BLAS Level 1 Function from C /* The following example illustrates a call from a C program to the complex BLAS Level 1 function zdotc(). This function computes the dot product of two double-precision complex vectors. In this example, the complex dot product is returned in the structure c. */ #include "mkl.h" #define N 5 void main() { int n, inca = 1, incb = 1, i; typedef struct{ double re; double im; } complex16; complex16 a[N], b[N], c; void zdotc(); n = N; for( i = 0; i < n; i++ ){ a[i].re = (double)i; a[i].im = (double)i * 2.0; b[i].re = (double)(n - i); b[i].im = (double)i * 2.0; } zdotc( &c, &n, a, &inca, b, &incb ); printf( "The complex dot product is: ( %6.2f, %6.2f) ", c.re, c.im ); } Example 2: Calling a Complex BLAS Level 1 Function from C++ #include "mkl.h" typedef struct{ double re; double im; } complex16; extern "C" void zdotc (complex16*, int *, complex16 *, int *, complex16 *, int *); #define N 5 void main() { int n, inca = 1, incb = 1, i; complex16 a[N], b[N], c; n = N; for( i = 0; i < n; i++ ){ a[i].re = (double)i; a[i].im = (double)i * 2.0; b[i].re = (double)(n - i); b[i].im = (double)i * 2.0; } zdo tc(&c, &n, a, &inca, b, &incb ); printf( "The complex dot product is: ( %6.2f, %6.2f) ", c.re, c.im ); } Example 3: Using the CBLAS Interface Instead of Calling BLAS Directly from C Programs #include "mkl.h" typedef struct{ double re; double im; } complex16; extern "C" void cblas_zdotc_sub ( const int , const complex16 *, const int , const complex16 *, const int, const complex16*); #define N 5 void main() { int n, inca = 1, incb = 1, i; complex16 a[N], b[N], c; n = N; for( i = 0; i < n; i++ ){ a[i].re = (double)i; a[i].im = (double)i * 2.0; b[i].re = (double)(n - i); b[i].im = (double)i * 2.0; } cblas_zdotc_sub(n, a, inca, b, incb,&c ); printf( "The complex dot product is: ( %6.2f, %6.2f) ", c.re, c.im ); } |
This article applies to: Software Products General
For more complete information about compiler optimizations, see our Optimization Notice.
Comments (2) 
| September 8, 2009 1:53 PM PDT
Jesper Gadegaard |
I've used the following command to compile. I don't know if it is 100% correct, but it worked for me: icc $1 -L"$LIBRARY_PATH -lmkl_em64t Replace $1 with you code-file and remember to select the library suited for your architecture (-lmkl_{ia32, em64t, ipf}) according to: intel.com/software/products/mkl/docs/mklgs_lnx.htm |
Trackbacks (1)
- LAPACK and BLAS on Ubuntu 10.04 | Thesis Blog
July 7, 2011 3:56 PM PDT
Leave a comment 
To obtain technical support, please go to Software Support.

Dr P.Manley-Cooke
and which includes do we have to use?
One source of information says "use this if that" and the next says "use the other if the other".
We have the use of a computer, could this not sort out what to do?