Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 8th, 2012  |  syntax: None  |  size: 1.09 KB  |  views: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <omp.h>
  4.  
  5. int main(void)
  6. {
  7.         #pragma omp parallel num_threads(4)
  8.         {
  9.                 printf("%d: Hello outer parallel region!\n", omp_get_thread_num());
  10.  
  11.                 #pragma omp parallel
  12.                 {
  13.                         printf("%d: Hello inner parallel region!\n", omp_get_thread_num());
  14.                 }
  15.         }
  16.  
  17.         return 0;
  18. }
  19.  
  20. ==============================================================================
  21. After OpenMP lowering and expansion:
  22. ==============================================================================
  23.  
  24. /* libgomp/parallel.c:
  25.  * - GOMP_parallel_start
  26.  * - GOMP_parallel_end
  27.  */
  28.  
  29. void main_omp_fn_1(void *omp_data)
  30. {
  31.         printf("%d: Hello inner parallel region!\n", omp_get_thread_num());
  32. }
  33.  
  34. void main_omp_fn_0(void *omp_data)
  35. {
  36.         printf("%d: Hello outer parallel region!\n", omp_get_thread_num());
  37.  
  38.         __builtin_GOMP_parallel_start(main_omp_fn_1, NULL, 0);
  39.  
  40.         main_omp_fn_1(NULL);
  41.        
  42.         __builtin_GOMP_parallel_end();
  43. }
  44.  
  45. int main(void)
  46. {
  47.         // Spawns a team of threads
  48.         __builtin_GOMP_parallel_start(main_omp_fn_0, NULL, 4);
  49.  
  50.         main_omp_fn_0(NULL);
  51.        
  52.         // Terminates current team of threads
  53.         __builtin_GOMP_parallel_end();
  54.  
  55.         return 0;
  56. }