Created
June 18, 2012 09:56
-
-
Save aprell/2947709 to your computer and use it in GitHub Desktop.
OpenMP: #pragma omp parallel
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(int argc, char *argv[]) | |
{ | |
if (argc != 2) exit(0); | |
#pragma omp parallel num_threads(4) | |
printf("Thread %d says %s\n", omp_get_thread_num(), argv[1]); | |
return 0; | |
} | |
============================================================================== | |
After OpenMP lowering and expansion: | |
============================================================================== | |
/* libgomp/parallel.c: | |
* - GOMP_parallel_start | |
* - GOMP_parallel_end | |
*/ | |
struct omp_data { | |
char **argv; | |
}; | |
void main_omp_fn_0(struct omp_data *omp_data) | |
{ | |
char **argv; | |
argv = omp_data->argv; | |
printf("Thread %d says %s\n", omp_get_thread_num(), argv[1]); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
struct omp_data omp_data; | |
if (argc != 2) exit(0); | |
omp_data.argv = argv; | |
// Spawns a team of threads | |
__builtin_GOMP_parallel_start(main_omp_fn_0, &omp_data, 4); | |
main_omp_fn_0(&omp_data); | |
// 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