# Vectorization of complex number operations using Cilk Plus (C++)

## Vectorization of complex number operations using Cilk Plus (C++)

Hi, during optimization of my code I found that even simple C++ std::complex operationsare not vectorized. See following code/////////////////////////////////////#ifdef USE_CPP   #include    typedef std::complex cmplx16;#else   #include    typedef complex double cmplx16;#endif // USE_CPP #define simd_for _Pragma ("simd") forvoid sum(int Nx, int Ny, int Nz, cmplx16 A[Nx][Ny][Nz], cmplx16 B[Nx][Ny][Nz], cmplx16 C[Nx][Ny][Nz]){ __assume_aligned(A,32); __assume_aligned(B,32); __assume_aligned(C,32); for(int x=0; x  C[x][y][z] = A[x][y][z] + B[x][y][z];  } } }}//////////////////////Compiling with icc (or icpc) to use C (complex doubles) outputs\$>  icc -c vector.cpp -vec-report=2  -O3 -mavx ...outputs vector.cpp(18): (col. 54) remark: SIMD LOOP WAS VECTORIZED.However, using C++ (std::complex), outputs\$> icc -c vector.cpp -vec-report=2 -complex-limited-range -O3 -mavx -DUSE_CPPvector.cpp(20): (col. 29) remark: loop was not vectorized: unsupported data type.vector.cpp(18): (col. 54) warning #13379: loop was not vectorized with "simd"Thus obviously vectorization is not supported for C++ complex numbers but for C. With -guide-vec=2 I can trace the problem to /usr/include/c++/4.4.6/complex(321): (col. 24) remark: loop was not vectorized: unsupported data type.However, is there anyway to enable proper vectorization using some kind of pragmas or a different libstdc++ implementation or MKL or ... ? If not, is this going to be fixed in thenear future or is the general advice to use C complex numbers in C++ code in caseof doing explicit real/imaginary part calculations is not an option ?thanks a lot !Paul

2 posts / 0 nouveau(x)
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

In order to get the simd loop to vectorize please try to define the simd_for macro as:

#define simd_for _Pragma ("simd vectorlength(2)") for

That should ensure the for loop operanting on complex arrays will vectorize and ensure AVX instructions are used.

The intent is to improve the simd vectorization in a product update of the Intel Composer XE 2013.

## Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ?