Created
June 18, 2012 10:01
-
-
Save aprell/2947722 to your computer and use it in GitHub Desktop.
OpenMP: #pragma omp parallel (nested)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <omp.h> | |
int main(void) | |
{ | |
#pragma omp parallel num_threads(4) | |
{ | |
printf("%d: Hello outer parallel region!\n", omp_get_thread_num()); | |
#pragma omp parallel | |
{ | |
printf("%d: Hello inner parallel region!\n", omp_get_thread_num()); | |
} | |
} | |
return 0; | |
} | |
============================================================================== | |
After OpenMP lowering and expansion: | |
============================================================================== | |
/* libgomp/parallel.c: | |
* - GOMP_parallel_start | |
* - GOMP_parallel_end | |
*/ | |
void main_omp_fn_1(void *omp_data) | |
{ | |
printf("%d: Hello inner parallel region!\n", omp_get_thread_num()); | |
} | |
void main_omp_fn_0(void *omp_data) | |
{ | |
printf("%d: Hello outer parallel region!\n", omp_get_thread_num()); | |
__builtin_GOMP_parallel_start(main_omp_fn_1, NULL, 0); | |
main_omp_fn_1(NULL); | |
__builtin_GOMP_parallel_end(); | |
} | |
int main(void) | |
{ | |
// Spawns a team of threads | |
__builtin_GOMP_parallel_start(main_omp_fn_0, NULL, 4); | |
main_omp_fn_0(NULL); | |
// Terminates current team of threads | |
__builtin_GOMP_parallel_end(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment