dbcsr_add_wm_from_matrix Subroutine

public subroutine dbcsr_add_wm_from_matrix(matrix, limits)

Creates a work matrix from the data present in a finalized matrix.

Arguments

Type IntentOptional Attributes Name
type(dbcsr_type), intent(inout) :: matrix

DBCSR matrix

integer, intent(in), optional, DIMENSION(4) :: limits

the limits to use for copying


Source Code

   SUBROUTINE dbcsr_add_wm_from_matrix(matrix, limits)
      !! Creates a work matrix from the data present in a finalized matrix.

      TYPE(dbcsr_type), INTENT(INOUT)                    :: matrix
         !! DBCSR matrix
      INTEGER, DIMENSION(4), INTENT(IN), OPTIONAL        :: limits
         !! the limits to use for copying

      CHARACTER(len=*), PARAMETER :: routineN = 'dbcsr_add_wm_from_matrix'

      INTEGER                                            :: handle, ithread, nthreads, nwms, &
                                                            old_nwms, size_used
      LOGICAL                                            :: preexists

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

      CALL timeset(routineN, handle)
!$OMP     BARRIER
      preexists = ASSOCIATED(matrix%wms)
      IF (preexists) THEN
         old_nwms = SIZE(matrix%wms)
         IF (old_nwms .EQ. 0) &
            DBCSR_WARN("Nonexisting work matrices?!")
      ELSE
         old_nwms = 0
      END IF
      nthreads = 1; ithread = 0
!$    nthreads = OMP_GET_NUM_THREADS(); ithread = OMP_GET_THREAD_NUM()
      IF (nthreads .GT. 1) THEN
         IF (old_nwms /= nthreads .AND. old_nwms /= 0) &
            DBCSR_ABORT("Number of work matrices and threads do not match")
      END IF
      nwms = MAX(1, old_nwms)
!$    nwms = MAX(nwms, nthreads)
!$OMP     BARRIER
!$OMP     MASTER
      IF (.NOT. ASSOCIATED(matrix%wms)) THEN
         CALL dbcsr_work_create(matrix, &
                                INT(matrix%nblks*default_resize_factor/nwms), &
                                INT(matrix%nze*default_resize_factor/nwms), &
                                n=nwms, work_mutable=.FALSE.)
      END IF
!$OMP     END MASTER
!$OMP     BARRIER
      size_used = matrix%nze
      CALL dbcsr_fill_wm_from_matrix(matrix%wms, matrix, size_used, &
                                     limits=limits)
!$OMP     BARRIER
      CALL timestop(handle)
   END SUBROUTINE dbcsr_add_wm_from_matrix