2017-12-23 25 views
0

私は、各スレッドがomp_get_thread_num()でアクセス可能なスレッドのID番号でアドレス指定されたメモリを管理するようにすることで、CPU上で動作するOpenMPコードを持っています。これはCPU上でうまく動作しますが、GPUでも動作しますか?GPUで `omp_get_thread_num()`を使うことはできますか?

A MWEは次のとおりです。

#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"; 
} 

答えて

0

答えはノーのようです。使用PGIでコンパイル

pgc++ -fast -mp -ta=tesla,pinned,cc60 -Minfo=all test2.cpp 

を与える:

13, Parallel region activated 
    Parallel loop activated with static block schedule 
    Loop not vectorized/parallelized: contains call 
14, Parallel region terminated 

g++ -O3 test2.cpp -fopenmp -fopt-info 

使用GCCでコンパイル一方は

test2.cpp:17: note: not vectorized: loop contains function calls or data references that cannot be analyzed 
test2.cpp:17: note: bad data references. 
を与えます
関連する問題