Site Tools


collapse-openmp

Differences

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

Link to this comparison view

Next revision
Previous revision
collapse-openmp [June 11, 2026 at 07:42] – created - external edit 127.0.0.1collapse-openmp [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-# Collapse (OpenMP) 
-**Collapse** is an OpenMP clause that merges multiple perfectly-nested loops into a single flat iteration space before distributing work across threads. When a loop nest has too few outer iterations to keep all threads busy, distributing only the outer loop leaves most threads idle. `collapse(N)` multiplies the available parallelism by treating the combined iteration space as one loop. "Perfectly nested" means no statements appear between the loop headers. 
- 
-```c 
-#pragma omp parallel for collapse(2) 
-for (int i = 0; i < M; i++) { 
-    for (int j = 0; j < N; j++) { 
-        a[i][j] = b[i][j] * c[i][j]; 
-    } 
-} 
-``` 
- 
-Without `collapse(2)`, a 4-thread run on a loop with `M = 2` would use at most 2 threads. With it, the iteration space is `M * N`, and all 4 threads stay busy. The combined iteration space is split and scheduled according to the `schedule` clause as usual. 
  
collapse-openmp.1781163760.md.gz · Last modified: by 127.0.0.1