Elemental functions: Writing data parallel code in C/C++ using Intel® Cilk™ Plus

Published: 01/24/2011, Last Updated: 01/24/2011

Intel® Cilk™ Plus is a simple C/C++ language extension construct for data parallel operations.


Intel® Cilk™ Plus provides simple to use language extensions to express data and task-parallelism to the C and C++ language implemented by the Intel® C++ Compiler, which is part of Intel® Parallel Composer and Intel® Parallel Studio. This article describes one of these programming constructs: “elemental functions”.

There are cases in which the algorithm performs operations on large collection of data, with no dependence among the operations being performed on the various data item. For example, the programmer may write, at a certain point of the algorithm: add arrays a1 and a2 and store the result in array r. When thinking at that level, the programmer is thinking in terms of a single operation that needs to be performed on many elements, independently of each other. Unfortunately, the C/C++ programming languages do not provide constructs that allow expressing the operation as such. Instead, they force the programmer to elaborate the operation in terms of a loop that operates on each array element. The end result, in terms of the values being stored in the result array, would be the same. However, the introduction of the loop introduces an unintended order of operations: The implementation has to add the first two array elements, store the results in the first location of the result array, move on to perform the same operation on the second set of elements, and so on. An example later will show what is expected to be a typical use of elemental function: use a single line to mark a standard C/C++ function as elemental, change the invocation loop from serial to parallel (in this example, it is a change of one keyword) and that is it.

To continue reading the article, click on the link below.

Refer to http://software.intel.com/content/www/us/en/develop/articles/optimization-notice.html for more information regarding performance and optimization choices in Intel software products.

Product and Performance Information


Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804