From 98c8a23b00f88de5ef5d5bdb90e170066d5fd0bc Mon Sep 17 00:00:00 2001 From: Connor Moore Date: Fri, 23 Jan 2026 11:05:33 -0500 Subject: Added second loop variation and preliminary results --- matrixproduct.f90 | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'matrixproduct.f90') diff --git a/matrixproduct.f90 b/matrixproduct.f90 index feb4cf1..fd15622 100644 --- a/matrixproduct.f90 +++ b/matrixproduct.f90 @@ -11,10 +11,10 @@ program matrixproduct external :: dgemm !> double-precision general matrix-matrix multiplication real(real64), allocatable, dimension(:,:) :: A, B, C - real(real64) :: start, end, loop_time, matmul_time, blas_time + real(real64) :: start, end, loop_time, loop_alt_time, matmul_time, blas_time integer(int32) :: n - do n = 1000,100000,1000 + do n = 1000,35000,1000 call prep_mats(A,B,C,n) call cpu_time(start) @@ -23,6 +23,12 @@ program matrixproduct loop_time = end-start C = 0 + call cpu_time(start) + !call triple_loop_mul_alt(A,B,C,n) + call cpu_time(end) + loop_alt_time = end-start + C = 0 + call cpu_time(start) C = matmul(A,B) call cpu_time(end) @@ -34,7 +40,8 @@ program matrixproduct call cpu_time(end) blas_time = end-start - write(*,'((i5),3(e16.8))') n, loop_time, matmul_time, blas_time + !write(*,'((i5),4(e16.8))') n, loop_time, loop_alt_time, matmul_time, blas_time + write(*,'((i5),2(e16.8))') n, matmul_time, blas_time enddo contains @@ -69,5 +76,20 @@ contains end subroutine triple_loop_mul + subroutine triple_loop_mul_alt(A,B,C,n) + real(real64), dimension(:,:), intent(in) :: A,B + real(real64), dimension(:,:), intent(out) :: C + integer(int32), intent(in) :: n + integer(int32) :: i, j, k + + col: do j = 1,n + row: do i = 1,n + sum: do k = 1,n + C(i,j) = C(i,j) + A(i,k)*B(k,j) + end do sum + end do row + end do col + + end subroutine triple_loop_mul_alt end program matrixproduct -- cgit v1.2.3