OpenMP
krisrak
31.5K views
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
OpenMP Playground
Write any OpenMP code and run
test.cpp
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <omp.h>
#include <iostream>
static const int N = 16;
int main(){
int is_cpu = true;
int *data = static_cast<int*>(malloc(N * sizeof(int)));
for(int i=0; i<N; i++) data[i] = i;
#pragma omp target map(from:is_cpu) map(tofrom:data[0:N])
{
is_cpu=omp_is_initial_device();
#pragma omp parallel for
for (int i=0; i<N; i++)
data[i] *= 2;
}
printf ("Running on %s\n", (is_cpu?"CPU":"GPU"));
for(int i=0; i<N; i++) std::cout << data[i] << std::endl;
free(data);
return 0;
}
Enter to Rename, Shift+Enter to Preview