Site Tools


sections-openmp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
sections-openmp [June 11, 2026 at 10:03] – Ivan Janevskisections-openmp [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-# Sections (OpenMP) 
-Suppose you have a few independent operations — compress a buffer, encrypt a header, write a log — that share no data and could run simultaneously. A loop doesn't fit because the operations are distinct, not iterations of the same work. 
- 
-**Sections** is the OpenMP construct for this case: it distributes a fixed set of independent code blocks across threads at compile time. Each block is wrapped in `#pragma omp section`. 
- 
-```c 
-#pragma omp parallel sections 
-{ 
-    #pragma omp section 
-    compress(data); 
- 
-    #pragma omp section 
-    encrypt(header); 
- 
-    #pragma omp section 
-    write_log(meta); 
-} 
-``` 
- 
-If there are more `section` blocks than threads, the excess blocks are queued and picked up as threads become free. If there are fewer blocks than threads, the extra threads sit idle. For a large or dynamic number of tasks, [[tasks-openmp|tasks]] are more flexible; `sections` is simpler when the count is small and fixed. 
  
sections-openmp.1781172206.md.gz · Last modified: by Ivan Janevski