diff options
| author | Connor Moore <connor@hhmoore.ca> | 2026-01-30 23:13:40 -0500 |
|---|---|---|
| committer | Connor Moore <connor@hhmoore.ca> | 2026-01-30 23:13:40 -0500 |
| commit | e1babc4f71ba2e3fa3139dddb6d77f1c7b5a9683 (patch) | |
| tree | 463089ac45f16f5650e9ae8c1b69c0853b2e493f /matrixproduct.f90 | |
| parent | d81191c40989de0c3809c4eade2c58ab1c44146d (diff) | |
Added support for OpenMP. Cleaned up makefile. Added gnuplot file for `make plots`.
Diffstat (limited to 'matrixproduct.f90')
| -rw-r--r-- | matrixproduct.f90 | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/matrixproduct.f90 b/matrixproduct.f90 index e622ac2..d7b3d13 100644 --- a/matrixproduct.f90 +++ b/matrixproduct.f90 @@ -6,7 +6,7 @@ program matrixproduct !> 2. Fortran native matmul routine !> 3. LAPACK/BLAS library call - use :: omp_lib + use omp_lib use, intrinsic :: iso_fortran_env implicit none external :: dgemm !> double-precision general matrix-matrix multiplication @@ -16,24 +16,31 @@ program matrixproduct integer(int32) :: n, start_num, step_num, stop_num character(10) :: temp_in logical :: run_loops + + !> Start by taking the command-line arguments. This is useful because + !> it lets us call the program from Bash with a variable matrix size 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(3, temp_in) + read(temp_in,'(i10)') step_num + !> The last argument is a string [yes/no] that instructs the program + !> to either run with the triple-loops or ignore them completely. call get_command_argument(4, temp_in) - select case (temp_in) - case ('yes ') + select case (trim(temp_in)) + case ('yes') run_loops=.TRUE. - case ('no ') + case ('no') run_loops=.FALSE. case default - write(*,'(A,A,A)') "WARNING: ",temp_in," not supported argument for run_loops [yes/no]" + write(*,'("WARNING:",A," is not a supported argument [yes/no], defaulting to YES")') temp_in + run_loops=.TRUE. end select - write(*,'(A,i10,i10,i10)') "Running with start, step, stop ",start_num,step_num,stop_num + write(*,'("Compiled with ",A,A," on ",A)') COMPILER_VERSION(), COMPILER_OPTIONS() + write(*,'("Running with start=",I0,", stop=",I0,", step=",I0)') start_num, stop_num, step_num do n = start_num, stop_num, step_num call prep_mats(A,B,C,n) @@ -94,7 +101,7 @@ contains integer(int32), intent(in) :: n integer(int32) :: i, j, k - !$omp parallel do private(i,j,k) + !$omp parallel do private(j,k) row: do i = 1,n col: do j = 1,n sum: do k = 1,n @@ -112,6 +119,7 @@ contains integer(int32), intent(in) :: n integer(int32) :: i, j, k + !$omp parallel do private(j,k) col: do j = 1,n row: do i = 1,n sum: do k = 1,n @@ -119,6 +127,7 @@ contains end do sum end do row end do col + !$omp end parallel do end subroutine triple_loop_mul_alt |
