From 2157bcd5276d35f2c462d8bf711dbd392ad2d11b Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 23 Apr 2019 22:35:16 +0200 Subject: implement multiplication using dot_product --- src/dotmath.F90 | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/dotmath.F90 b/src/dotmath.F90 index bb1725b..81f1f13 100644 --- a/src/dotmath.F90 +++ b/src/dotmath.F90 @@ -38,5 +38,55 @@ MODULE dotmat CONTAINS + FUNCTION dotmull_4(A, B) result(C) + IMPLICIT none + real(kind=4), intent(in), dimension(1:,1:) :: A, B + real(kind=4), dimension(:,:), allocatable :: C + integer :: i, j + + allocate(C(size(A, 1), size(B, 2))) + + DO j = 1, size(B, 2) + DO i = 1, size(A, 1) + + C(i,j) = dot_product(A(i,:), B(:,j)) + END DO + END DO + + END FUNCTION dotmull_4 + + FUNCTION dotmull_8(A, B) result(C) + IMPLICIT none + real(kind=8), intent(in), dimension(1:,1:) :: A, B + real(kind=8), dimension(:,:), allocatable :: C + integer :: i, j + + allocate(C(size(A, 1), size(B, 2))) + + DO j = 1, size(B, 2) + DO i = 1, size(A, 1) + + C(i,j) = dot_product(A(i,:), B(:,j)) + END DO + END DO + + END FUNCTION dotmull_8 + FUNCTION dotmull_16(A, B) result(C) + IMPLICIT none + real(kind=16), intent(in), dimension(1:,1:) :: A, B + real(kind=16), dimension(:,:), allocatable :: C + integer :: i, j + + allocate(C(size(A, 1), size(B, 2))) + + DO j = 1, size(B, 2) + DO i = 1, size(A, 1) + + C(i,j) = dot_product(A(i,:), B(:,j)) + END DO + END DO + + END FUNCTION dotmull_16 + END MODULE dotmat -- cgit v1.2.3