This repository contains a collection of comprehensive OpenMP examples demonstrating various parallel programming concepts using C++ with Visual Studio 2022 on Windows. Each demo is a self-contained project with full CMake support, detailed documentation, and batch files for easy building and execution.
The repository is organized into the following sections:
- 🔰 Basic Command Line - Introduction to OpenMP compiler options and basic flags
- 🔄 Basic Parallel Regions - Introduction to OpenMP parallel regions
- 🔁 Parallel For Loops - Parallelizing loops with different approaches
- ⚙️ Scheduling Strategies - Comparison of different work distribution strategies
- 💾 Data Sharing - Demonstration of variable scoping and data sharing clauses
- ➕ Reduction Operations - Various reduction operations and custom reductions
- 🔒 Synchronization - Different synchronization mechanisms with performance comparisons
- 📋 Task Parallelism - Task-based programming for irregular parallelism
- 🧵 Nested Parallelism & Affinity - Nested parallel regions and thread affinity controls
- 🚀 SIMD Vectorization - Data parallelism with SIMD instructions
- 🛠️ Debugging & Performance - Techniques for finding and fixing common OpenMP issues
Each folder contains its own README.md with detailed explanations, diagrams, and instructions.
- Windows 10/11
- Visual Studio 2022 Community Edition
- CMake 3.20 or higher
- C++17 compatible compiler
Each project includes:
- A complete CMakeLists.txt configuration
- Source code with extensive comments
- Batch files for configuration, building, and running
- Documentation explaining concepts and implementation
- Visual diagrams illustrating key concepts
To run any example:
- Navigate to the example directory
- Run
configure.batto set up the CMake project - Run
build_all.batto compile the example in all configurations - Run
run.batto execute the example with default settings
The projects now use a unified script system for easier usage:
configure.bat- Sets up the CMake project (run once)build_all.bat- Builds Debug, Release, and Profile configurationsclean.bat- Removes build files for a fresh startrun.bat- Unified script with multiple options:--debug,--release,--profile- Select build configuration--verbose,--quick,--benchmark- Run mode options--threads N- Set number of OpenMP threads--example NAME- Run specific example--help- Show all available options
run_all.bat- Runs examples in different configurations sequentially
Example usages:
run.bat --debug --verbose
run.bat --release --benchmark --threads 8
run.bat --example race_conditions
For best results, follow the examples in numerical order as they build upon concepts introduced in previous demos.
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenMP Architecture Review Board for the OpenMP specification
- Microsoft for Visual Studio and MSVC OpenMP implementation
Contributions are welcome! Please feel free to submit a Pull Request.
