Intel® Advisor User Guide

ID 766448
Date 7/13/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Verify Whether Incidental Sharing Exists

Sharing is incidental only if the task writes to the memory location before any read of the memory location anywhere in the dynamic extent of the task. This is easy to check when the task is a few lines of code in a single function. It is much harder when the task is hundreds or thousands of lines of code, and involves calls to many functions in many source files.

Even worse, the sharing is not incidental if any code that might execute after the task completes, or in any other task that might run at the same time as the task, could read a value written by the task to that memory location.

There is no "magic bullet" to prove that the requirements are met, but there is a simple technique that you might find useful. Add statements that write a known bad value into the memory location immediately after the ANNOTATE_ITERATION_TASK(taskname);, and then test your serial program. If the sharing is incidental, these assignments will have no effect. If  not, there is a good chance that the changes will change the program behavior. Of course, the effectiveness of this technique depends on how good your test system is at detecting the resulting bugs.

For example, if you want to confirm that the variable x is incidentally shared in the_task():

extern int x;
// ...
ANNOTATE_SITE_BEGIN(site1); 
for (i = 0; i != n; ++i) {
    ANNOTATE_ITERATION_TASK(task1);
    x = 0xdeadbeef;
    the_task();
    x = 0xdeadbeef;
}
ANNOTATE_SITE_BEGIN();

To identify stray memory references, consider using the C/C++ special-purpose annotations ANNOTATE_OBSERVE_USES() and ANNOTATE_CLEAR_USES().