Changeset 1228ef7 in flexpart.git for src/partoutput_short_mpi.f90


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG