diff options
author | Wojtek Kosior <kwojtus@protonmail.com> | 2019-04-25 13:05:18 +0200 |
---|---|---|
committer | Wojtek Kosior <kwojtus@protonmail.com> | 2019-04-25 13:05:18 +0200 |
commit | 7a3dc61f1205a30d09e5e6662c1eecd651c92fd5 (patch) | |
tree | bea892a6159da61d8cfb6ff9d867b9a85b0e288b /src | |
parent | 2cef86b7eca2dbf96cda5909de27754249dc9259 (diff) | |
download | fortran-assignment1-7a3dc61f1205a30d09e5e6662c1eecd651c92fd5.tar.gz fortran-assignment1-7a3dc61f1205a30d09e5e6662c1eecd651c92fd5.zip |
make selection between floating point types possible
Diffstat (limited to 'src')
-rw-r--r-- | src/main.F90 | 80 |
1 files changed, 75 insertions, 5 deletions
diff --git a/src/main.F90 b/src/main.F90 index 43eeabb..be9dd58 100644 --- a/src/main.F90 +++ b/src/main.F90 @@ -6,17 +6,17 @@ PROGRAM mul integer, parameter :: seed = 123456 real :: time - integer :: dim = 10, multype = 1, realtype = 4 + integer :: dim = 10, multype = 1, realtype = 8 DO WHILE (dim < 2000) SELECT CASE(realtype) CASE (4) time = measure_4(dim) - ! CASE (8) - ! time = measure_8(dim) - ! CASE (16) - ! time = measure_16(dim) + CASE (8) + time = measure_8(dim) + CASE (16) + time = measure_16(dim) CASE default write (*, *) "wrong kind for real: ", realtype @@ -73,5 +73,75 @@ CONTAINS time = end - start END FUNCTION measure_4 + + real FUNCTION measure_8(dim) result(time) + integer, intent(in) :: dim + real(kind=8), dimension(:,:), allocatable :: mat1, mat2, res + real :: start, end + + call init_random_seed() + + allocate(mat1(dim,dim)) + allocate(mat2(dim,dim)) + allocate(res(dim,dim)) + + call random_number(mat1) + call random_number(mat2) + + call cpu_time(start) + + SELECT CASE(multype) + CASE (1) + res = naivmull(mat1, mat2) + CASE (2) + res = bettmull(mat1, mat2) + CASE (3) + res = dotmull(mat1, mat2) + CASE default + res = matmul(mat1, mat2) + + END SELECT + + call cpu_time(end) + + time = end - start + + END FUNCTION measure_8 + + + real FUNCTION measure_16(dim) result(time) + integer, intent(in) :: dim + real(kind=16), dimension(:,:), allocatable :: mat1, mat2, res + real :: start, end + + call init_random_seed() + + allocate(mat1(dim,dim)) + allocate(mat2(dim,dim)) + allocate(res(dim,dim)) + + call random_number(mat1) + call random_number(mat2) + + call cpu_time(start) + + SELECT CASE(multype) + CASE (1) + res = naivmull(mat1, mat2) + CASE (2) + res = bettmull(mat1, mat2) + CASE (3) + res = dotmull(mat1, mat2) + CASE default + res = matmul(mat1, mat2) + + END SELECT + + call cpu_time(end) + + time = end - start + + END FUNCTION measure_16 + END PROGRAM mul |