LMDZ
bands.F90
Go to the documentation of this file.
1 !
2 ! $Id: bands.F90 2351 2015-08-25 15:14:59Z emillour $
3 !
4  module bands
5 
6  integer, parameter :: bands_caldyn=1
7  integer, parameter :: bands_vanleer=2
8  integer, parameter :: bands_dissip=3
9 
10  INTEGER,dimension(:),allocatable :: jj_nb_caldyn
11  INTEGER,dimension(:),allocatable :: jj_nb_vanleer
12  INTEGER,dimension(:),allocatable :: jj_nb_vanleer2
13  INTEGER,dimension(:),allocatable :: jj_nb_dissip
14  INTEGER,dimension(:),allocatable :: jj_nb_physic
15  INTEGER,dimension(:),allocatable :: jj_nb_physic_bis
16  INTEGER,dimension(:),allocatable :: distrib_phys
17 
18  contains
19 
20  subroutine allocatebands
21  USE parallel_lmdz
22  implicit none
23 
24  allocate(jj_nb_caldyn(0:mpi_size-1))
25  allocate(jj_nb_vanleer(0:mpi_size-1))
26  allocate(jj_nb_vanleer2(0:mpi_size-1))
27  allocate(jj_nb_dissip(0:mpi_size-1))
28  allocate(jj_nb_physic(0:mpi_size-1))
29  allocate(jj_nb_physic_bis(0:mpi_size-1))
30  allocate(distrib_phys(0:mpi_size-1))
31 
32  end subroutine allocatebands
33 
34  subroutine read_distrib
35  USE parallel_lmdz
36  implicit none
37 
38  include "dimensions.h"
39  integer :: i,j
40  character (len=4) :: siim,sjjm,sllm,sproc
41  character (len=255) :: filename
42  integer :: unit_number=10
43  integer :: ierr
44 
45  call allocatebands
46  write(siim,'(i3)') iim
47  write(sjjm,'(i3)') jjm
48  write(sllm,'(i3)') llm
49  write(sproc,'(i3)') mpi_size
50  filename='Bands_'//trim(adjustl(siim))//'x'//trim(adjustl(sjjm))//'x'//trim(adjustl(sllm))//'_' &
51  //trim(adjustl(sproc))//'prc.dat'
52 
53  OPEN(unit=unit_number,file=trim(filename),status='old',form='formatted',iostat=ierr)
54 
55  if (ierr==0) then
56 
57  do i=0,mpi_size-1
58  read (unit_number,*) j,jj_nb_caldyn(i)
59  enddo
60 
61  do i=0,mpi_size-1
62  read (unit_number,*) j,jj_nb_vanleer(i)
63  enddo
64 
65  do i=0,mpi_size-1
66  read (unit_number,*) j,jj_nb_dissip(i)
67  enddo
68 
69  do i=0,mpi_size-1
70  read (unit_number,*) j,distrib_phys(i)
71  enddo
72 
73  CLOSE(unit_number)
74 
75  else
76  do i=0,mpi_size-1
77  jj_nb_caldyn(i)=(jjm+1)/mpi_size
78  if (i<mod(jjm+1,mpi_size)) jj_nb_caldyn(i)=jj_nb_caldyn(i)+1
79  enddo
80 
83 
84  do i=0,mpi_size-1
85  distrib_phys(i)=(iim*(jjm-1)+2)/mpi_size
86  IF (i<mod(iim*(jjm-1)+2,mpi_size)) distrib_phys(i)=distrib_phys(i)+1
87  enddo
88  endif
89 
90  end subroutine read_distrib
91 
92 
93  SUBROUTINE set_bands
94  USE parallel_lmdz
95  IMPLICIT NONE
96  include 'dimensions.h'
97  INTEGER :: i, ij
98  INTEGER :: jj_para_begin(0:mpi_size-1)
99  INTEGER :: jj_para_end(0:mpi_size-1)
100 
101  do i=0,mpi_size-1
102  jj_nb_vanleer2(i)=(jjm+1)/mpi_size
103  if (i<mod(jjm+1,mpi_size)) jj_nb_vanleer2(i)=jj_nb_vanleer2(i)+1
104  enddo
105 
106  jj_para_begin(0)=1
107  ij=distrib_phys(0)+iim-1
108  jj_para_end(0)=((ij-1)/iim)+1
109 
110  DO i=1,mpi_size-1
111  ij=ij+1
112  jj_para_begin(i)=((ij-1)/iim)+1
113  ij=ij+distrib_phys(i)-1
114  jj_para_end(i)=((ij-1)/iim)+1
115  ENDDO
116 
117  do i=0,mpi_size-1
118  jj_nb_physic(i)=jj_para_end(i)-jj_para_begin(i)+1
119  if (i/=0) then
120  if (jj_para_begin(i)==jj_para_end(i-1)) then
121  jj_nb_physic(i-1)=jj_nb_physic(i-1)-1
122  endif
123  endif
124  enddo
125 
126  do i=0,mpi_size-1
127  jj_nb_physic_bis(i)=jj_para_end(i)-jj_para_begin(i)+1
128  if (i/=0) then
129  if (jj_para_begin(i)==jj_para_end(i-1)) then
131  else
134  endif
135  endif
136  enddo
137 
138  end subroutine set_bands
139 
140 
141  subroutine adjustbands_caldyn
142  use times
143  USE parallel_lmdz
144  implicit none
145 
146  real :: minvalue,maxvalue
147  integer :: min_proc,max_proc
148  integer :: i,j
149  real,allocatable,dimension(:) :: value
150  integer,allocatable,dimension(:) :: index
151  real :: tmpvalue
152  integer :: tmpindex
153 
154  allocate(value(0:mpi_size-1))
155  allocate(index(0:mpi_size-1))
156 
157 
159 
160  do i=0,mpi_size-1
162  index(i)=i
163  enddo
164 
165  do i=0,mpi_size-2
166  do j=i+1,mpi_size-1
167  if (value(i)>value(j)) then
168  tmpvalue=value(i)
169  value(i)=value(j)
170  value(j)=tmpvalue
171 
172  tmpindex=index(i)
173  index(i)=index(j)
174  index(j)=tmpindex
175  endif
176  enddo
177  enddo
178 
179  maxvalue=value(mpi_size-1)
180  max_proc=index(mpi_size-1)
181 
182  do i=0,mpi_size-2
183  minvalue=value(i)
184  min_proc=index(i)
185  if (jj_nb_caldyn(max_proc)>3) then
186  if (timer_iteration(jj_nb_caldyn(min_proc)+1,timer_caldyn,min_proc)<=1 ) then
187  jj_nb_caldyn(min_proc)=jj_nb_caldyn(min_proc)+1
188  jj_nb_caldyn(max_proc)=jj_nb_caldyn(max_proc)-1
189  exit
190  else
191  if (timer_average(jj_nb_caldyn(min_proc)+1,timer_caldyn,min_proc) &
192  -timer_delta(jj_nb_caldyn(min_proc)+1,timer_caldyn,min_proc) < maxvalue) then
193  jj_nb_caldyn(min_proc)=jj_nb_caldyn(min_proc)+1
194  jj_nb_caldyn(max_proc)=jj_nb_caldyn(max_proc)-1
195  exit
196  endif
197  endif
198  endif
199  enddo
200 
201  deallocate(value)
202  deallocate(index)
203 
204  end subroutine adjustbands_caldyn
205 
206  subroutine adjustbands_vanleer
207  use times
208  USE parallel_lmdz
209  implicit none
210 
211  real :: minvalue,maxvalue
212  integer :: min_proc,max_proc
213  integer :: i,j
214  real,allocatable,dimension(:) :: value
215  integer,allocatable,dimension(:) :: index
216  real :: tmpvalue
217  integer :: tmpindex
218 
219  allocate(value(0:mpi_size-1))
220  allocate(index(0:mpi_size-1))
221 
222 
224 
225  do i=0,mpi_size-1
227  index(i)=i
228  enddo
229 
230  do i=0,mpi_size-2
231  do j=i+1,mpi_size-1
232  if (value(i)>value(j)) then
233  tmpvalue=value(i)
234  value(i)=value(j)
235  value(j)=tmpvalue
236 
237  tmpindex=index(i)
238  index(i)=index(j)
239  index(j)=tmpindex
240  endif
241  enddo
242  enddo
243 
244  maxvalue=value(mpi_size-1)
245  max_proc=index(mpi_size-1)
246 
247  do i=0,mpi_size-2
248  minvalue=value(i)
249  min_proc=index(i)
250 
251  if (jj_nb_vanleer(max_proc)>3) then
252  if (timer_average(jj_nb_vanleer(min_proc)+1,timer_vanleer,min_proc)==0. .or. &
253  timer_average(jj_nb_vanleer(max_proc)-1,timer_vanleer,max_proc)==0.) then
254  jj_nb_vanleer(min_proc)=jj_nb_vanleer(min_proc)+1
255  jj_nb_vanleer(max_proc)=jj_nb_vanleer(max_proc)-1
256  exit
257  else
258  if (timer_average(jj_nb_vanleer(min_proc)+1,timer_vanleer,min_proc) < maxvalue) then
259  jj_nb_vanleer(min_proc)=jj_nb_vanleer(min_proc)+1
260  jj_nb_vanleer(max_proc)=jj_nb_vanleer(max_proc)-1
261  exit
262  endif
263  endif
264  endif
265  enddo
266 
267  deallocate(value)
268  deallocate(index)
269 
270  end subroutine adjustbands_vanleer
271 
272  subroutine adjustbands_dissip
273  use times
274  USE parallel_lmdz
275  implicit none
276 
277  real :: minvalue,maxvalue
278  integer :: min_proc,max_proc
279  integer :: i,j
280  real,allocatable,dimension(:) :: value
281  integer,allocatable,dimension(:) :: index
282  real :: tmpvalue
283  integer :: tmpindex
284 
285  allocate(value(0:mpi_size-1))
286  allocate(index(0:mpi_size-1))
287 
288 
290 
291  do i=0,mpi_size-1
293  index(i)=i
294  enddo
295 
296  do i=0,mpi_size-2
297  do j=i+1,mpi_size-1
298  if (value(i)>value(j)) then
299  tmpvalue=value(i)
300  value(i)=value(j)
301  value(j)=tmpvalue
302 
303  tmpindex=index(i)
304  index(i)=index(j)
305  index(j)=tmpindex
306  endif
307  enddo
308  enddo
309 
310  maxvalue=value(mpi_size-1)
311  max_proc=index(mpi_size-1)
312 
313  do i=0,mpi_size-2
314  minvalue=value(i)
315  min_proc=index(i)
316 
317  if (jj_nb_dissip(max_proc)>3) then
318  if (timer_iteration(jj_nb_dissip(min_proc)+1,timer_dissip,min_proc)<=1) then
319  jj_nb_dissip(min_proc)=jj_nb_dissip(min_proc)+1
320  jj_nb_dissip(max_proc)=jj_nb_dissip(max_proc)-1
321  exit
322  else
323  if (timer_average(jj_nb_dissip(min_proc)+1,timer_dissip,min_proc) &
324  - timer_delta(jj_nb_dissip(min_proc)+1,timer_dissip,min_proc) < maxvalue) then
325  jj_nb_dissip(min_proc)=jj_nb_dissip(min_proc)+1
326  jj_nb_dissip(max_proc)=jj_nb_dissip(max_proc)-1
327  exit
328  endif
329  endif
330  endif
331  enddo
332 
333  deallocate(value)
334  deallocate(index)
335 
336  end subroutine adjustbands_dissip
337 
338  subroutine adjustbands_physic
339  use times
340 #ifdef CPP_PHYS
341 ! Ehouarn: what follows is only related to // physics
342  USE mod_phys_lmdz_para, only : klon_mpi_para_nb
343 #endif
344  USE parallel_lmdz
345  implicit none
346 
347  integer :: i,Index
348  real,allocatable,dimension(:) :: value
349  integer,allocatable,dimension(:) :: Inc
350  real :: medium
351  integer :: NbTot,sgn
352 
353  allocate(value(0:mpi_size-1))
354  allocate(inc(0:mpi_size-1))
355 
356 
358 
359  medium=0
360  do i=0,mpi_size-1
362  medium=medium+value(i)
363  enddo
364 
365  medium=medium/mpi_size
366  nbtot=0
367 #ifdef CPP_PHYS
368  do i=0,mpi_size-1
369  inc(i)=nint(klon_mpi_para_nb(i)*(medium-value(i))/value(i))
370  nbtot=nbtot+inc(i)
371  enddo
372 
373  if (nbtot>=0) then
374  sgn=1
375  else
376  sgn=-1
377  nbtot=-nbtot
378  endif
379 
380  index=0
381  do i=1,nbtot
382  inc(index)=inc(index)-sgn
383  index=index+1
384  if (index>mpi_size-1) index=0
385  enddo
386 
387  do i=0,mpi_size-1
388  distrib_phys(i)=klon_mpi_para_nb(i)+inc(i)
389  enddo
390 #endif
391  end subroutine adjustbands_physic
392 
393  subroutine writebands
394  USE parallel_lmdz
395  implicit none
396  include "dimensions.h"
397 
398  integer :: i,j
399  character (len=4) :: siim,sjjm,sllm,sproc
400  character (len=255) :: filename
401  integer :: unit_number=10
402  integer :: ierr
403 
404  write(siim,'(i3)') iim
405  write(sjjm,'(i3)') jjm
406  write(sllm,'(i3)') llm
407  write(sproc,'(i3)') mpi_size
408 
409  filename='Bands_'//trim(adjustl(siim))//'x'//trim(adjustl(sjjm))//'x'//trim(adjustl(sllm))//'_' &
410  //trim(adjustl(sproc))//'prc.dat'
411 
412  OPEN(unit=unit_number,file=trim(filename),status='replace',form='formatted',iostat=ierr)
413 
414  if (ierr==0) then
415 
416 ! write (unit_number,*) '*** Bandes caldyn ***'
417  do i=0,mpi_size-1
418  write (unit_number,*) i,jj_nb_caldyn(i)
419  enddo
420 
421 ! write (unit_number,*) '*** Bandes vanleer ***'
422  do i=0,mpi_size-1
423  write (unit_number,*) i,jj_nb_vanleer(i)
424  enddo
425 
426 ! write (unit_number,*) '*** Bandes dissip ***'
427  do i=0,mpi_size-1
428  write (unit_number,*) i,jj_nb_dissip(i)
429  enddo
430 
431  do i=0,mpi_size-1
432  write (unit_number,*) i,distrib_phys(i)
433  enddo
434 
435  CLOSE(unit_number)
436  else
437  print *,'probleme lors de l ecriture des bandes'
438  endif
439 
440  end subroutine writebands
441 
442  end module bands
443 
444 
Definition: bands.F90:4
integer, dimension(:), allocatable distrib_phys
Definition: bands.F90:24
integer, parameter timer_physic
Definition: times.F90:10
integer, dimension(:), allocatable jj_nb_caldyn
Definition: bands.F90:10
subroutine adjustbands_dissip(new_dist)
Definition: bands.F90:313
subroutine writebands
Definition: bands.F90:438
integer, save mpi_size
real, dimension(:,:,:), allocatable timer_average
Definition: times.F90:19
!$Id Turb_fcg_gcssold get_uvd hqturb_gcssold endif!large scale llm day day1 day day1 *dt_toga endif!time annee_ref dt_toga u_toga vq_toga w_prof vq_prof llm day day1 day day1 *dt_dice endif!time annee_ref dt_dice swup_dice vg_dice omega_dice tg_prof vg_profd w_profd omega_profd!do llm!print llm l llm
integer, dimension(:), allocatable jj_nb_dissip
Definition: bands.F90:13
integer, parameter timer_caldyn
Definition: times.F90:7
!$Id klon initialisation mois suivants day_rain itap ENDIF!Calcul fin de nday_rain calcul nday_rain itap DO i
Definition: calcul_divers.h:24
subroutine allgather_timer_average
Definition: times.F90:173
integer, dimension(:,:,:), allocatable timer_iteration
Definition: times.F90:18
integer, parameter timer_dissip
Definition: times.F90:9
!$Id klon klev DO klon!IM klev DO klon klon nbp_lat DO nbp_lon ij
real, dimension(:,:,:), allocatable timer_delta
Definition: times.F90:20
integer, dimension(:), allocatable jj_nb_physic
Definition: bands.F90:14
!$Id Turb_fcg!implicit none!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc!cette routine permet d obtenir hq et ainsi de!pouvoir calculer la convergence et le cisaillement dans la physiq!cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc INTEGER klev REAL j
Definition: 1Dconv.h:27
subroutine adjustbands_vanleer(new_dist)
Definition: bands.F90:244
Definition: times.F90:1
subroutine allocatebands
Definition: bands.F90:29
integer, dimension(:), allocatable jj_nb_vanleer2
Definition: bands.F90:12
subroutine set_bands
Definition: bands.F90:106
integer, parameter bands_vanleer
Definition: bands.F90:7
c c zjulian c cym CALL iim cym klev iim
Definition: ini_bilKP_ave.h:24
integer, dimension(:), allocatable jj_nb_physic_bis
Definition: bands.F90:15
subroutine adjustbands_caldyn(new_dist)
Definition: bands.F90:177
integer, parameter bands_dissip
Definition: bands.F90:8
subroutine read_distrib
Definition: bands.F90:43
integer, parameter timer_vanleer
Definition: times.F90:8
integer, dimension(:), allocatable jj_nb_vanleer
Definition: bands.F90:11
integer, parameter bands_caldyn
Definition: bands.F90:6
!$Header!integer nvarmx s s unit
Definition: gradsdef.h:20
subroutine adjustbands_physic
Definition: bands.F90:382