TNO Intern

Commit 4baf02a9 authored by Arjo Segers's avatar Arjo Segers
Browse files

Fixed simulation on parallel domains.

parent 50ff87ef
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -191,6 +191,7 @@ EOF
#! /bin/bash

#SBATCH --job-name=${jbname}
#SBATCH --account=emep
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=${NPE}
#SBATCH --time=01:00:00
+45 −21
Original line number Diff line number Diff line
@@ -189,8 +189,9 @@ program Tutorial_Oper_Simulate
  ! init MPI interface:
  call MPI_Init( ierror=status )
  if ( status /= MPI_SUCCESS ) then
    errorcode=status; call MPI_Error_String( errorcode, errormsg, errorlen, status ); write (logfu,'(a)') trim(errormsg)
    write (logfu,'("could not initialize MPI environment; exit code : ",i6)') status
    errorcode=status; call MPI_Error_String( errorcode, errormsg, errorlen, status )
    write (logfu,'("ERROR - ",a)') trim(errormsg)
    write (logfu,'("ERROR - could not initialize MPI environment; exit code : ",i6)') status
    TRACEBACK; status=1; call Exit(status)
  end if
  ! use global communicator:
@@ -198,12 +199,14 @@ program Tutorial_Oper_Simulate
  ! size and rank:
  call MPI_Comm_Size( comm, npes, ierror=status )
  if ( status /= MPI_SUCCESS ) then
    errorcode=status; call MPI_Error_String( errorcode, errormsg, errorlen, status ); write (logfu,'(a)') trim(errormsg)
    errorcode=status; call MPI_Error_String( errorcode, errormsg, errorlen, status )
    write (logfu,'("ERROR - ",a)') trim(errormsg)
    TRACEBACK; status=1; call Exit(status)
  end if
  call MPI_Comm_Rank( comm, id, ierror=status )
  if ( status /= MPI_SUCCESS ) then
    errorcode=status; call MPI_Error_String( errorcode, errormsg, errorlen, status ); write (logfu,'(a)') trim(errormsg)
    errorcode=status; call MPI_Error_String( errorcode, errormsg, errorlen, status )
    write (logfu,'("ERROR - ",a)') trim(errormsg)
    TRACEBACK; status=1; call Exit(status)
  end if

@@ -220,9 +223,9 @@ program Tutorial_Oper_Simulate
  ! open:
  open( unit=logfu, file=trim(logfile), status='replace', iostat=status )
  if ( status/=0 ) then
    write (*,'("opening log file for output:")')
    write (*,'("  unit : ",i6)') logfu
    write (*,'("  file : ",a)') trim(logfile)
    write (*,'("ERROR - opening log file for output:")')
    write (*,'("ERROR -   unit : ",i6)') logfu
    write (*,'("ERROR -   file : ",a)') trim(logfile)
    TRACEBACK; status=1; call Exit(status)
  end if
  ! also write CSO messages to this unit:
@@ -254,9 +257,9 @@ program Tutorial_Oper_Simulate
  !! open:
  !open( unit=logfu, file=trim(logfile), status='replace', iostat=status )
  !if ( status/=0 ) then
  !  write (*,'("opening log file for output:")')
  !  write (*,'("  unit : ",i6)') logfu
  !  write (*,'("  file : ",a)') trim(logfile)
  !  write (*,'("ERROR - opening log file for output:")')
  !  write (*,'("ERROR -   unit : ",i6)') logfu
  !  write (*,'("ERROR -   file : ",a)') trim(logfile)
  !  TRACEBACK; status=1; call Exit(status)
  !end if
  !! also write CSO messages to this unit:
@@ -344,7 +347,7 @@ program Tutorial_Oper_Simulate
      ndomx = 2
      ndomy = 2
    case default
      write (logfu,'(a,": unsupported number of domains ",i0)') npes
      write (logfu,'("ERROR - unsupported number of domains ",i0)') npes
      TRACEBACK; status=1; call Exit(status)
  end select
  ! info ...
@@ -546,8 +549,9 @@ program Tutorial_Oper_Simulate

          ! info ...
          write (logfu,'(a,":   store ...")') rname
          ! store mapping weights, might be saved and used to create gridded averages;
          ! cell indices ii/jj need to be the global index numbers!
          ! store mapping weights, will be used later to fill target arrays;
          ! for ii/jj, store the global index numbers to ensure that pixels overlapping
          ! more domains are handled correctly!
          call sdata%SetMapping( areas, nw, dom_ilon0+ii, dom_ilat0+jj, ww, status )
          IF_NOT_OK_RETURN(status=1)

@@ -598,7 +602,7 @@ program Tutorial_Oper_Simulate
              IF_NOT_OK_RETURN(status=1)
            !~ unknown ...
            case default
              write (logfu,'("unsupported dimension `",a,"`")') trim(udimname)
              write (logfu,'("ERROR - unsupported dimension `",a,"`")') trim(udimname)
              TRACEBACK; status=1; call Exit(status)
          end select
        end do ! idim
