fortran - Reading multiple files in parallel and storing them in shared variables -


i have program reads number of large files (~100s files, 120mb each) generated mpi program, can take time. each file contains variables in corresponding subdomain. want read in variables files , store them specific slice of 4 dimensional array. since takes considerable amount of time, parallelize piece of code openmp:

  6     subroutine read_old_restart   7         integer :: ii   8         integer :: thread_id   9         integer :: omp_get_thread_num  10         character(len=21) :: file_name  11   12         !$omp parallel private(ii,file_name)  13         ii=0,nproc_old-1  14             if(ii < 10)  15                 write(file_name,401) "input/restart_00", ii, ".out"  16             else if(ii < 100)  17                 write(file_name,402) "input/restart_0" , ii, ".out"  18             else  19                 write(file_name,403) "input/restart_"  , ii, ".out"  20             end if  21             print*, "thread = ", omp_get_thread_num(), "reading ", file_name  22 401 format(a16,i1,a4)  23 402 format(a15,i2,a4)  24 403 format(a14,i3,a4)  25             open (unit=321, file=trim(file_name), status="old", form="unformatted")  26             read(321) t                       ,                         &   27                       old_u         (:,:,:,ii),                         &   28                       old_v         (:,:,:,ii),                         &   29                       old_w         (:,:,:,ii),                         &  30                       old_p         (:,:,:,ii),                         &  31                       old_uc        (:,:,:,ii),                         &  32                       old_vc        (:,:,:,ii),                         &  33                       old_wc        (:,:,:,ii),                         &  34                       old_un2       (:,:,:,ii),                         &  35                       old_vn2       (:,:,:,ii),                         &  36                       old_wn2       (:,:,:,ii),                         &  37                       old_un1       (:,:,:,ii),                         &  38                       old_vn1       (:,:,:,ii),                         &  39                       old_wn1       (:,:,:,ii),                         &  40                       old_p1        (:,:,:,ii),                         &  41                       old_viscu     (:,:,:,ii),                         &  42                       old_viscv     (:,:,:,ii),                         &  43                       old_viscw     (:,:,:,ii),                         &  44                       old_convu     (:,:,:,ii),                         &  45                       old_convv     (:,:,:,ii),                         &  46                       old_convw     (:,:,:,ii),                         &  47                       statindex               ,                         &  48                       old_umn       (:,:,:,ii),                         &  49                       old_uumn      (:,:,:,ii),                         &  50                       old_urms      (:,:,:,ii),                         &  51                       old_mass_frac (:,:,:,:,:,ii), &                     52                       old_entht     (:,:,:,:,ii)  53             close (321)  54         end  55         !$omp end parallel  56     end subroutine read_old_restart 

the code compiles , runs fine first loop of each thread. here output:

 thread =            3 reading input/restart_030.out  thread =            7 reading input/restart_067.out  thread =            2 reading input/restart_020.out  thread =            6 reading input/restart_058.out  thread =            9 reading input/restart_085.out  thread =            8 reading input/restart_076.out  thread =            5 reading input/restart_049.out  thread =            4 reading input/restart_040.out  thread =           11 reading input/restart_103.out  thread =            0 reading input/restart_000.out  thread =            1 reading input/restart_010.out  thread =           10 reading input/restart_094.out 

the code appears running , gets stuck on above output. when running top, cannot cpu usage. idea why not working expected?

you should use private integer variable unit number , set different value each thread. using same file unit differently different threads recipe trouble. quite surprised not crash.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -