!===============================================================================
!
! matmul.F90 - multiplication of small matrices
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 2016 Hinnerk Stueben
!
! This file is part of BQCD -- Berlin Quantum ChromoDynamics program
!
! BQCD is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! BQCD is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with BQCD.  If not, see <http://www.gnu.org/licenses/>.
!
!-------------------------------------------------------------------------------

DO n = 2, 2
FOR rkind in 4 8

!------------------------------------------------------------------------------
subroutine matmul%%n%%_nn_c%%rkind(out, a, b)

  implicit none
  complex(rkind), intent(out) :: out(n, n)
  complex(rkind), intent(in)  :: a(n, n), b(n, n)

  DO k = 1, n
  DO j = 1, n
  DO i = 1, n
  IF (( k == 1 ))
  out(i, j) = a(i, k) * b(k, j)
  ELSE
  out(i, j) = out(i, j) + a(i, k) * b(k, j)
  ENDIF
  ENDDO
  ENDDO

  ENDDO
end

!------------------------------------------------------------------------------
subroutine matmul%%n%%_cn_c%%rkind(out, a, b)

  implicit none
  complex(rkind), intent(out) :: out(n, n)
  complex(rkind), intent(in)  :: a(n, n), b(n, n)

  DO k = 1, n
  DO i = 1, n
  DO j = 1, n
  IF (( k == 1 ))
  out(i, j) = conjg(a(k, i)) * b(k, j)
  ELSE
  out(i, j) = out(i, j) + conjg(a(k, i)) * b(k, j)
  ENDIF
  ENDDO
  ENDDO

  ENDDO
end

!------------------------------------------------------------------------------
subroutine matmul%%n%%_nc_c%%rkind(out, a, b)

  implicit none
  complex(rkind), intent(out) :: out(n, n)
  complex(rkind), intent(in)  :: a(n, n), b(n, n)

  DO k = 1, n
  DO i = 1, n
  DO j = 1, n
  IF (( k == 1 ))
  out(i, j) = a(i, k) * conjg(b(j, k))
  ELSE
  out(i, j) = out(i, j) + a(i, k) * conjg(b(j, k))
  ENDIF
  ENDDO
  ENDDO

  ENDDO
end

ENDFOR
ENDDO
!==============================================================================
