Work Sharing and Thread Data Management

Work sharing

Overview
Work sharing construct: sections
Compile and run hello_sections.c
Challenge: section

Given the following functions: $y=x^{4} + 15x^{3} + 10x^{2} + 2x$ develop an OpenMP program called poly_openmp.c with sections/section directives. Each section should handle the calculations for one term of the polynomial.

Solution
Work sharing construct: single

hello_sections_nosingle.c: ```c linenums=”1” –8<– “docs/csc466/lectures/data/openmp/hello_sections_nosingle.c”

1
2
3
4
5
`hello_sections_single.c`: 

```c linenums="1"
--8<-- "docs/csc466/lectures/data/openmp/hello_sections_single.c"

hello_sections_single_nowait.c:

c linenums="1" --8<-- "docs/csc466/lectures/data/openmp/hello_sections_nowait.c"

Compile and run singles

Shared and Private Data

Overview

c linenums="1" --8<-- "docs/csc466/lectures/data/openmp/counter_openmp.c"

shared and private data
Shared and Private

```c linenums=”1” –8<– “docs/csc466/lectures/data/openmp/shared_private.c”

Explain the reason why the value of j is the way it is
Run and explain the results of the last variable

c linenums="1" --8<-- "docs/csc466/lectures/data/openmp/first_last.c"