dbcsr_data_new Subroutine

public subroutine dbcsr_data_new(area, data_type, data_size, data_size2, memory_type)

Initializes a data area and all the actual data pointers

Arguments

TypeIntentOptionalAttributesName
type(dbcsr_data_obj), intent(inout) :: area

data area

integer, intent(in) :: data_type

select data type to use

integer, intent(in), optional :: data_size

allocate this much data second dimension data size

integer, intent(in), optional :: data_size2

allocate this much data second dimension data size

type(dbcsr_memtype_type), intent(in), optional :: memory_type

type of memory to use


Contents

Source Code


Source Code

   SUBROUTINE dbcsr_data_new(area, data_type, data_size, data_size2, &
                             memory_type)
      !! Initializes a data area and all the actual data pointers

      TYPE(dbcsr_data_obj), INTENT(INOUT)                :: area
         !! data area
      INTEGER, INTENT(IN)                                :: data_type
         !! select data type to use
      INTEGER, INTENT(IN), OPTIONAL                      :: data_size, data_size2
         !! allocate this much data
         !! second dimension data size
      TYPE(dbcsr_memtype_type), INTENT(IN), OPTIONAL     :: memory_type
         !! type of memory to use

      CHARACTER(len=*), PARAMETER :: routineN = 'dbcsr_data_new'
      INTEGER                                            :: d, handle, total_size_oversized, &
                                                            total_size_requested
      INTEGER, DIMENSION(2)                              :: sizes_oversized, sizes_requested
      TYPE(dbcsr_memtype_type)                           :: my_memory_type

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

      CALL timeset(routineN, handle)

      IF (ASSOCIATED(area%d)) &
         DBCSR_ABORT("area already associated")

      my_memory_type = dbcsr_memtype_default
      IF (PRESENT(memory_type)) my_memory_type = memory_type

      sizes_requested(:) = 0; d = 1
      IF (PRESENT(data_size)) sizes_requested(1) = data_size

      IF (dbcsr_type_is_2d(data_type)) THEN
         d = 2
         IF (PRESENT(data_size2)) sizes_requested(2) = data_size2

         IF (PRESENT(data_size) .NEQV. PRESENT(data_size2)) &
            DBCSR_ABORT("Must specify 2 sizes for 2-D data")
      END IF

      sizes_oversized = INT(sizes_requested*my_memory_type%oversize_factor)
      total_size_requested = PRODUCT(sizes_requested(1:d))
      total_size_oversized = PRODUCT(sizes_oversized(1:d))

      IF (ANY(sizes_requested < 0) .OR. ANY(sizes_oversized < 0)) &
         DBCSR_ABORT("Negative data size requested, integer overflow?")

      IF (total_size_requested > 1 .AND. ASSOCIATED(my_memory_type%pool)) THEN
         area = dbcsr_mempool_get(my_memory_type, data_type, total_size_requested)
      END IF

      IF (.NOT. ASSOCIATED(area%d)) THEN
         ALLOCATE (area%d)
!$OMP        CRITICAL (crit_area_id)
         id = id + 1
         area%d%id = id
!$OMP        END CRITICAL (crit_area_id)
         area%d%refcount = 1
         area%d%memory_type = my_memory_type
         area%d%data_type = data_type
         IF (PRESENT(data_size)) THEN
            CALL internal_data_allocate(area%d, sizes_oversized(1:d))
         END IF
      END IF

      area%d%ref_size = total_size_requested

      CALL timestop(handle)
   END SUBROUTINE dbcsr_data_new