How do I use OpenMP/TBB for parallelism in C++?

Learn how to leverage OpenMP and TBB (Threading Building Blocks) for parallelism in C++. This guide provides examples and insights to improve your application's performance through concurrent programming.
OpenMP, TBB, C++, parallelism, concurrency, multithreading, performance optimization

        // Example using OpenMP
        #include 
        #include 
        
        int main() {
            #pragma omp parallel
            {
                int thread_id = omp_get_thread_num();
                std::cout << "Hello from thread " << thread_id << std::endl;
            }
            return 0;
        }

        // Example using TBB
        #include 
        #include 
        
        int main() {
            tbb::parallel_for(0, 10, [](int i) {
                std::cout << "Hello from TBB thread " << i << std::endl;
            });
            return 0;
        }
    

OpenMP TBB C++ parallelism concurrency multithreading performance optimization