D.6.1 Initialize_Distributed_Vector Procedure

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

  subroutine Initialize_Distributed_Vector (DV, Structure, Dimensionality, &
                                            Name, status, dim1, dim2, dim3)

    ! Use associations.

    use Caesar_Flags_Module, only: initialized_flag

    ! Input variables.

    type(Base_Structure_type), target :: Structure            ! Base structure.
    type(character,*), intent(in), optional :: Name           ! Variable name.
    type(integer), intent(in) :: Dimensionality   ! Dimensionality for this DV.
    type(integer), intent(in), optional :: dim1, dim2, dim3   ! Dimensions.

    ! Output variables.

    ! Distributed_Vector to be initialized.
    type(Distributed_Vector_type), intent(out) :: DV 
    type(Status_type), intent(out), optional :: status  ! Exit status.

    ! Internal variables.

    type(Status_type), dimension(3) :: allocate_status ! Allocation Status.
    type(Status_type) :: consolidated_status           ! Consolidated Status.
    type(integer) :: NSlice              ! Number of values that are on one 
                                         ! slice, given by a constant location
                                         ! on the distributed axis.

    !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    ! Verify requirements.

    VERIFY(Valid_State(Structure),5)              ! Structure is valid.
    VERIFY(Dimensionality .InInterval. (/1,4/),5) ! Dimensionality is in range.
    VERIFY(PRESENT(dim1) .or. Dimensionality == 1,5) ! Proper dimensions exist.
    VERIFY(PRESENT(dim2) .or. Dimensionality <= 2,5) ! Proper dimensions exist.
    VERIFY(PRESENT(dim3) .or. Dimensionality <= 3,5) ! Proper dimensions exist.

    ! Set up structure pointer.

    DV%Structure => Structure

    ! Allocations and initializations.

    call Initialize (allocate_status)
    call Initialize (consolidated_status)

    call Initialize (DV%NValues_Vector, NPEs, allocate_status(1))

    ! Set to maximum dimensionality of 4 to enable VERIFYs without if-checks.
    ! Also, this gets around problems with using the dimensionality when it
    ! is set to a negative number for a ragged right array.
    call Initialize (DV%Dimensions, 4, allocate_status(2)) 
    DV%Dimensions(Dimensionality) = Length_PE(Structure)

    select case (Dimensionality)
    case (1)
      call Initialize (DV%Values1, Length_PE(Structure), allocate_status(3))
    case (2)
      call Initialize (DV%Values2, dim1, Length_PE(Structure), &
                       allocate_status(3))
      DV%Dimensions(1) = dim1
    case (3)
      call Initialize (DV%Values3, dim1, dim2, Length_PE(Structure), &
                       allocate_status(3))
      DV%Dimensions(1) = dim1
      DV%Dimensions(2) = dim2
    case (4)
      call Initialize (DV%Values4, dim1, dim2, dim3, Length_PE(Structure), &
                       allocate_status(3))
      DV%Dimensions(1) = dim1
      DV%Dimensions(2) = dim2
      DV%Dimensions(3) = dim3
    !case (-1)
    !  call Initialize (DV%ValuesRR, Length_PE(Structure), &
    !                   allocate_status)
    !  DV%NValues_Total = F(Length_Total(Structure))
    end select
    NSlice = PRODUCT(DV%Dimensions(1:Dimensionality-1))

    ! Set NValues numbers. (This won't work for Ragged Right arrays --
    ! where the number of values is a function of the length axis.)

    DV%NValues_Total  = NSlice * Length_Total(Structure)
    DV%NValues_PE     = NSlice * Length_PE(Structure)
    DV%NValues_Vector = NSlice * Length_Vector(Structure)

    consolidated_status = allocate_status
    if (PRESENT(status)) then
      WARN_IF(Error(consolidated_status), 5)
      status = consolidated_status
    else
      VERIFY(Normal(consolidated_status), 5)
    end if
    call Finalize (consolidated_status)
    call Finalize (allocate_status)

    ! Set up internals.

    if (PRESENT(Name)) DV%Name = Name
    DV%Dimensionality = Dimensionality
    DV%Version = 0

    ! Set initialization flag.

    DV%Initialized = initialized_flag

    ! Verify guarantees.

    VERIFY(Valid_State(DV),5)  ! DV is now valid.

    return
  end subroutine Initialize_Distributed_Vector



Michael L. Hall