splitting_jacobi_cpu_s.f90 Source File


Source Code

submodule(splitting_m) splitting_jacobi_cpu_s
    !! Splitting solver with Jacobi splitting method on CPU
    implicit none

contains

    module subroutine create_jacobi_cpu(self, mesh)
        class(splitting_jacobi_cpu_t), intent(inout) :: self
        type(mesh_cart_t), intent(in), target :: mesh

        ! Store dimension
        self%ndim = mesh%get_n_points()

        ! Allocate local arrays
        allocate(self%xn(self%ndim))

        ! Damping factor
        self%omega = 0.5_FP

    end subroutine

    module subroutine apply_jacobi_cpu(self, a, dinv, x, b)
        class(splitting_jacobi_cpu_t), intent(inout) :: self
        type(csrmat_t), intent(in) :: a
        real(FP), intent(in), dimension(self%ndim) :: dinv
        real(FP), intent(inout), dimension(self%ndim) :: x
        real(FP), intent(in), dimension(self%ndim) :: b

        integer :: row

        ! Compute xn
        call csr_times_vec(a, x, self%xn)
        ! Update x
#ifdef __NVCOMPILER
            !$omp simd
#else
            !$omp do simd schedule(static)
#endif
        do row = 1, a%ndim
            x(row) = x(row) + self%omega*dinv(row)*(b(row) - self%xn(row))
        enddo
#ifdef __NVCOMPILER
            !$omp end simd
#else
            !$omp end do simd
#endif

    end subroutine

    module subroutine destructor_jacobi_cpu(self)
        type(splitting_jacobi_cpu_t), intent(inout) :: self

        if (allocated(self%xn)) deallocate(self%xn)
        self%ndim = 0

    end subroutine

end submodule