source: flexpart.git/src/partoutput_short_mpi.f90 @ 1228ef7

dev
Last change on this file since 1228ef7 was 1228ef7, checked in by Espen Sollum <eso@…>, 3 years ago

MPI: fix for mquasilag output

  • Property mode set to 100644
File size: 5.7 KB
Line 
1! SPDX-FileCopyrightText: FLEXPART 1998-2019, see flexpart_license.txt
2! SPDX-License-Identifier: GPL-3.0-or-later
3
4subroutine partoutput_short(itime)
5  !                              i
6  !*****************************************************************************
7  !                                                                            *
8  !     Dump all particle positions                                            *
9  !                                                                            *
10  !     Author: A. Stohl                                                       *
11  !                                                                            *
12  !     12 March 1999                                                          *
13  !                                                                            *
14  !     12/2014 eso: Version for MPI                                           *
15  !                  Particle positions are sent to root process for output    *
16  !                                                                            *
17  !*****************************************************************************
18  !                                                                            *
19  ! Variables:                                                                 *
20  !                                                                            *
21  !*****************************************************************************
22
23  use par_mod
24  use com_mod
25  use mpi_mod
26
27  implicit none
28
29  real(kind=dp) :: jul
30  integer, dimension(:), allocatable :: numshorts,displs
31  integer :: itime,i,j,jjjjmmdd,ihmmss,numshortout,numshortall,numshortmpi
32  integer :: ix,jy,ixp,jyp
33  real :: xlon,ylat,zlim,dt1,dt2,dtt,ddx,ddy,rddx,rddy,p1,p2,p3,p4,topo
34  character :: adate*8,atime*6
35
36  integer(kind=2) :: idump(3,maxpart)
37  integer :: i4dump(maxpart)
38  integer(kind=2),dimension(:,:),allocatable :: idump_all(:,:)
39  integer,dimension(:), allocatable :: i4dump_all(:)
40!  character(LEN=8) :: file_stat='OLD'
41  character(LEN=8) :: file_stat='REPLACE'
42
43! This is not needed, in this version only root process writes the file
44  ! if (lroot) then
45  !   file_stat='REPLACE'
46  ! end if
47
48! Array to gather numshortout from all processes
49  allocate(numshorts(mp_partgroup_np), displs(mp_partgroup_np))
50
51  ! Determine current calendar date, needed for the file name
52  !**********************************************************
53
54  jul=bdate+real(itime,kind=dp)/86400._dp
55  call caldate(jul,jjjjmmdd,ihmmss)
56  write(adate,'(i8.8)') jjjjmmdd
57  write(atime,'(i6.6)') ihmmss
58
59
60  ! Some variables needed for temporal interpolation
61  !*************************************************
62
63  dt1=real(itime-memtime(1))
64  dt2=real(memtime(2)-itime)
65  dtt=1./(dt1+dt2)
66
67
68  ! Loop about all particles
69  !*************************
70
71  numshortout=0
72  numshortall=0
73  do i=1,numpart
74
75  ! Take only valid particles
76  !**************************
77
78    if (itra1(i).eq.itime) then
79      xlon=xlon0+xtra1(i)*dx
80      ylat=ylat0+ytra1(i)*dy
81
82  !*****************************************************************************
83  ! Interpolate several variables (PV, specific humidity, etc.) to particle position
84  !*****************************************************************************
85
86      ix=xtra1(i)
87      jy=ytra1(i)
88      ixp=ix+1
89      jyp=jy+1
90      ddx=xtra1(i)-real(ix)
91      ddy=ytra1(i)-real(jy)
92      rddx=1.-ddx
93      rddy=1.-ddy
94      p1=rddx*rddy
95      p2=ddx*rddy
96      p3=rddx*ddy
97      p4=ddx*ddy
98
99  ! Topography
100  !***********
101
102      topo=p1*oro(ix ,jy) &
103           + p2*oro(ixp,jy) &
104           + p3*oro(ix ,jyp) &
105           + p4*oro(ixp,jyp)
106
107
108  ! Convert positions to integer*2 variables (from -32768 to 32767)
109  ! Do this only for region of main interest, i.e. extended North Atlantic region,
110  ! and for the tracer of interest, i.e. the North American one
111  !*****************************************************************************
112
113      if (xlon.gt.180.) xlon=xlon-360.
114      if (xlon.lt.-180.) xlon=xlon+360.
115
116      numshortall=numshortall+1
117      if ((xlon.gt.-140).and.(xlon.lt.60).and.(ylat.gt.10).and. &
118           (xmass1(i,1).gt.0.)) then
119        numshortout=numshortout+1
120        idump(1,numshortout)=nint(xlon*180.)
121        idump(2,numshortout)=nint(ylat*360.)
122        zlim=min(ztra1(i)+topo,32766.)
123        idump(3,numshortout)=nint(zlim)
124        i4dump(numshortout)=npoint(i)
125      endif
126    endif
127  end do
128
129
130 
131! Get total number of particles from all processes
132!************************************************
133  call MPI_Allgather(numshortout, 1, MPI_INTEGER, numshorts, 1, MPI_INTEGER, &
134       mp_comm_used, mp_ierr)
135 
136  numshortmpi = sum(numshorts(:))
137
138
139! Gather all data at root process
140!********************************
141  allocate(idump_all(3,numshortmpi), i4dump_all(numshortmpi))
142  displs(1)=0
143  do i=2,mp_partgroup_np
144    displs(i)=displs(i-1)+numshorts(i-1)
145  end do
146
147  call MPI_gatherv(i4dump, numshortout, MPI_INTEGER, i4dump_all, numshorts(:), &
148       & displs, MPI_INTEGER, id_root, mp_comm_used, mp_ierr)
149  displs = displs*3 
150  call MPI_gatherv(idump, 3*numshortout, MPI_INTEGER2, idump_all, 3*numshorts(:), &
151       & displs, MPI_INTEGER2, id_root, mp_comm_used, mp_ierr)
152 
153  ! Open output file and write the output
154  !**************************************
155
156  if (lroot) then ! MPI root process only
157    open(unitshortpart,file=path(2)(1:length(2))//'shortposit_'//adate// &
158         atime,form='unformatted',status=file_stat,position='append')
159    write(unitshortpart) itime
160    write(unitshortpart) numshortmpi
161    write(unitshortpart) &
162           (i4dump_all(i),(idump_all(j,i),j=1,3),i=1,numshortmpi)
163    close(unitshortpart)
164  end if
165
166  deallocate(idump_all, i4dump_all)
167
168end subroutine partoutput_short
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG