openmp
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| openmp [June 10, 2026 at 21:49] – Ivan Janevski | openmp [August 22, 2026 at 15:22] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| # OpenMP | # OpenMP | ||
| - | **OpenMP** is a parallel computing API mostly used for CPU parallelism. It's created for C, C++ and Fortran programming languages. | ||
| - | It' | + | **OpenMP** is a shared-memory parallelism API for C, C++, and Fortran. Add a `# |
| - | OpenMP | + | The execution model is **fork-join**: |
| - | ## Example | ||
| ```c | ```c | ||
| - | // #include < | + | // compile: gcc -O2 -fopenmp -o sum sum.c |
| - | #pragma omp parallel | + | // run: OMP_NUM_THREADS=4 ./sum |
| - | { | + | // description: |
| - | | + | |
| - | printf(" | + | #include < |
| + | #include < | ||
| + | |||
| + | int main(void) | ||
| + | | ||
| + | double t = omp_get_wtime(); | ||
| + | #pragma omp parallel for reduction(+: | ||
| + | for (long i = 0; i < n; i++) | ||
| + | sum += i; | ||
| + | printf(" | ||
| + | return 0; | ||
| } | } | ||
| ``` | ``` | ||
| - | For example, if your environment variable is set to `export OMP_NUM_THREADS=5` you would see the following. Each worker thread | + | |
| - | ``` | + | On a 4-core machine this runs roughly 4× faster with `-fopenmp` than without. [[amdahls-law|Amdahl' |
| - | Hello, I'm thread 4 | + | |
| - | Hello, I'm thread | + | ## Concepts |
| - | Hello, I'm thread | + | |
| - | Hello, I'm thread 2 | + | 1. [[openmp-data-sharing|Data sharing]] |
| - | Hello, I' | + | 2. [[openmp-parallel-loops|Parallel loops]] |
| - | ``` | + | 3. [[openmp-collapse|Collapse]] |
| + | 4. [[openmp-reduction|Reduction]] | ||
| + | 5. [[openmp-scheduling|Scheduling]] | ||
| + | 6. [[openmp-simd|SIMD]] | ||
| + | 7. [[openmp-tasks|Tasks]] | ||
| + | 8. [[openmp-single|Single]] | ||
| + | 9. [[openmp-master|Master]] | ||
| + | 10. [[openmp-sections|Sections]] | ||
| + | 11. [[openmp-barrier|Barrier]] | ||
| + | 12. [[openmp-nowait|Nowait]] | ||
| + | 13. [[openmp-critical-sections|Critical sections]] | ||
| + | 14. [[openmp-atomic|Atomic]] | ||
| + | 15. [[openmp-flush|Flush]] | ||
| + | 16. [[openmp-false-sharing|False sharing]] | ||
| + | 17. [[openmp-thread-affinity|Thread affinity]] | ||
| + | 18. [[openmp-time-measurement|Time measurement]] | ||
| + | 19. [[openmp-overview|Overview]] | ||
openmp.1781128156.md.gz · Last modified: by Ivan Janevski
