Intel® C++ Compiler 19.0 Developer Guide and Reference

Debugging an Intel® Cilk™ Plus Program

Intel® Cilk™ Plus is a deprecated feature. Use OpenMP* or Intel® Threading Building Blocks instead. For more information see Migrate Your Application to use OpenMP* or Intel® TBB Instead of Intel® Cilk™ Plus.

By default, the number of worker threads is set to the number of cores on the host system. In most cases, the default value works well. Additionally, on systems that support simultaneous multithreading on each core, Intel® Cilk™ Plus uses all available hardware threads—except on Intel® Xeon Phi™ processors and coprocessors where it uses half the number of available hardware threads.

You can increase or decrease the number of workers under program control or via the environment. You may want to use fewer workers than the number of processor cores available in order to run tests or to reserve resources for other programs. In some cases, you may want to oversubscribe by creating more workers than the number of available processor cores. This may be useful if you have workers waiting on locks, or if you want to test a parallel program on a single-core computer.

Environment

You can specify the number of worker threads using the environment variable CILK_NWORKERS.

Windows*: set CILK_NWORKERS=4

Linux* and macOS*: export CILK_NWORKERS=4

Program Control

Prior to the first call to a function that performs a spawn (cilk_spawn or cilk_for) within a program, you may set the desired number of workers by calling __cilkrts_set_param("nworkers","N"), where N is a number expressed in decimal or, with a leading 0x or 0, in hexadecimal or octal. This call to set the worker count overrides the value set in the CILK_NWORKERS environment variable. To use __cilkrts_set_param, make sure to specify #include <cilk/cilk_api.h> in your program.

Example:

 if (0!= __cilkrts_set_param("nworkers","4"))
 {
    printf("Failed to set worker count\n");
    return 1;
 }

Intel® Cilk™ Plus is a deprecated feature. Use OpenMP* or Intel® Threading Building Blocks instead. For more information see Migrate Your Application to use OpenMP* or Intel® TBB Instead of Intel® Cilk™ Plus.

Serialization

The provided keywords are designed to have serial semantics. In other words, every Intel® Cilk™ Plus program corresponds to an equivalent C/C++ program. Such a C/C++ program is referred to as the serialization of the program. The serialization is particularly useful when debugging Intel® Cilk™ Plus programs.

How to Create a Serialization

The header file cilk_stub.h contains macros that redefine the Intel® Cilk™ Plus keywords and library calls into an equivalent serial form. To build a serialization do one of the following:

Debugging Strategies

Intel® Cilk™ Plus is a deprecated feature. Use OpenMP* or Intel® Threading Building Blocks instead. For more information see Migrate Your Application to use OpenMP* or Intel® TBB Instead of Intel® Cilk™ Plus.

Debugging a parallel program can be more difficult than debugging a serial program. Use of Intel® Cilk™ Plus is designed to simplify the challenge of parallel debugging as much as possible. Start by debugging the serialization first.

Follow these guidelines to minimize the problem of debugging parallel programs:

It may be simpler to debug programs built without optimizations. Debugging without optimizations turns off inlining, resulting in a more accurate call stack; additionally, the compiler does not attempt to reorder instructions and optimize register usage.