collapse-openmp
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| collapse-openmp [June 11, 2026 at 09:18] – Ivan Janevski | collapse-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. " | ||
| - | |||
| - | ```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)`, | ||
collapse-openmp.1781169491.md.gz · Last modified: by Ivan Janevski
