Intel® oneAPI DPC++/C++ Compiler Developer Guide and Reference

ID 767253
Date 3/22/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Intel's valarray Implementation

The Intel® oneAPI DPC++/C++ Compiler provides a high performance implementation of specialized one-dimensional valarray operations for the C++ standard STL valarray container.

The standard C++ valarray template consists of array/vector operations for high performance computing. These operations are designed to exploit high performance hardware features such as parallelism and achieve performance benefits.

Intel's valarray implementation uses the Intel® Integrated Performance Primitives (Intel® IPP), which is part of the product. Select Intel® IPP when you install the product.

The valarray implementation consists of a replacement header, <valarray>, that provides a specialized, high-performance implementation for the following operators and types:

Operator

Type

abs, acos, acosh, asin, asinh, atan, atan2, atanh, cbrt, cdfnorm, ceil, cos, cosh, erf, erfc, erfinv, exp, expm1, floor, hypot, inv, invcbrt, invsqrt, ln, log, log10, log1p, nearbyint, pow, pow2o3, pow3o2, powx, rint, round, sin, sinh, sqrt, tan, tanh, trunk

float, double

add, conj, div, mul, mulbyconj, mul, sub

Ipp32fc, Ipp64fc

addition, subtraction, division, multiplication

float, double

bitwise or, and, xor

(all unsigned) char, short, int

min, max, sum

signed or short/signed int, float, double

Use valarray in Source Code

valarray is not available for SYCL.

Intel's valarray implementation allows you to declare large arrays for parallel processing. Improved implementation of valarray is tied up with calling the Intel® IPP libraries that are part of Intel® IPP.

To use valarrays in your source code, include the valarray header file, <valarray>. The <valarray> header file is located in the path <installdir>/perf_header.

The following example shows a valarray addition operation (+) specialized through use of Intel's implementation of valarray:

#include <valarray>
void test( )
{
	std::valarray<float> vi(N), va(N);
	…
	vi = vi + va;  //array addition
	…
}
NOTE:

To use the static merged library containing all CPU-specific optimized versions of the library code, you need to call the ippStaticInit function first, before any Intel® IPP calls. This ensures automatic dispatch to the appropriate version of the library code for Intel® processor and the generic version of the library code for non-Intel processors at runtime. If you do not call ippStaticInit first, the merged library will use the generic instance of the code. If you are using the dynamic version of the libraries, you do not need to call ippStaticInit.

Product and Performance Information

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.

Notice revision #20201201