Open Multi-processing (OpenMP)

an extension to C/C++/Fortran languages by adding the parallelizing features to them. - Introduction

// OpenMP header
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
  
int main(int argc, char* argv[])
{
    int nthreads, tid;
  
    // Begin of parallel region
    #pragma omp parallel private(nthreads, tid)
    {
        // Getting thread number
        tid = omp_get_thread_num();
        printf("Welcome to GFG from thread = %d\n",
               tid);
  
        if (tid == 0) {
  
            // Only master thread does this
            nthreads = omp_get_num_threads();
            printf("Number of threads = %d\n",
                   nthreads);
        }
    }
}

caption

see also

  • [Agade arena][https://github.com/Agade09/CG-UTTT-Arena/blob/master/Arena.cpp)
Written on January 28, 2023, Last update on January 29, 2023
c++ concurrency thread