Shared Memory Application Programming by Alessandrini Victor;

Shared Memory Application Programming by Alessandrini Victor;

Author:Alessandrini, Victor; [Alessandrini, Victor]
Language: eng
Format: epub
Publisher: Elsevier Science
Published: 2015-11-07T00:00:00+00:00


Comments on data-sharing clauses

Consider first the shared clause: as stated above variables tagged as shared behave as global variables for the duration of the construct. It looks as if OpenMP was promoting a private local variable in the parent task to a global status. In fact, this is not really needed, because shared does not necessarily means global: shared only means that all worker threads have been granted access the original local variable sitting in the parent thread stack. For this to happen, it is sufficient that the parent thread publishes its local data by passing to other threads a pointer to it. Therefore, when a shared variable occurs in a task code block, the compiler is really implementing a pointer or a reference to the parent task local data. This explains a statement often found in the literature: local data items in the parent task tagged as firstprivate are captured by value, and those tagged shared are captured by reference.

Consider next the reduction clause. Listing 10.5 shows how it operates. Let us assume that partial results computed by the worker threads need to be accumulated. This was often done this in the past by asking the worker threads to accumulate their partial results in a mutex-protected global variable. OpenMP can perform the required reduction directly, as shown.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.