@@ -665,7 +669,7 @@ program Tutorial_Oper_Simulate
                      vfac = 1.0e-3
                    !
                    case default
                      write (logfu,'("unsupported conversion `",a,"` for variable `",a,"`")') &
                      write (logfu,'("ERROR - unsupported conversion `",a,"` for variable `",a,"`")') &
                                         trim(conversion), trim(uvarnames(iuvar))
                     TRACEBACK; status=1; call Exit(status)
                  end select
@@ -686,8 +690,19 @@ program Tutorial_Oper_Simulate
                    data1(:,ipix) = 0.0
                    ! loop over source contributions:
                    do iw = iw0(ipix)+1, iw0(ipix)+nw(ipix)
                      ! local indices:
                      ilon = ii(iw) - dom_ilon0
                      ilat = jj(iw) - dom_ilat0
                      !! TESTING ...
                      !if ( (ilon < 1) .or. (ilon > size(conc,1)) .or. (ilat < 1) .or. (ilat > size(conc,2)) ) then
                      !  write (logfu,'("ERROR - soure cell (",i0,",",i0,") outside local domain (1:",i0,",1:",i0,")")') &
                      !           ilon, ilat, size(conc,1), size(conc,2)
                      !  write (logfu,'("ERROR -   pixel  : ",i0)') ipix
                      !  write (logfu,'("ERROR -   weight : ",i0,es16.8)') iw, ww(iw)
                      !  TRACEBACK; status=1; call Exit(status)
                      !end if
                      ! add contribution:
                      data1(:,ipix) = data1(:,ipix) + conc(ii(iw),jj(iw),:) * vfac * ww(iw)/areas(ipix)
                      data1(:,ipix) = data1(:,ipix) + conc(ilon,ilat,:) * vfac * ww(iw)/areas(ipix)
                    end do ! iw
                  end if ! nw > 0
                end do ! itsel
@@ -713,8 +728,11 @@ program Tutorial_Oper_Simulate
                    data1(:,ipix) = 0.0
                    ! loop over source contributions:
                    do iw = iw0(ipix)+1, iw0(ipix)+nw(ipix)
                      ! local indices:
                      ilon = ii(iw) - dom_ilon0
                      ilat = jj(iw) - dom_ilat0
                      ! add contribution:
                      data1(:,ipix) = data1(:,ipix) + hp(ii(iw),jj(iw),:) * ww(iw)/areas(ipix)
                      data1(:,ipix) = data1(:,ipix) + hp(ilon,ilat,:) * ww(iw)/areas(ipix)
                    end do ! iw
                  end if ! nw > 0
                end do ! itsel
@@ -740,8 +758,11 @@ program Tutorial_Oper_Simulate
                    data0(ipix) = 0.0
                    ! loop over source contributions:
                    do iw = iw0(ipix)+1, iw0(ipix)+nw(ipix)
                      ! local indices:
                      ilon = ii(iw) - dom_ilon0
                      ilat = jj(iw) - dom_ilat0
                      ! add contribution:
                      data0(ipix) = data0(ipix) + tcc(ii(iw),jj(iw)) * ww(iw)/areas(ipix)
                      data0(ipix) = data0(ipix) + tcc(ilon,ilat) * ww(iw)/areas(ipix)
                    end do ! iw
                  end if ! nw > 0
                end do ! itsel
@@ -767,15 +788,18 @@ program Tutorial_Oper_Simulate
                    data1(:,ipix) = 0.0
                    ! loop over source contributions:
                    do iw = iw0(ipix)+1, iw0(ipix)+nw(ipix)
                      ! local indices:
                      ilon = ii(iw) - dom_ilon0
                      ilat = jj(iw) - dom_ilat0
                      ! add contribution:
                      data1(:,ipix) = data1(:,ipix) + cc(ii(iw),jj(iw),:) * ww(iw)/areas(ipix)
                      data1(:,ipix) = data1(:,ipix) + cc(ilon,ilat,:) * ww(iw)/areas(ipix)
                    end do ! iw
                  end if ! nw > 0
                end do ! itsel

              !~
              case default
                write (logfu,'("unsupported variable name `",a,"`")') trim(uvarnames(iuvar))
                write (logfu,'("ERROR - unsupported variable name `",a,"`")') trim(uvarnames(iuvar))
                TRACEBACK; status=1; call Exit(status)
            end select

@@ -854,7 +878,7 @@ program Tutorial_Oper_Simulate
  ! done with MPI interface:
  call MPI_Finalize( ierror=status )
  if ( status /= MPI_SUCCESS ) then
    write (logfu,'("could not finalize MPI environment; exit code : ",i6)') status
    write (logfu,'("ERROR - could not finalize MPI environment; exit code : ",i6)') status
    TRACEBACK; status=1; call Exit(status)
  end if
#endif