Intel® C++ Compiler Classic Developer Guide and Reference

ID 767249
Date 7/13/2023
Public
Document Table of Contents

Intel's valarray Implementation

The Intel® C++ Compiler Classic 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 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

Intel's valarray implementation allows you to declare huge arrays for parallel processing. Improved implementation of valarray is tied up with calling the IPP libraries that are part of Intel® Integrated Performance Primitives (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 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* and macOS), is used to include the required valarray header file and all the necessary 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, "merged" libraries refers to using a static library that contains all the CPU-specific variants of the library code.

Linux* OS Examples

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

icpc -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):

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

Merged (static):

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

Windows* OS Examples

The following command line performs a one-step compilation for a system based on IA-32 architecture, running Windows OS:

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

The following command lines perform separate compile and link steps for a system based on IA-32 architecture, running Windows OS:

DLL (dynamic):

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

Merged (static):

icc /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