I have OpenMP code which works on the CPU by having each thread manage memory addressed by the thread's id number, accessible via omp_get_thread_num()
. This works well on the CPU, but can it work on the GPU?
A MWE is:
#include <iostream>
#include <omp.h>
int main(){
const int SIZE = 400000;
int *m;
m = new int[SIZE];
#pragma omp target
{
#pragma omp parallel for
for(int i=0;i<SIZE;i++)
m[i] = omp_get_thread_num();
}
for(int i=0;i<SIZE;i++)
std::cout<<m[i]<<"\n";
}