Guest User

openmp.cpp

a guest
Jul 25th, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <omp.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main (int argc, char *argv[])
  6. {
  7. int nthreads, tid;
  8.  
  9. /* Fork a team of threads giving them their own copies of variables */
  10. #pragma omp parallel private(nthreads, tid)
  11.   {
  12.  
  13.   /* Obtain thread number */
  14.   tid = omp_get_thread_num();
  15.   printf("Hello World from thread = %d\n", tid);
  16.  
  17.   /* Only master thread does this */
  18.   if (tid == 0)
  19.     {
  20.     nthreads = omp_get_num_threads();
  21.     printf("Number of threads = %d\n", nthreads);
  22.     }
  23.  
  24.   }  /* All threads join master thread and disband */
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment