0% found this document useful (0 votes)
23 views3 pages

Parallel Pragma Suspend or Resume of Thread

The document discusses using OpenMP pragmas to parallelize code without unnecessary overhead. Within a parallel region, adjacent parallel loops or sections can share threads without needing to suspend or resume threads between them. Work can also be shared using both parallel loops and sections within a single parallel region to eliminate overhead from forking new threads. Sections divide work among already created threads to execute each section once in parallel.

Uploaded by

bsgindia82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Parallel Pragma Suspend or Resume of Thread

The document discusses using OpenMP pragmas to parallelize code without unnecessary overhead. Within a parallel region, adjacent parallel loops or sections can share threads without needing to suspend or resume threads between them. Work can also be shared using both parallel loops and sections within a single parallel region to eliminate overhead from forking new threads. Sections divide work among already created threads to execute each section once in parallel.

Uploaded by

bsgindia82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Parallel pragma suspend or resume of thread: operations, still creates overhead and may be unnecessary when two parallel

l regions, loops, or sections are adjacent as shown in the following example.

#pragma omp parallel for for( k = 0; k < m; k++ ) { fn1(k); fn2(k); } #pragma omp parallel for // adds unnecessary overhead for ( k = 0; k < m; k++ ) { fn3(k); fn4(k); }

Within a Parallel region:


#pragma { #pragma for ( k fn1(k); } #pragma for ( k fn3(k); } } omp parallel omp for = 0; k < m; k++ ) { fn2(k); omp for = 0; k < m; k++ ) { fn4(k);

Work-sharing Sections:
The work-sharing sections construct directs the OpenMP compiler and runtime to distribute the identified sections of your application among threads in the team created for the parallel region. The following example uses work-sharing for loops and work-sharing sections together within a single parallel region. In this case, the overhead of forking or resuming threads for parallel sections is eliminated.

Example: Parallel sections


#pragma omp parallel Sections Private(y,z) { #pragma omp section { y=sectionA(x); fn7(y); } #pragma omp section { z = sectionB(x); fn8(z); } }

Work can be shared within a parallel region


#pragma omp parallel { #pragma omp for for ( k = 0; k < m; k++ ) { x = fn1(k) + fn2(k); } #pragma omp sections private(y, z) { #pragma omp section { y = sectionA(x); fn7(y); } #pragma omp section { z = sectionB(x); fn8(z); } } }

OpenMP first creates several threads. Then, the iterations of the loop are divided among the threads. Once the loop is finished, the sections are divided among the threads so that each section is executed exactly once, but in parallel with the other sections.

If the program contains more sections than threads, the remaining sections get scheduled as threads finish their previous sections.

You might also like