Issue with common block in OpenMP parallel programming

旧城冷巷雨未停 提交于 2019-12-01 13:37:50

Firstly as the comment above says I would strongly advise against the use of common especially in modern code, and mixing global data and parallelism is just asking for a world of pain - in fact global data is just a bad idea full stop.

OK, your questions:

  1. My subroutines has common blocks. Do I have to declare all the common block and threadprivate in the parallel do region?

No,threadprivate is a declarative directive, and should be used only in the declarative part of the code, and it must appear after every declaration.

  1. How do they pass information? I want seperate common clock for each thread and want them to pass information through the end of parallel region. Does it happen here?

As you suspect each thread will gets its own version of the common block. When you enter the first parallel region the values in the block will be undefined, unless you use copyin to broadcast the values from the master thread. For subsequent parallel regions the values will be retained as long as the number of threads used in each region is the same. Between regions the values in the common block will be those of the master thread.

  1. Are those common block accessible through the subroutine? My Ford subroutine rewrite some variables in common block and Condat subroutine rewrite over them again but the function uses the values from Condat subroutine. Is that possible rewrite and pass the common block variable using threadprivate here?

I have to admit I am unsure what you are asking here. But if you are asking whether common can be used to communicate variables between different sub-programs in OpenMP code, the answer is yes, just as in serial Fortran (note capitalisation)

How about converting the common blocks into modules?

Change common /root/ root1, root2 to use gammax, then make a new file root.f that contains:

module root
implicit none
save
real :: root1, root2
!$omp threadprivate( root1, root2 )
end module root
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!