[775] | 1 | ! |
---|
[1403] | 2 | !$Id: mod_phys_lmdz_omp_data.F90 3605 2019-11-21 15:43:45Z dcugnet $ |
---|
[775] | 3 | ! |
---|
| 4 | MODULE mod_phys_lmdz_omp_data |
---|
| 5 | |
---|
| 6 | INTEGER,SAVE :: omp_size |
---|
| 7 | INTEGER,SAVE :: omp_rank |
---|
| 8 | LOGICAL,SAVE :: is_omp_root |
---|
[3605] | 9 | LOGICAL,SAVE :: is_omp_master ! alias of is_omp_root |
---|
[1001] | 10 | LOGICAL,SAVE :: is_using_omp |
---|
[2429] | 11 | LOGICAL,SAVE :: is_north_pole_phy, is_south_pole_phy |
---|
[775] | 12 | |
---|
| 13 | INTEGER,SAVE,DIMENSION(:),ALLOCATABLE :: klon_omp_para_nb |
---|
| 14 | INTEGER,SAVE,DIMENSION(:),ALLOCATABLE :: klon_omp_para_begin |
---|
| 15 | INTEGER,SAVE,DIMENSION(:),ALLOCATABLE :: klon_omp_para_end |
---|
| 16 | |
---|
| 17 | INTEGER,SAVE :: klon_omp |
---|
| 18 | INTEGER,SAVE :: klon_omp_begin |
---|
| 19 | INTEGER,SAVE :: klon_omp_end |
---|
[3605] | 20 | !$OMP THREADPRIVATE(omp_rank,klon_omp,is_omp_root,is_omp_master,klon_omp_begin,klon_omp_end) |
---|
[2429] | 21 | !$OMP THREADPRIVATE(is_north_pole_phy, is_south_pole_phy) |
---|
[775] | 22 | |
---|
| 23 | CONTAINS |
---|
| 24 | |
---|
| 25 | SUBROUTINE Init_phys_lmdz_omp_data(klon_mpi) |
---|
[2429] | 26 | USE dimphy |
---|
| 27 | USE mod_phys_lmdz_mpi_data, ONLY : is_north_pole_dyn, is_south_pole_dyn |
---|
[775] | 28 | IMPLICIT NONE |
---|
| 29 | INTEGER, INTENT(in) :: klon_mpi |
---|
| 30 | |
---|
| 31 | INTEGER :: i |
---|
| 32 | |
---|
[1403] | 33 | CHARACTER (LEN=20) :: modname='Init_phys_lmdz_omp_data' |
---|
| 34 | CHARACTER (LEN=80) :: abort_message |
---|
| 35 | |
---|
| 36 | |
---|
[1001] | 37 | #ifdef CPP_OMP |
---|
[775] | 38 | INTEGER :: OMP_GET_NUM_THREADS |
---|
| 39 | EXTERNAL OMP_GET_NUM_THREADS |
---|
| 40 | INTEGER :: OMP_GET_THREAD_NUM |
---|
| 41 | EXTERNAL OMP_GET_THREAD_NUM |
---|
| 42 | #endif |
---|
| 43 | |
---|
[1001] | 44 | #ifdef CPP_OMP |
---|
[775] | 45 | !$OMP MASTER |
---|
[1001] | 46 | is_using_omp=.TRUE. |
---|
[775] | 47 | omp_size=OMP_GET_NUM_THREADS() |
---|
| 48 | !$OMP END MASTER |
---|
[2429] | 49 | !$OMP BARRIER |
---|
[775] | 50 | omp_rank=OMP_GET_THREAD_NUM() |
---|
| 51 | #else |
---|
[1001] | 52 | is_using_omp=.FALSE. |
---|
[775] | 53 | omp_size=1 |
---|
| 54 | omp_rank=0 |
---|
| 55 | #endif |
---|
| 56 | |
---|
| 57 | is_omp_root=.FALSE. |
---|
| 58 | !$OMP MASTER |
---|
| 59 | IF (omp_rank==0) THEN |
---|
| 60 | is_omp_root=.TRUE. |
---|
| 61 | ELSE |
---|
[1403] | 62 | abort_message = 'ANORMAL : OMP_MASTER /= 0' |
---|
[3605] | 63 | CALL abort_physic (modname,abort_message,1) |
---|
[775] | 64 | ENDIF |
---|
| 65 | !$OMP END MASTER |
---|
[3605] | 66 | is_omp_master=is_omp_root |
---|
[775] | 67 | |
---|
| 68 | !$OMP MASTER |
---|
[2429] | 69 | |
---|
[775] | 70 | ALLOCATE(klon_omp_para_nb(0:omp_size-1)) |
---|
| 71 | ALLOCATE(klon_omp_para_begin(0:omp_size-1)) |
---|
| 72 | ALLOCATE(klon_omp_para_end(0:omp_size-1)) |
---|
| 73 | |
---|
| 74 | DO i=0,omp_size-1 |
---|
| 75 | klon_omp_para_nb(i)=klon_mpi/omp_size |
---|
| 76 | IF (i<MOD(klon_mpi,omp_size)) klon_omp_para_nb(i)=klon_omp_para_nb(i)+1 |
---|
| 77 | ENDDO |
---|
| 78 | |
---|
| 79 | klon_omp_para_begin(0) = 1 |
---|
| 80 | klon_omp_para_end(0) = klon_omp_para_nb(0) |
---|
| 81 | |
---|
| 82 | DO i=1,omp_size-1 |
---|
| 83 | klon_omp_para_begin(i)=klon_omp_para_end(i-1)+1 |
---|
| 84 | klon_omp_para_end(i)=klon_omp_para_begin(i)+klon_omp_para_nb(i)-1 |
---|
| 85 | ENDDO |
---|
| 86 | !$OMP END MASTER |
---|
| 87 | !$OMP BARRIER |
---|
[2429] | 88 | |
---|
| 89 | if ((is_north_pole_dyn) .AND. (omp_rank == 0 )) then |
---|
| 90 | is_north_pole_phy = .TRUE. |
---|
| 91 | else |
---|
| 92 | is_north_pole_phy = .FALSE. |
---|
| 93 | endif |
---|
| 94 | if ((is_south_pole_dyn) .AND. (omp_rank == omp_size-1)) then |
---|
| 95 | is_south_pole_phy = .TRUE. |
---|
| 96 | else |
---|
| 97 | is_south_pole_phy = .FALSE. |
---|
| 98 | endif |
---|
[775] | 99 | |
---|
| 100 | klon_omp=klon_omp_para_nb(omp_rank) |
---|
| 101 | klon_omp_begin=klon_omp_para_begin(omp_rank) |
---|
| 102 | klon_omp_end=klon_omp_para_end(omp_rank) |
---|
| 103 | |
---|
| 104 | CALL Print_module_data |
---|
| 105 | |
---|
| 106 | END SUBROUTINE Init_phys_lmdz_omp_data |
---|
| 107 | |
---|
| 108 | SUBROUTINE Print_module_data |
---|
[3605] | 109 | USE print_control_mod, ONLY: lunout |
---|
[775] | 110 | IMPLICIT NONE |
---|
[3605] | 111 | ! INCLUDE "iniprint.h" |
---|
[775] | 112 | |
---|
| 113 | !$OMP CRITICAL |
---|
[1575] | 114 | WRITE(lunout,*)'--------> TASK ',omp_rank |
---|
| 115 | WRITE(lunout,*)'omp_size =',omp_size |
---|
| 116 | WRITE(lunout,*)'omp_rank =',omp_rank |
---|
| 117 | WRITE(lunout,*)'is_omp_root =',is_omp_root |
---|
| 118 | WRITE(lunout,*)'klon_omp_para_nb =',klon_omp_para_nb |
---|
| 119 | WRITE(lunout,*)'klon_omp_para_begin =',klon_omp_para_begin |
---|
| 120 | WRITE(lunout,*)'klon_omp_para_end =',klon_omp_para_end |
---|
| 121 | WRITE(lunout,*)'klon_omp =',klon_omp |
---|
| 122 | WRITE(lunout,*)'klon_omp_begin =',klon_omp_begin |
---|
| 123 | WRITE(lunout,*)'klon_omp_end =',klon_omp_end |
---|
[775] | 124 | !$OMP END CRITICAL |
---|
| 125 | |
---|
| 126 | END SUBROUTINE Print_module_data |
---|
| 127 | END MODULE mod_phys_lmdz_omp_data |
---|