test_Reduce_max Subroutine

public subroutine test_Reduce_max()

Arguments

None

Source Code

      subroutine test_Reduce_max

      ! Tolerance for floating point equality tests
      real(ESMF_KIND_R4), parameter :: fuzz4 = 0.0
      real(ESMF_KIND_R8), parameter :: fuzz8 = 0.0d0

      logical :: passflg

! This subroutine tests all the overloaded versions of the ESMF global sum.

      ! Test with integer arguments
      !=============================
      !EX_UTest
      array4 = (/50,50/)
      ! Set expected results
      if (npets == 1) then
        array5 = (/1,2/)
      else
        array5 = (/301,302/)
      end if
      write(failMsg, *) "Did not return ESMF_SUCCESS"
      write(name, *) "VM Reduce ESMF_REDUCE_MAXTest: integer"
      call ESMF_VMReduce(vm, sendData=array1, recvData=array4, &
        count=nsize, reduceflag=ESMF_REDUCE_MAX, rootPet=rootPet, rc=rc)
      call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE)

      ! print the result
      print *, 'Global max:' 
      print *, localPet,' array4(1): ', array4(1), &
                        ' array4(2):', array4(2) 

      print *, localPet,' array1(1): ', array1(1), &
                        ' array1(2):', array1(2) 
      !------------------------------------------------------------------------
      !EX_UTest
      write(failMsg, *) "Returned wrong results"
      write(name, *) "Verify Reduce ESMF_REDUCE_MAXResults Test: integer"
      if (localPet == rootPet) then
        passflg = array4(1)==array5(1) .and. array4(2)==array5(2)
      else
        passflg = .true.  ! Values are undefined after MPI_Reduce
      end if
      call ESMF_Test(passflg, name, failMsg, result, ESMF_SRCLINE)
      !------------------------------------------------------------------------

      !Test with ESMF_KIND_R8 arguments
      !=================================
      !EX_UTest
      farray4 = (/50.0,50.0/)
      ! Set expected results
      if (npets == 1) then
        farray5 = (/1.0,2.0/)
      else
        farray5 = (/301.0,302.0/)
      end if
      write(failMsg, *) "Did not return ESMF_SUCCESS"
      write(name, *) "VM Reduce ESMF_REDUCE_MAXTest: ESMF_KIND_R8"
      call ESMF_VMReduce(vm, sendData=farray1, recvData=farray4, &
        count=nsize, reduceflag=ESMF_REDUCE_MAX, rootPet=rootPet, rc=rc)
      call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE)

      ! print the result
      print *, 'Global max:'
      print *, localPet,' farray4(1): ', farray4(1), &
                        ' farray4(2):', farray4(2)

       print *, localPet,' farray1(1): ', farray1(1), &
                        ' farray1(2):', farray1(2)


      !------------------------------------------------------------------------
      !EX_UTest
      write(failMsg, *) "Returned wrong results"
      write(name, *) "Verify Reduce ESMF_REDUCE_MAXResults Test: ESMF_KIND_R8"
      if (localPet == rootPet) then
        passflg = abs (farray4(1)-farray5(1)) <= fuzz8 .and. abs (farray4(2)-farray5(2)) <= fuzz8
      else
        passflg = .true.  ! Values on non-root PETs are undefined after MPI_Reduce
      end if
      call ESMF_Test(passflg, name, failMsg, result, ESMF_SRCLINE)

      !------------------------------------------------------------------------

      !Test with ESMF_KIND_R4 arguments
      !=================================
      !EX_UTest
      f4array4 = (/50.0,50.0/)
      ! Set expected results
      if (npets == 1) then
        f4array5 = (/1.0,2.0/)
      else
        f4array5 = (/301.0,302.0/)
      end if

      write(failMsg, *) "Did not return ESMF_SUCCESS"
      write(name, *) "VM Reduce ESMF_REDUCE_MAXTest: ESMF_KIND_R4"
      call ESMF_VMReduce(vm, sendData=f4array1, recvData=f4array4, &
        count=nsize, reduceflag=ESMF_REDUCE_MAX, rootPet=rootPet, rc=rc)
      call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE)

      ! print the result
      print *, 'Global max:'
      print *, localPet,' f4array4(1): ', f4array4(1), &
                        ' f4array4(2):', f4array4(2)

       print *, localPet,' f4array1(1): ', f4array1(1), &
                        ' f4array1(2):', f4array1(2)



      !------------------------------------------------------------------------
      !EX_UTest
      write(failMsg, *) "Returned wrong results"
      write(name, *) "Verify Reduce ESMF_REDUCE_MAXResults Test: ESMF_KIND_R4"
      if (localPet == rootPet) then
        passflg = abs (f4array4(1)-f4array5(1)) <= fuzz4 .and. abs (f4array4(2)-f4array5(2)) <= fuzz4
      else
        passflg = .true.  ! Values are undefined after MPI_Reduce
      end if
      call ESMF_Test(passflg, name, failMsg, result, ESMF_SRCLINE)

      !------------------------------------------------------------------------


      end subroutine test_Reduce_max