diff options
| author | Connor Moore <connor@hhmoore.ca> | 2026-01-28 23:03:54 -0500 |
|---|---|---|
| committer | Connor Moore <connor@hhmoore.ca> | 2026-01-28 23:03:54 -0500 |
| commit | d81191c40989de0c3809c4eade2c58ab1c44146d (patch) | |
| tree | b82792c714ea222feace2895672dcd1e57b87aaa /matrixproduct.f90 | |
| parent | 98c8a23b00f88de5ef5d5bdb90e170066d5fd0bc (diff) | |
Added command line arguments for farming results. Major update. Added makefile support.
Diffstat (limited to 'matrixproduct.f90')
| -rw-r--r-- | matrixproduct.f90 | 62 |
1 files changed, 46 insertions, 16 deletions
diff --git a/matrixproduct.f90 b/matrixproduct.f90 index fd15622..e622ac2 100644 --- a/matrixproduct.f90 +++ b/matrixproduct.f90 @@ -5,29 +5,52 @@ program matrixproduct !> 1. Basic triple-loop (iterative algorithm) !> 2. Fortran native matmul routine !> 3. LAPACK/BLAS library call - + + use :: omp_lib use, intrinsic :: iso_fortran_env implicit none external :: dgemm !> double-precision general matrix-matrix multiplication real(real64), allocatable, dimension(:,:) :: A, B, C real(real64) :: start, end, loop_time, loop_alt_time, matmul_time, blas_time - integer(int32) :: n - - do n = 1000,35000,1000 + integer(int32) :: n, start_num, step_num, stop_num + character(10) :: temp_in + logical :: run_loops + + call get_command_argument(1, temp_in) + read(temp_in,'(i10)') start_num + call get_command_argument(2, temp_in) + read(temp_in,'(i10)') step_num + call get_command_argument(3, temp_in) + read(temp_in,'(i10)') stop_num + call get_command_argument(4, temp_in) + select case (temp_in) + case ('yes ') + run_loops=.TRUE. + case ('no ') + run_loops=.FALSE. + case default + write(*,'(A,A,A)') "WARNING: ",temp_in," not supported argument for run_loops [yes/no]" + end select + + write(*,'(A,i10,i10,i10)') "Running with start, step, stop ",start_num,step_num,stop_num + + do n = start_num, stop_num, step_num call prep_mats(A,B,C,n) - call cpu_time(start) - !call triple_loop_mul(A,B,C,n) - call cpu_time(end) - loop_time = end-start - C = 0 + if(run_loops) then + call cpu_time(start) + call triple_loop_mul(A,B,C,n) + call cpu_time(end) + 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) + call triple_loop_mul_alt(A,B,C,n) + call cpu_time(end) + loop_alt_time = end-start + C = 0 + endif call cpu_time(start) C = matmul(A,B) @@ -40,8 +63,13 @@ program matrixproduct call cpu_time(end) blas_time = end-start - !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 + deallocate(A,B,C) + + if(run_loops) then + write(*,'((i5),4(e16.8))') n, loop_time, loop_alt_time, matmul_time, blas_time + else + write(*,'((i5),2(e16.8))') n, matmul_time, blas_time + endif enddo contains @@ -66,6 +94,7 @@ contains integer(int32), intent(in) :: n integer(int32) :: i, j, k + !$omp parallel do private(i,j,k) row: do i = 1,n col: do j = 1,n sum: do k = 1,n @@ -73,6 +102,7 @@ contains end do sum end do col end do row + !$omp end parallel do end subroutine triple_loop_mul |
