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

ID 767253
Date 9/08/2022
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.

Compiling valarray Source Code

To compile your valarray source code, the compiler option, /Quse-intel-optimized-headers (for Windows) or -use-intel-optimized-headers (for Linux), is used to include the required valarray header file and all the necessary Intel® IPP library files.

The following examples illustrate how to compile and link a program to include the Intel valarray replacement header file and link with the Intel® IPP libraries. Refer to the Intel® IPP documentation for details.

In the following examples, the merged libraries use a static library that contains all the CPU-specific variants of the library code.

Linux Examples

The following command line performs a one-step compilation for a system based on Intel® 64 architecture, running Linux OS:

icpx -use-intel-optimized-headers source.cpp

The following command lines perform separate compile and link steps for a system based on Intel® 64 architecture, running Linux OS:

so (dynamic):

icpx -use-intel-optimized-headers -c source.cpp
icpx source.o -use-intel-optimized-headers -shared-intel

Merged (static):

icpx -use-intel-optimized-headers -c source.cpp
icpx source.o -use-intel-optimized-headers

Windows Examples

The following command example performs a one-step compilation for a system running Windows OS:

icx /Quse-intel-optimized-headers source.cpp

The following command examples perform separate compile and link steps for a system running Windows OS:

DLL (dynamic):

icx /Quse-intel-optimized-headers /c source.cpp
icx source.obj /Quse-intel-optimized-headers

Merged (static):

icx /Quse-intel-optimized-headers /Qipp-link:static /c source.cpp
icx source.obj /Quse-intel-optimized-headers /Qipp-link:static 

Product and Performance Information

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

Notice revision #20201201