Last active
October 6, 2015 05:58
-
-
Save aprell/2947737 to your computer and use it in GitHub Desktop.
OpenMP: #pragma omp task
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) | |
{ | |
int s, a = 4, b = 2; | |
#pragma omp task shared(s) | |
s = a + b; | |
#pragma omp taskwait | |
printf("s is %d\n", s); | |
return 0; | |
} | |
============================================================================== | |
After OpenMP lowering and expansion: | |
============================================================================== | |
/* | |
* libgomp/task.c: | |
* - GOMP_task | |
* - GOMP_taskwait | |
*/ | |
extern void GOMP_task(void (*fn)(void *), void *data, void (*copyfn)(void *, void *), | |
long arg_size, long arg_align, bool if_clause, unsigned flags __attribute__((unused))); | |
extern void GOMP_taskwait(void); | |
struct omp_data { | |
int a, b, *s; | |
}; | |
void main_omp_fn_0(struct omp_data *omp_data) | |
{ | |
int *s, a, b; | |
a = omp_data->a; | |
b = omp_data->b; | |
s = omp_data->s; | |
*s = a + b; | |
} | |
int main(void) | |
{ | |
int s, a = 4, b = 2; | |
struct omp_data omp_data; | |
omp_data.a = a; | |
omp_data.b = b; | |
omp_data.s = &s; | |
__builtin_GOMP_task(main_omp_fn_0, &omp_data, NULL, 12, 4, 1, 0); | |
// Waits until child tasks have completed | |
// Helps executing them | |
__builtin_GOMP_taskwait(); | |
printf("s is %d\n", s); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment