To build the Intel® Cilk™ Plus version, you will modify the sample application to use Intel® Cilk™ Plus and then compile the modified code. You will then run the application and then compare the time with the baseline performance time.
Remove all of the files that were created when you build the serial version by running the following command:
%make clean
Open the source file src/build_with_cilk/build_with_cilk.cpp.
Remove the comment marks from the Intel® Cilk™ Plus header files to use the Intel® Cilk™ Plus keywords.
Remove the comment marks from the draw_task() function related to Intel® Cilk™ Plus implementation. Note the differences in this function and the serial draw_task() function. The for keyword is replaced with the cilk_for keyword to parallelize the for loop without needing to change most of the rest of the loop. Since you cannot branch out of a cilk_for loop, replace the return with a boolean flag flagExit to avoid threads from doing unnecessary work.
Add comment marks the serial draw_task() function since the Intel® Cilk™ Plus version of the draw_task() function replaces this function.
Build the sample by running the following command:
%make cilk
Run the sample application.
Compare the time to render the image to the baseline performance time.
If you want to change the number of threads available to Intel® Cilk™ Plus, you can set an environment variable CILK_NWORKERS to the number of threads. You can also use a runtime function __cilkrts_set_param("nworkers", "N") where N is a string with the number of threads. You must call this runtime function before the first call to a cilk_spawn() or cilk_for() function. Note that while this sets the maximum number of threads that will be used to run Intel® Cilk™ Plus code in parallel, the Intel® Cilk™ Plus runtime by design will only use threads that find enough work to steal. Very small workloads may only see one thread being used.
This step is the last step in the tutorial.