D.8.7 Gather_and_Collect_CA_from_DV Procedure

The main documentation of the Gather_and_Collect_CA_from_DV Procedure contains additional explanation of this code listing.

  subroutine Gather_and_Collect_CA_from_DV (CA, DV)
  
    ! Input variable.
  
    type(Distributed_Vector_type), intent(in) :: DV     ! DV to be gathered.
  
    ! Input/Output variable.
    
    type(Collected_Array_type), intent(inout) :: CA     ! Gathered vector.
  
    ! Internal variables.

    type(integer) :: i, j, k                            ! Loop counters.

    !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
    ! Verify requirements.
  
    VERIFY(Valid_State(CA),5)                        ! CA is valid.
    VERIFY(Valid_State(DV),5)                        ! DV is valid.
    ! DV, CA -> same Many Structure.
    VERIFY(ASSOCIATED(DV%Structure,CA%Many_Structure),5) 
    ! DV, CA -> same Dimensionality and Dimensions.
    VERIFY(DV%Dimensionality == CA%Dimensionality,5)
    VERIFY(CA%Dimensions(1:CA%Dimensionality-2) == dnl
           DV%Dimensions(1:DV%Dimensionality-2),5)    ! Same dimensions.

    ! Gather the off PE values if they are out-of-date. This could be done
    ! faster for multiple dimensions by packing everything into a single
    ! vector, gathering, and then unpacking. Maybe in a later version.

    if (Version(CA) /= Version(DV)) then

      select case (CA%Many_of_One_Index%Dimensionality)

      ! Vector Index.

      case (1)

        select case (CA%Dimensionality)
        case (1)
          call Gather (CA%Values1, DV%Values1, Trace=CA%Many_of_One_Index%Trace)
        case (2)
          do i = 1, CA%Dimensions(1)
            call Gather (CA%Values2(i,:), DV%Values2(i,:), &
                         Trace=CA%Many_of_One_Index%Trace)
          end do
        case (3)
          do i = 1, CA%Dimensions(1)
            do j = 1, CA%Dimensions(2)
              call Gather (CA%Values3(i,j,:), DV%Values3(i,j,:), &
                           Trace=CA%Many_of_One_Index%Trace)
            end do
          end do
        case (4)
          do i = 1, CA%Dimensions(1)
            do j = 1, CA%Dimensions(2)
              do k = 1, CA%Dimensions(3)
                call Gather (CA%Values4(i,j,k,:), DV%Values4(i,j,k,:), &
                             Trace=CA%Many_of_One_Index%Trace)
              end do
            end do
          end do
        !case (-1)
        !  call Gather (CA%ValuesRR, DV%ValuesRR, &
        !               Trace=CA%Many_of_One_Index%Trace)
        end select

      ! Array Index.

      case (2)

        select case (CA%Dimensionality)
        case (1)
          call Gather (CA%Values2, DV%Values1, Trace=CA%Many_of_One_Index%Trace)
        case (2)
          do i = 1, CA%Dimensions(1)
            call Gather (CA%Values3(i,:,:), DV%Values2(i,:), &
                         Trace=CA%Many_of_One_Index%Trace)
          end do
        case (3)
          do i = 1, CA%Dimensions(1)
            do j = 1, CA%Dimensions(2)
              call Gather (CA%Values4(i,j,:,:), DV%Values3(i,j,:), &
                           Trace=CA%Many_of_One_Index%Trace)
            end do
          end do
        case (4)
          do i = 1, CA%Dimensions(1)
            do j = 1, CA%Dimensions(2)
              do k = 1, CA%Dimensions(3)
                call Gather (CA%Values5(i,j,k,:,:), DV%Values4(i,j,k,:), &
                             Trace=CA%Many_of_One_Index%Trace)
              end do
            end do
          end do
        !case (-1)
        !  call Gather (CA%ValuesRR, DV%ValuesRR, &
        !               Trace=CA%Many_of_One_Index%Trace)
        end select

      end select

    end if

    ! Set version.

    CA = Version(DV)
  
    ! Verify guarantees.

    VERIFY(Valid_State(CA),5)  ! CA is valid.
  
    return
  end subroutine Gather_and_Collect_CA_from_DV



Michael L. Hall