sum_matrix_int32 Function

private function sum_matrix_int32(matrix, threaded) result(res)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: matrix(:,:)
logical, intent(in), optional :: threaded

Return Value integer(kind=int32)


Called by

proc~~sum_matrix_int32~~CalledByGraph proc~sum_matrix_int32 sum_matrix_int32 interface~pic_sum pic_sum interface~pic_sum->proc~sum_matrix_int32

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: cols
integer(kind=default_int), private :: i
integer(kind=default_int), private :: ii
integer(kind=default_int), private :: j
integer(kind=default_int), private :: jj
integer(kind=default_int), private :: rows
logical, private :: use_threads

Source Code

   function sum_matrix_int32(matrix, threaded) result(res)
      integer(int32), intent(in) :: matrix(:, :)
      logical, intent(in), optional :: threaded
      logical :: use_threads
      integer(int32) :: res
      integer(default_int) :: cols, rows, i, j, ii, jj

      rows = size(matrix, 1)
      cols = size(matrix, 2)

      if (present(threaded)) then
         use_threads = threaded
      else
         use_threads = use_threaded_default
      end if
      res = 0_int32
      if (use_threads) then
         !$omp parallel do collapse(2) private(i,j,ii,jj) reduction(+: res)
         do jj = 1, cols, block_size
            do ii = 1, rows, block_size
               do j = jj, min(jj + block_size - 1, cols)
                  do i = ii, min(ii + block_size - 1, rows)
                     res = res + matrix(i, j)
                  end do
               end do
            end do
         end do
         !$omp end parallel do
      else
         res = sum(matrix)
      end if

   end function sum_matrix_int32