PGI, OpenMP and namelist in Fortran -


i encounter problem while trying read namelist in fortran program, using openmp , portland group compiler.

what trying simple: call read_namelist subroutine in single region, initialize parameters want read namelist, , open, read, close namelist. parameters i'm reading in namelist threadprivate, , spread them other threads after reading.

while works gnu , intel compilers, fails pgi , cannot why. no error, read parameters equal default parameters, not ones read namelist.

here example of trying do:

program read_input   !$ use omp_lib   use params   implicit none    integer :: rank=0, nthreads=1    !$omp parallel default(private)   !$ rank = omp_get_thread_num()   !$ nthreads = omp_get_num_threads()      !$omp single    print*, 'there ', nthreads, ' threads running'    call read_nml   !$omp end single copyprivate(nx, ny, nz)    print*, 'rank: ', rank   print*, 'nx, ny, nz: ', nx, ny, nz   !$omp end parallel     contains   subroutine read_nml     use params     implicit none     namelist /input_params/ nx, ny, nz      call default_parameters     print*, 'nx, ny, nz (default): ', nx, ny, nz      open(unit=1, file='input', status='old')     read(1, input_params)     close(1)     print*, 'nx, ny, nz (read): ', nx, ny, nz      return   end subroutine read_nml    subroutine default_parameters     use params     implicit none      nx = 2; ny = 2; nz = 2      return   end subroutine default_parameters end program read_input 

the module params simple , contains only:

module params   integer :: nx, ny, nz   !$omp threadprivate(nx, ny, nz) end module params 

compiling pgfortran, here output (with 2 threads):

 start program: read_input  there             2  threads running  nx, ny, nz (default):             2            2            2  rank:             0  nx, ny, nz:             2            2            2  rank:             1  nx, ny, nz:             2            2            2 

and if compile same piece of code intel or gnu compilers (still 2 threads):

 start program: read_input  there            2  threads running  nx, ny, nz (default):            2           2           2  nx, ny, nz (read):           10          10          10  rank:            0  nx, ny, nz:           10          10          10  rank:            1  nx, ny, nz:           10          10          10 

any thought or hint appreciated!

i don't exact reason, @ least found workaround, playing code.

if parameters read in namelist private in subroutine, can read no problem; therefore replacing

call read_nml 

by

call read_nml(nx, ny, nz) 

and subroutine read_nml by

  subroutine read_nml(nx, ny, nz)     implicit none     integer :: nx, ny, nz                  namelist /input_params/ nx, ny, nz      call default_parameters     print*, 'nx, ny, nz (default): ', nx, ny, nz      open(unit=1, file='input', status='old')     read(1, input_params)     close(1)     print*, 'nx, ny, nz (read): ', nx, ny, nz      return   end subroutine read_nml 

works well. guess once again problem of status (private) of attributes, don't why intel , gnu compilers handled no problem whereas pgi compiler not able handle it. actually, why parameters threadprivate in module, prevent kind of behaviour. if can give me better answer 1 have, i'm still interested!


Comments