alloc_workspace Subroutine

public pure subroutine alloc_workspace(self, n, stat)

Initializes nf_workspace, i.e., (re)allocates all allocatable arrays and sets them to zero.

Type Bound

nf_workspace

Arguments

Type IntentOptional Attributes Name
class(nf_workspace), intent(inout) :: self

Workspace object.

integer, intent(in) :: n

Problem dimension.

integer, intent(out), optional :: stat

Error status of the allocation.


Called by

proc~~alloc_workspace~~CalledByGraph proc~alloc_workspace nf_workspace%alloc_workspace proc~alloc_state nf_state%alloc_state proc~alloc_state->proc~alloc_workspace proc~nf_solver_initialize nf_solver%nf_solver_initialize proc~nf_solver_initialize->proc~alloc_state

Variables

Type Visibility Attributes Name Initial
integer, public :: ierr(8)

Source Code

   pure subroutine alloc_workspace(self, n, stat)
   !! Initializes [[nf_workspace]], i.e., (re)allocates all allocatable arrays and sets them
   !! to zero.

      class(nf_workspace), intent(inout) :: self
         !! Workspace object.
      integer, intent(in) :: n
         !! Problem dimension.
      integer, intent(out), optional :: stat
         !! Error status of the allocation.

      integer :: ierr(8)

      if (n <= 0) then
         error stop "Error: 'n' must be positive in hompack_nf_state%alloc()."
      end if

      if (present(stat)) stat = 0

      ! Deallocate any previously allocated arrays
      if (allocated(self%alpha)) deallocate (self%alpha)
      if (allocated(self%qr)) deallocate (self%qr)
      if (allocated(self%tz)) deallocate (self%tz)
      if (allocated(self%w)) deallocate (self%w)
      if (allocated(self%wp)) deallocate (self%wp)
      if (allocated(self%z0)) deallocate (self%z0)
      if (allocated(self%z1)) deallocate (self%z1)
      if (allocated(self%pivot)) deallocate (self%pivot)

      ! Allocate/initialize workspace arrays
      allocate (self%alpha(3*n + 3), source=zero, stat=ierr(1))
      allocate (self%qr(n, n + 2), source=zero, stat=ierr(2))
      allocate (self%tz(n + 1), source=zero, stat=ierr(3))
      allocate (self%w(n + 1), source=zero, stat=ierr(4))
      allocate (self%wp(n + 1), source=zero, stat=ierr(5))
      allocate (self%z0(n + 1), source=zero, stat=ierr(6))
      allocate (self%z1(n + 1), source=zero, stat=ierr(7))
      allocate (self%pivot(n + 1), source=0, stat=ierr(8))

      if (any(ierr /= 0)) then
         if (present(stat)) then
            stat = ierr(findloc(ierr /= 0, .true., dim=1))
         else
            error stop "Error: Allocation failed in hompack_nf_workspace%alloc()."
         end if
      end if

   end subroutine alloc_workspace