# Calling BLAS Functions that Return the Complex Values in C/C++ Code

## Example "Calling a Complex BLAS Level 1 Function from C"

#include "mkl.h" #define N 5 int main() { int n = N, inca = 1, incb = 1, i; MKL_Complex16 a[N], b[N], c; for( i = 0; i < n; i++ ) { a[i].real = (double)i; a[i].imag = (double)i * 2.0; b[i].real = (double)(n - i); b[i].imag = (double)i * 2.0; } zdotc( &c, &n, a, &inca, b, &incb ); printf( "The complex dot product is: ( %6.2f, %6.2f)\n", c.real, c.imag ); return 0; }

## Example "Calling a Complex BLAS Level 1 Function from C++"

#include <complex> #include <iostream> #define MKL_Complex16 std::complex<double> #include "mkl.h" #define N 5 int main() { int n, inca = 1, incb = 1, i; std::complex<double> a[N], b[N], c; n = N; for( i = 0; i < n; i++ ) { a[i] = std::complex<double>(i,i*2.0); b[i] = std::complex<double>(n-i,i*2.0); } zdotc(&c, &n, a, &inca, b, &incb ); std::cout << "The complex dot product is: " << c << std::endl; return 0; }

## Example "Using CBLAS Interface Instead of Calling BLAS Directly from C"

#include <stdio.h> #include "mkl.h" typedef struct{ double re; double im; } complex16; #define N 5 int 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)\n", c.re, c.im ); return 0; }