2017-03-20 27 views
1

入れ子の並列領域に問題があるので、私は非常に単純なopenmpのfortranプログラムを試しています。コードは以下の通りである。OpenMPとgfortranのネストされた並列領域

PROGRAM TEST_OPENMP 
IMPLICIT NONE 
INTEGER :: omp_get_num_threads, omp_get_thread_num 
CALL omp_set_num_threads(4) 
WRITE(*,*) "I am the master thread" 
!$OMP PARALLEL 
write(*,*) "Hello, I am in the first parallel region", omp_get_thread_num() 
!$OMP PARALLEL 
write(*,*) "I am a nested parallel region : ", omp_get_thread_num() 
!$OMP END PARALLEL 
!$OMP END PARALLEL 
write(*,*) "The master thread is back: serial region", omp_get_thread_num() 
END PROGRAM TEST_OPENMP 

私は「...私は、ネストされたよ」「こんにちは、私は...だ」との16のように始まる文字列の4つのインスタンスを持つことが期待されるが、私は何を得ます

I am the master thread 
Hello, I am in the first parallel region   3 
Hello, I am in the first parallel region   2 
Hello, I am in the first parallel region   1 
I am a nested parallel region :   0 
I am a nested parallel region :   0 
Hello, I am in the first parallel region   0 
I am a nested parallel region :   0 
I am a nested parallel region :   0 
The master thread is back: serial region   0 

したがって、2番目の並列領域は線形として扱われます。私は'gfortran -fopenmp filename 'でコンパイルしています。恐ろしいことをしていますか?

+0

ですか? – tim18

+0

(非常に)有用な先端のopenmp初心者のおかげで。 – Currix

+0

もっと注意を喚起するために、すべてのFortranの質問に対してtag [tag:fortran]を使用してください。特定のバージョンタグを追加することはできますが、ここでは必ずしも必要ではありません。コードは古いFortran 90固有のものではありません。 –

答えて

1

ティムティムありがとう。 OMP_NESTEDについて言及していないチュートリアルを使用していました。愚かな質問には申し訳ありません。

は、今ではスムーズに動作します:それは関係なく、OMP_NESTEDの同じ

$ export OMP_NESTED=True 
$ gfortran -fopenmp openmp_example_3.f90 
$ a.out 
I am the master thread 
Hello, I am in the first parallel region   0 
Hello, I am in the first parallel region   3 
I am a nested parallel region :   0 
I am a nested parallel region :   2 
Hello, I am in the first parallel region   2 
I am a nested parallel region :   1 
Hello, I am in the first parallel region   1 
I am a nested parallel region :   3 
I am a nested parallel region :   0 
I am a nested parallel region :   1 
I am a nested parallel region :   1 
I am a nested parallel region :   0 
I am a nested parallel region :   1 
I am a nested parallel region :   3 
I am a nested parallel region :   2 
I am a nested parallel region :   3 
I am a nested parallel region :   0 
I am a nested parallel region :   2 
I am a nested parallel region :   3 
I am a nested parallel region :   2 
The master thread is back: serial region   0 
関連する問題