This project is a C++ console application that demonstrates parallel programming concepts using both POSIX Threads (pthreads) and OpenMP.
It simulates a simple Task Manager, where multiple tasks run in parallel, log their execution, and report results.
The program creates six different tasks, executes them concurrently using pthreads with mutex-based synchronization,
and then re-implements the same tasks using OpenMP with critical regions.
This project showcases:
- Multi-threading with pthreads
- Synchronization with mutex locks
- Parallel sections with OpenMP
- Performance comparison between pthreads and OpenMP
Each thread simulates a different system-like task:
- Factorial Calculation
- Computes factorial of a number.
- Fibonacci Sequence
- Computes the nth Fibonacci number.
- Prime Number Counter
- Counts all prime numbers up to 100,000.
- File Download Simulation
- Simulates downloading a file with percentage updates.
- Directory Scan Simulation
- Simulates scanning a folder and listing files.
- Random Number Generator
- Generates and prints random numbers.
Each task reports:
- Start & finish messages
- Execution result (e.g., factorial result, Fibonacci number, prime count, etc.)
- Execution time
- Uses
pthread_createto launch threads. - Each thread logs its execution details in a shared vector
taskLogs. - A mutex lock (
pthread_mutex_t) ensures that logs are written safely without race conditions. - Main thread waits for completion using
pthread_join.
- Uses
#pragma omp parallel sectionsto run tasks in parallel. - Shared log storage (
taskLogsOmp) is protected by#pragma omp criticalsections. - No manual thread creation/joining needed.
parallel-task-manager-cpp/
│
├── src/
│ └── parallel_task_manager.cpp # Main C++ source code
│
├── README.md # Project documentation
└── LICENSE # MIT License
g++ src/task_manager.cpp -o task_manager -lpthread
./parallel_task_managerg++ src/task_manager.cpp -o task_manager -fopenmp
./parallel_task_manager[Thread 1] Starting Factorial Task...
[Thread 2] Starting Fibonacci Task...
[Thread 3] Starting Prime Number Task...
[Thread 4] Starting Download File Task...
[Thread 5] Starting Directory Scan Task...
[Thread 6] Starting Random Number Task...
...
[Thread 1] Done!!! Result = 40320
[Thread 2] Done!!! Fibonacci(18) = 2584
[Thread 3] Done!!! Primes Found Between (2-100000). Count = 9592
[Thread 4] File Download Completed :)
[Thread 5] Directory Scan Completed :)
[Thread 6] Random Numbers = 72 15 93 40 61
<<<<<<<< [Pthreads + Mutex] Execution Time: 12.452891 seconds. >>>>>>>>
!! PASSING TO THE OpenMP !!
<<<<<<<< [OpenMP] Execution Time: 15.823712 seconds. >>>>>>>>
- Add more task types (e.g., sorting, matrix multiplication).
- Store logs in external files.
- Visualize thread execution timeline.
- Compare performance across different system configurations.
- Language: C++17
- Threading APIs: POSIX Threads (pthreads), OpenMP
- Synchronization: Mutex locks, critical sections
- Libraries:
<pthread.h>,<omp.h>,<chrono>,<thread>,<vector>
This project is licensed under the MIT License.
See the LICENSE file for details.