source: LMDZ6/trunk/libf/phy_common/mod_phys_lmdz_omp_data.F90 @ 5396

Last change on this file since 5396 was 5291, checked in by abarral, 7 weeks ago

Move thermcell_old.h iotd.h to module

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1!
2!$Id: mod_phys_lmdz_omp_data.F90 5291 2024-10-28 15:44:39Z evignon $
3!
4MODULE mod_phys_lmdz_omp_data
5
6  INTEGER,SAVE :: omp_size
7  INTEGER,SAVE :: omp_rank
8  LOGICAL,SAVE :: is_omp_root
9  LOGICAL,SAVE :: is_omp_master  ! alias of is_omp_root
10  LOGICAL,SAVE :: is_using_omp
11  LOGICAL,SAVE :: is_north_pole_phy, is_south_pole_phy
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
20!$OMP  THREADPRIVATE(omp_rank,klon_omp,is_omp_root,is_omp_master,klon_omp_begin,klon_omp_end)
21!$OMP  THREADPRIVATE(is_north_pole_phy, is_south_pole_phy)
22
23CONTAINS
24 
25  SUBROUTINE Init_phys_lmdz_omp_data(klon_mpi)
26    USE dimphy
27    USE mod_phys_lmdz_mpi_data, ONLY : is_north_pole_dyn, is_south_pole_dyn
28    IMPLICIT NONE
29    INTEGER, INTENT(in) :: klon_mpi
30
31    INTEGER :: i
32
33    CHARACTER (LEN=20) :: modname='Init_phys_lmdz_omp_data'
34    CHARACTER (LEN=80) :: abort_message
35
36
37#ifdef CPP_OMP   
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
44#ifdef CPP_OMP
45!$OMP MASTER
46        is_using_omp=.TRUE.
47        omp_size=OMP_GET_NUM_THREADS()
48!$OMP END MASTER
49!$OMP BARRIER
50        omp_rank=OMP_GET_THREAD_NUM()   
51#else   
52    is_using_omp=.FALSE.
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
62     abort_message = 'ANORMAL : OMP_MASTER /= 0'
63     CALL abort_physic (modname,abort_message,1)
64   ENDIF
65!$OMP END MASTER
66   is_omp_master=is_omp_root
67
68!$OMP MASTER
69
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
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
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
109  USE print_control_mod, ONLY: lunout
110  IMPLICIT NONE
111
112!$OMP CRITICAL 
113  WRITE(lunout,*)'--------> TASK ',omp_rank
114  WRITE(lunout,*)'omp_size =',omp_size
115  WRITE(lunout,*)'omp_rank =',omp_rank
116  WRITE(lunout,*)'is_omp_root =',is_omp_root
117  WRITE(lunout,*)'klon_omp_para_nb =',klon_omp_para_nb
118  WRITE(lunout,*)'klon_omp_para_begin =',klon_omp_para_begin
119  WRITE(lunout,*)'klon_omp_para_end =',klon_omp_para_end   
120  WRITE(lunout,*)'klon_omp =',klon_omp
121  WRITE(lunout,*)'klon_omp_begin =',klon_omp_begin
122  WRITE(lunout,*)'klon_omp_end =',klon_omp_end   
123!$OMP END CRITICAL
124
125  END SUBROUTINE Print_module_data
126END MODULE mod_phys_lmdz_omp_data
Note: See TracBrowser for help on using the repository browser.