Changeset 1228ef7 in flexpart.git


Ignore:
Timestamp:
Aug 2, 2021, 12:11:23 PM (3 years ago)
Author:
Espen Sollum <eso@…>
Branches:
dev
Parents:
6cb0801
Message:

MPI: fix for mquasilag output

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/makefile

    r71f2128 r1228ef7  
    9090## OPTIMIZATION LEVEL
    9191O_LEV = 2 # [0,1,2,3,g,s,fast]
    92 O_LEV_DBG = g # [0,g]
     92O_LEV_DBG = 0 # [0,g]
    9393
    9494## LIBRARIES
     
    100100
    101101LDFLAGS  = $(FFLAGS) -L$(LIBPATH1) -Wl,-rpath,$(LIBPATH1) $(LIBS) #-L$(LIBPATH2)
    102 LDDEBUG  = $(DBGFLAGS) -L$(LIBPATH1) $(LIBS) #-L$(LIBPATH2)
     102LDDEBUG  = $(DBGFLAGS) -L$(LIBPATH1) -Wl,-rpath,$(LIBPATH1) $(LIBS) #-L$(LIBPATH2)
    103103
    104104MODOBJS = \
  • src/mpi_mod.f90

    ra803521 r1228ef7  
    178178    implicit none
    179179
    180     integer :: i,j,s,addmaxpart=0
     180    integer :: i,j,s
    181181
    182182! Each process gets an ID (mp_pid) in the range 0,..,mp_np-1
     
    486486
    487487    integer,intent(in) :: num_part
    488     integer :: i,jj, addone
     488    integer :: i
    489489
    490490! Exit if too many particles
     
    589589    integer, intent(in) :: itime
    590590    real :: pmin,z
    591     integer :: i,jj,nn, num_part=1,m,imin, num_trans
    592     logical :: first_iter
     591    integer :: i,jj,nn,m,imin, num_trans
    593592    integer,allocatable,dimension(:) :: idx_arr
    594593    real,allocatable,dimension(:) :: sorted ! TODO: we don't really need this
     
    613612    end do
    614613
    615 ! Do not rebalance particles for ipout=3    
    616     if (ipout.eq.3) return
     614! Do not rebalance particles for ipout=3 or mquasilag=1
     615    if ((ipout.eq.3).or.(mquasilag.eq.1)) return
    617616
    618617! For each successive element in index array, see if a lower value exists
  • src/partoutput_short_mpi.f90

    r92fab65 r1228ef7  
    1313  !                                                                            *
    1414  !     12/2014 eso: Version for MPI                                           *
    15   !                  Processes sequentially access and append data to file     *
    16   !                  NB: Do not use yet!                                       *
     15  !                  Particle positions are sent to root process for output    *
     16  !                                                                            *
    1717  !*****************************************************************************
    1818  !                                                                            *
     
    2828
    2929  real(kind=dp) :: jul
    30   integer :: itime,i,j,jjjjmmdd,ihmmss,numshortout,numshortall
     30  integer, dimension(:), allocatable :: numshorts,displs
     31  integer :: itime,i,j,jjjjmmdd,ihmmss,numshortout,numshortall,numshortmpi
    3132  integer :: ix,jy,ixp,jyp
    3233  real :: xlon,ylat,zlim,dt1,dt2,dtt,ddx,ddy,rddx,rddy,p1,p2,p3,p4,topo
     
    3536  integer(kind=2) :: idump(3,maxpart)
    3637  integer :: i4dump(maxpart)
    37   character(LEN=8) :: file_stat='OLD'
     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'
    3842
    39   ! MPI root process creates the file, other processes append to it
    40   if (lroot) file_stat='REPLACE'
     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))
    4150
    4251  ! Determine current calendar date, needed for the file name
     
    115124        i4dump(numshortout)=npoint(i)
    116125      endif
    117 
    118126    endif
    119127  end do
    120128
    121129
     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 
    122153  ! Open output file and write the output
    123154  !**************************************
    124155
    125   open(unitshortpart,file=path(2)(1:length(2))//'shortposit_'//adate// &
    126        atime,form='unformatted',status=file_stat,position='append')
     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
    127165
    128   ! Write current time to file
    129   !***************************
    130 
    131   if (lroot) write(unitshortpart) itime ! MPI root process only
    132   ! :TODO: get total numshortout (MPI reduction), add MPI barrier, open file
    133   ! sequentially below
    134   write(unitshortpart) numshortout
    135   write(unitshortpart) &
    136        (i4dump(i),(idump(j,i),j=1,3),i=1,numshortout)
    137 
    138 
    139   write(*,*) numshortout,numshortall
    140 
    141   close(unitshortpart)
     166  deallocate(idump_all, i4dump_all)
    142167
    143168end subroutine partoutput_short
  • src/releaseparticles_mpi.f90

    r92fab65 r1228ef7  
    5151  real(kind=dp) :: juldate,julmonday,jul,jullocal,juldiff
    5252  real,parameter :: eps=nxmax/3.e5,eps2=1.e-6
    53   integer :: mind2
     53  integer :: mind2, numpartcount_mpi
    5454! mind2        eso: pointer to 2nd windfield in memory
    55 
    5655  integer :: idummy = -7
    5756!save idummy,xmasssave
     
    6059  logical :: first_call=.true.
    6160
    62 ! Use different seed for each process.
    63 !****************************************************************************
     61! Use different random seed for each process
     62!*******************************************
    6463  if (first_call) then
    6564    idummy=idummy+mp_seed
     
    6867
    6968  mind2=memind(2)
     69
     70! For mquasilag=1, assign unique particle ID across processes
     71  numpartcount_mpi=mp_partid-mp_partgroup_np+1
    7072
    7173! Determine the actual date and time in Greenwich (i.e., UTC + correction for daylight savings time)
     
    210212                 nclassunc)
    211213            numparticlecount=numparticlecount+1
     214! Use a stride equal to number of processes for the MPI version
     215            numpartcount_mpi=numpartcount_mpi+mp_partgroup_np
    212216            if (mquasilag.eq.0) then
    213217              npoint(ipart)=i
    214218            else
    215               npoint(ipart)=numparticlecount
     219              npoint(ipart)=numpartcount_mpi
    216220            endif
    217221            idt(ipart)=mintime               ! first time step
  • src/timemanager_mpi.f90

    rb1f28c3 r1228ef7  
    448448      endif
    449449
    450 ! :TODO: MPI output of particle positions;  each process sequentially
    451 !   access the same file
    452450      if ((mquasilag.eq.1).and.(itime.eq.(loutstart+loutend)/2)) &
    453            call partoutput_short(itime)    ! dump particle positions in extremely compressed format
     451           call partoutput_short(itime) ! dump particle positions in extremely compressed format
    454452
    455453
     
    557555        if ((iout.eq.4).or.(iout.eq.5)) call plumetraj(itime)
    558556        if ((iflux.eq.1).and.(lnetcdfout.eq.0)) call fluxoutput(itime)
     557#ifdef USE_NCF
    559558        if ((iflux.eq.1).and.(lnetcdfout.eq.1)) call fluxoutput_netcdf(itime)
     559#endif
    560560        if (mp_measure_time) call mpif_mtime('iotime',1)
    561561
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG