Intel® Advisor Help

Parallelize Data - Intel Cilk Plus Counted Loops

When tasks are loop iterations, and the iterations are over a range of values that are known before the loop starts, the loop is easily expressed in Intel Cilk Plus.

Consider the following serial code and the need to add parallelism to this loop:

    ANNOTATE_SITE_BEGIN(sitename);
        for (int i = lo; i < hi; ++i) {
            ANNOTATE_ITERATION_TASK(taskname);
                statement;
        }
    ANNOTATE_SITE_END();

Intel Cilk Plus makes it easy to introduce parallelism into loops. After you optionally remove the Intel Advisor annotations, simply replace the for keyword with _Cilk_for:

...
    _Cilk_for (int i = lo; i < hi; ++i) {
        statement
    }

Note that this will not necessarily create the same set of tasks described by the annotations. The cilk_for will split the loop iterations into a number of chunks dynamically computed to take best advantage of the parallelism available on the system running the program.

If your source file provides #include <cilk/cilk.h>, use cilk_for instead of _Cilk_for.

See Also