aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-04-23 22:25:27 +0200
committerWojtek Kosior <kwojtus@protonmail.com>2019-04-23 22:25:27 +0200
commit51ce1efb441b6950032d622e6f859797db256fa7 (patch)
tree4022965101f1d8fe6d660a7eede9360a71d6838a
parent15a3c9bb954cd912ce2af323b85b108d10bd74c8 (diff)
downloadfortran-assignment1-51ce1efb441b6950032d622e6f859797db256fa7.tar.gz
fortran-assignment1-51ce1efb441b6950032d622e6f859797db256fa7.zip
implement better multiplication
-rw-r--r--src/bettermath.F9059
1 files changed, 59 insertions, 0 deletions
diff --git a/src/bettermath.F90 b/src/bettermath.F90
index 4b64c54..e2c0773 100644
--- a/src/bettermath.F90
+++ b/src/bettermath.F90
@@ -38,5 +38,64 @@ MODULE bettmat
CONTAINS
+ FUNCTION bettmull_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, k
+
+ allocate(C(size(A, 1), size(B, 2)))
+ C = 0
+
+ DO j = 1, size(B(1,:))
+ DO k = 1, size(A(1,:))
+ DO i = 1, size(A(:,1))
+
+ C(i,j) = C(i,j) + A(i,k) * B(k,j)
+ END DO
+ END DO
+ END DO
+
+ END FUNCTION bettmull_4
+
+ FUNCTION bettmull_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, k
+
+ allocate(C(size(A, 1), size(B, 2)))
+ C = 0
+
+ DO j = 1, size(B(1,:))
+ DO k = 1, size(A(1,:))
+ DO i = 1, size(A(:,1))
+
+ C(i,j) = C(i,j) + A(i,k) * B(k,j)
+ END DO
+ END DO
+ END DO
+
+ END FUNCTION bettmull_8
+ FUNCTION bettmull_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, k
+
+ allocate(C(size(A, 1), size(B, 2)))
+ C = 0
+
+ DO j = 1, size(B(1,:))
+ DO k = 1, size(A(1,:))
+ DO i = 1, size(A(:,1))
+
+ C(i,j) = C(i,j) + A(i,k) * B(k,j)
+ END DO
+ END DO
+ END DO
+
+ END FUNCTION bettmull_16
+
END MODULE bettmat