aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-04-23 22:19:35 +0200
committerWojtek Kosior <kwojtus@protonmail.com>2019-04-23 22:19:35 +0200
commitdf497fc915b6a50ea13e0b755e86ac7f1b54fc01 (patch)
tree34fd5227410bf6502733369d74d5e683ab84958f
parent190548dfb2155b244ce3271d537110d41f42eea5 (diff)
downloadfortran-assignment1-df497fc915b6a50ea13e0b755e86ac7f1b54fc01.tar.gz
fortran-assignment1-df497fc915b6a50ea13e0b755e86ac7f1b54fc01.zip
implement naive multiplication
-rw-r--r--src/naivemath.F9060
1 files changed, 59 insertions, 1 deletions
diff --git a/src/naivemath.F90 b/src/naivemath.F90
index ef33aea..a83505e 100644
--- a/src/naivemath.F90
+++ b/src/naivemath.F90
@@ -38,6 +38,64 @@ MODULE naivmat
CONTAINS
-
+ FUNCTION naivmull_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 i = 1, size(A(:,1))
+ DO j = 1, size(B(1,:))
+ DO k = 1, size(A(1,:))
+
+ C(i,j) = C(i,j) + A(i,k) * B(k,j)
+ END DO
+ END DO
+ END DO
+
+ END FUNCTION naivmull_4
+
+ FUNCTION naivmull_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 i = 1, size(A, 1)
+ DO j = 1, size(B, 2)
+ DO k = 1, size(A, 2)
+
+ C(i,j) = C(i,j) + A(i,k) * B(k,j)
+ END DO
+ END DO
+ END DO
+
+ END FUNCTION naivmull_8
+
+ FUNCTION naivmull_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 i = 1, size(A, 1)
+ DO j = 1, size(B, 2)
+ DO k = 1, size(A, 2)
+
+ C(i,j) = C(i,j) + A(i,k) * B(k,j)
+ END DO
+ END DO
+ END DO
+
+ END FUNCTION naivmull_16
END MODULE naivmat