G.3.6 Convert_ELL_to_LAMG Procedure

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

  ifdef([USE_LAMG],[
    subroutine Convert_ELL_to_LAMG (LAMG_Matrix, ELLM, LAMG_Communicator, &
                                    LAMG_Options, status)
  
      ! Use association information.
  
      use Caesar_Numbers_Module, only: zero
      use LAMG_Module
  
      ! Input variables.
  
      type(ELL_Matrix_type), intent(in) :: ELLM         ! Matrix in ELL format.
      type(lamg_comm), intent(in) :: LAMG_Communicator  ! Communicator.
      type(LAMG_LS_Options), intent(in) :: LAMG_Options ! LAMG options.
  
      ! Output variables.
  
      type(LAMG_Matrix_dcsr_r), intent(out) :: LAMG_Matrix ! LAMG formt matrix.
      type(status_type), intent(out),optional :: status ! Output status.
  
      ! Internal variables.
  
      type(integer) :: NNonzeros_PE         ! Number of nonzeros on this PE.
      type(integer) :: LAMG_Status          ! LAMG status.
      type(integer,2) :: Columns_BNA        ! Matrix columns bare naked array.
      type(real,2) :: Values_BNA            ! Matrix values bare naked array.
      type(LAMG_Matrix_csr_r) :: LAMG_BR_Matrix ! LAMG block-row format matrix.
      type(integer) :: BR_Location          ! Location in the block-row matrix.
      type(integer) :: ELL_Location         ! Location in the ELL matrix.
      type(integer) :: row                  ! Row loop counter.
  
      type(Status_type), dimension(10) :: allocate_status ! Allocation Status.
      type(Status_type) :: consolidated_status           ! Consolidated Status.

      !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
      ! Verify requirements.
  
      VERIFY(Valid_State(ELLM),5)  ! ELLM is valid.

      ! Initializations.
  
      call Initialize (allocate_status)
      call Initialize (consolidated_status)

      ! Pull ELLM matrix values and columns out in BNAs.
  
      call Initialize (Values_BNA,  NRows_PE(ELLM), Max_Nonzeros(ELLM), &
                       allocate_status(1))
      call Initialize (Columns_BNA, NRows_PE(ELLM), Max_Nonzeros(ELLM), &
                       allocate_status(2))
      Values_BNA = ELLM
      Columns_BNA = ELLM
      NNonzeros_PE = COUNT(Values_BNA/=zero)
  
      ! Convert ELLM into LAMG matrix.
  
      LAMG_BR_Matrix%nrow = NRows_PE(ELLM)
      LAMG_BR_Matrix%ncol = NRows_Total(ELLM)
      LAMG_BR_Matrix%nnz  = NNonzeros_PE
  
      ! Initialize LAMG block-row matrix.
  
      call Initialize (LAMG_BR_Matrix%ia, LAMG_BR_Matrix%nrow+1, &
                       allocate_status(3))
      call Initialize (LAMG_BR_Matrix%ja, LAMG_BR_Matrix%nnz   , &
                       allocate_status(4))
      call Initialize (LAMG_BR_Matrix% a, LAMG_BR_Matrix%nnz   , &
                       allocate_status(5))
  
      ! Fill the LAMG block-row matrix.
  
      BR_location = 0
      do row = 1, NRows_PE(ELLM)
        LAMG_BR_Matrix%ia(row) = BR_location + 1
        do ELL_location = 1, Max_Nonzeros(ELLM)
          if (Values_BNA(row,ELL_location) /= zero) then
            BR_location = BR_location + 1
            LAMG_BR_Matrix% a(BR_location) =  Values_BNA(row,ELL_location)
            LAMG_BR_Matrix%ja(BR_location) = Columns_BNA(row,ELL_location)
          end if
        end do
      end do
      LAMG_BR_Matrix%ia(NRows_PE(ELLM) + 1) = BR_location + 1
      VERIFY(BR_location==NNonzeros_PE,4)
  
      ! Finalize BNA matrix.
  
      call Finalize (Values_BNA, allocate_status(6))
      call Finalize (Columns_BNA, allocate_status(7))
  
      ! Transform matrix into LAMG internal format.
  
      call LAMG_Transform_Matrix (LAMG_Matrix, LAMG_BR_Matrix, &
                                  LAMG_Communicator, LAMG_Options, LAMG_Status)
  
      ! Finalize LAMG block-row matrix.
  
      call Finalize (LAMG_BR_Matrix%ia, allocate_status(8))
      call Finalize (LAMG_BR_Matrix%ja, allocate_status(9))
      call Finalize (LAMG_BR_Matrix% a, allocate_status(10))
  
      ! Process status variables.
  
      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)

      ! Verify guarantees - none.
  
      return
    end subroutine Convert_ELL_to_LAMG
  ])



Michael L. Hall