最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

openmp - Variable declaration in fortran : Pros and Cons between declaration in a block construct or copy in a private OMP Paral

programmeradmin1浏览0评论

I wrote these two programs to test OMP PARALLEL:

1 : my_idx is declared at the beginning of the program and after a private copy for eah thread is done.

program my_pgm

    use omp_lib
    implicit none
    
    integer :: my_idx
    
    CALL OMP_set_dynamic(.FALSE.)
    CALL OMP_set_num_threads(2)
    
    !$OMP PARALLEL DEFAULT(SHARED) PRIVATE(my_idx)
 
    DO my_idx = 0, 3
        WRITE(*,*) 'my_idx , thread_num, ',my_idx,omp_get_thread_num()
    END DO
    
    !$OMP END PARALLEL
    
end program my_pgm

2 : my_idx is declared in a BLOCK after !$OMP PARALLEL

program my_pgm

    use omp_lib
    implicit none
        
    CALL OMP_set_dynamic(.FALSE.)
    CALL OMP_set_num_threads(2)
    
    !$OMP PARALLEL DEFAULT(SHARED)
    
    BLOCK

        integer :: my_idx
 
        DO my_idx = 0, 3
            WRITE(*,*) 'my_idx , thread_num, ',my_idx,omp_get_thread_num()
        END DO
    
    END BLOCK
    
    !$OMP END PARALLEL
    
end program my_pgm

What are the pros and the cons of these two programs ? Or are they equivalent ?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论