From bcb51764b8d4a557902a6df5e1c4f39ebe1e6afe Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Thu, 25 Apr 2019 13:47:29 +0200 Subject: enable mul implementation selection on command line, improve error notifications for wrong arguments --- src/main.F90 | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/main.F90 b/src/main.F90 index 97e8e2d..d6b8002 100644 --- a/src/main.F90 +++ b/src/main.F90 @@ -7,12 +7,11 @@ PROGRAM mul integer, parameter :: seed = 123456 real :: time - integer :: dim = 10, multype = 1, real_kind, stat - character(5) :: kind_arg + integer :: dim = 10, multype, real_kind, stat + character(5) :: kind_arg, impl_arg - IF (command_argument_count() < 1) THEN - write (error_unit, *) "Usage: mul KIND", char(10), & - "where KIND is one of: 4, 8, 16" + IF (command_argument_count() < 2) THEN + call print_usage() STOP END IF @@ -21,10 +20,27 @@ PROGRAM mul read (kind_arg, *, iostat = stat) real_kind IF (stat .ne. 0) THEN - write (error_unit, *) "Couldn't parse kind number argument" + write (error_unit, '(A)') "Couldn't parse kind number argument" + call print_usage() STOP END IF - + + call get_command_argument(2, impl_arg) + + IF (trim(impl_arg) .eq. "naiv") THEN + multype = 1 + ELSE IF (trim(impl_arg) .eq. "bett") THEN + multype = 2 + ELSE IF (trim(impl_arg) .eq. "dot") THEN + multype = 3 + ELSE IF (trim(impl_arg) .eq. "mat") THEN + multype = 4 + ELSE + write (error_unit, '(A)') "Unrecognized implementation argument" + call print_usage() + STOP + END IF + DO WHILE (dim < 2000) SELECT CASE(real_kind) @@ -35,7 +51,8 @@ PROGRAM mul CASE (16,3) time = measure_16(dim) CASE default - write (error_unit, *) "wrong kind for real: ", real_kind + write (error_unit, '(A,I6)') & + "wrong kind for real:", real_kind STOP END SELECT @@ -48,6 +65,16 @@ PROGRAM mul CONTAINS + SUBROUTINE print_usage() + + write (*, '(A)') & + "Usage: mul KIND IMPLEMENTATION" // char(10) // & + "where KIND is one of: 4, 8, 16" // char(10) // & + " IMPLEMENTATION is one of: naiv, bett, dot, mat" + + END SUBROUTINE print_usage + + SUBROUTINE init_random_seed() integer :: i, n -- cgit v1.2.3