diff options
| -rw-r--r-- | Makefile | 21 | ||||
| -rw-r--r-- | long_runs.cvs | 22 | ||||
| -rw-r--r-- | matrixproduct.f90 | 62 | ||||
| -rw-r--r-- | short_runs.csv | 36 |
4 files changed, 67 insertions, 74 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..39b5bdf --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +gnu: + gfortran matrixproduct.f90 -o bin/gcc.out -lblas -O3 -fopenmp +intel: + ifx matrixproduct.f90 -o bin/intel.out -lblas -O3 -fopenmp -heap-arrays + +dir: + mkdir results bin + +tests: clean dir gnu intel + ./bin/gcc.out 100 100 3500 yes > results/gcc_short + ./bin/intel.out 100 100 3500 yes > results/intel_short + + ./bin/gcc.out 3500 1000 10500 no > results/gcc_long + ./bin/intel.out 3500 1000 10500 no > results/gcc_long + +plots: + gnuplot -p plots.gnu + +clean: + rm -rf bin/ + rm -rf results/ diff --git a/long_runs.cvs b/long_runs.cvs deleted file mode 100644 index ff060c7..0000000 --- a/long_runs.cvs +++ /dev/null @@ -1,22 +0,0 @@ -N,matmul,blas_dgemm -1000,0.10193400E+00,0.58010400E+00 -2000,0.64242800E+00,0.46658950E+01 -3000,0.21485870E+01,0.16550798E+02 -4000,0.50890610E+01,0.38807770E+02 -5000,0.98788060E+01,0.75952624E+02 -6000,0.16943837E+02,0.12970843E+03 -7000,0.27091881E+02,0.20561875E+03 -8000,0.40548225E+02,0.31527694E+03 -9000,0.57014092E+02,0.44617752E+03 -10000,0.78390511E+02,0.61657925E+03 -11000,0.10588242E+03,0.82130777E+03 -12000,0.13627938E+03,0.10666839E+04 -13000,0.17270659E+03,0.13624819E+04 -14000,0.21550922E+03,0.16965049E+04 -15000,0.26559991E+03,0.21014043E+04 -16000,0.32860096E+03,0.25695269E+04 -17000,0.38339895E+03,0.30997033E+04 -18000,0.45901556E+03,0.37488178E+04 -19000,0.53562014E+03,0.45838361E+04 -20000,0.63253852E+03,0.54320727E+04 - 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 diff --git a/short_runs.csv b/short_runs.csv deleted file mode 100644 index d20051a..0000000 --- a/short_runs.csv +++ /dev/null @@ -1,36 +0,0 @@ -N,loop_row_col,loop_col_row,matmul,blas_dgemm -100,0.59300000E-03,0.56300000E-03,0.31900000E-03,0.90600000E-03 -200,0.48990000E-02,0.50670000E-02,0.12850000E-02,0.52280000E-02 -300,0.11546000E-01,0.12258000E-01,0.32410000E-02,0.13718000E-01 -400,0.46028000E-01,0.45641000E-01,0.67240000E-02,0.32451000E-01 -500,0.82411000E-01,0.87122000E-01,0.12307000E-01,0.62779000E-01 -600,0.15985300E+00,0.15981000E+00,0.21728000E-01,0.10790800E+00 -700,0.24306400E+00,0.25618400E+00,0.34095000E-01,0.17180100E+00 -800,0.51714500E+00,0.47772100E+00,0.50202000E-01,0.25702700E+00 -900,0.62514100E+00,0.75229600E+00,0.74008000E-01,0.37891900E+00 -1000,0.11347540E+01,0.14588680E+01,0.95838000E-01,0.53417100E+00 -1100,0.59069930E+01,0.59634460E+01,0.12902900E+00,0.72982500E+00 -1200,0.10091301E+02,0.10410358E+02,0.16694000E+00,0.10028480E+01 -1300,0.15387643E+02,0.14998313E+02,0.21131600E+00,0.12604330E+01 -1400,0.18312705E+02,0.18748105E+02,0.26171400E+00,0.15952700E+01 -1500,0.22782961E+02,0.23063631E+02,0.31871300E+00,0.19756550E+01 -1600,0.26743603E+02,0.27118118E+02,0.39060700E+00,0.23881740E+01 -1700,0.33753746E+02,0.33749378E+02,0.46649600E+00,0.28914880E+01 -1800,0.40048285E+02,0.40339913E+02,0.55305000E+00,0.33923480E+01 -1900,0.47055393E+02,0.47242679E+02,0.64035200E+00,0.39590110E+01 -2000,0.59399582E+02,0.59914291E+02,0.74202900E+00,0.46979740E+01 -2100,0.64968825E+02,0.65738129E+02,0.87708900E+00,0.54780350E+01 -2200,0.78502911E+02,0.79407814E+02,0.99478900E+00,0.63250410E+01 -2300,0.91680394E+02,0.94567158E+02,0.11410510E+01,0.72776670E+01 -2400,0.10457867E+03,0.10439878E+03,0.12784300E+01,0.83679490E+01 -2500,0.12307907E+03,0.12405015E+03,0.14541440E+01,0.94498140E+01 -2600,0.13987954E+03,0.14206693E+03,0.16377200E+01,0.10724434E+02 -2700,0.16004822E+03,0.16073829E+03,0.18362130E+01,0.11987520E+02 -2800,0.17975253E+03,0.18076746E+03,0.20205060E+01,0.13357210E+02 -2900,0.20810941E+03,0.21055106E+03,0.22729940E+01,0.14782116E+02 -3000,0.23689813E+03,0.24143141E+03,0.25030500E+01,0.16392925E+02 -3100,0.26648284E+03,0.26482139E+03,0.27888030E+01,0.18112838E+02 -3200,0.25087040E+03,0.25230091E+03,0.30511340E+01,0.20086456E+02 -3300,0.32902761E+03,0.34492439E+03,0.34200240E+01,0.23516174E+02 -3400,0.38203689E+03,0.37951516E+03,0.36512380E+01,0.25044592E+02 -3500,0.41389121E+03,0.41692274E+03,0.40134930E+01,0.27029907E+02 |
