public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thomas Koenig <tkoenig@netcologne.de>
To: Nicolas Koenig <koenigni@student.ethz.ch>,
	Jerry DeLisle <jvdelisle@charter.net>
Cc: GCC-Fortran-ML <fortran@gcc.gnu.org>
Subject: Re: [Patch, fortran] PR35339 Optimize implied do loops in io statements
Date: Mon, 29 May 2017 06:40:00 -0000	[thread overview]
Message-ID: <f68088b9-2eb9-7a14-2984-77a6b7fd9835@netcologne.de> (raw)
In-Reply-To: <4bf3850e-393c-6ef8-3895-4a17931c1b9b@student.ethz.ch>

Hi Nicolas,

> gcc@dcm-linux:~/pr/35339> gfortran -O3 perf_test.f90
> gcc@dcm-linux:~/pr/35339> time ./a.out
> 
> real    0m1.879s
> user    0m1.838s
> sys     0m0.040s
> gcc@dcm-linux:~/pr/35339> gfortran-7 -O3 perf_test.f90
> gcc@dcm-linux:~/pr/35339> time ./a.out
> 
> real    0m1.929s
> user    0m1.901s
> sys     0m0.028s

For formatted I/O, the advantage will not be large because
of the CPU time needed for converting numbers to decimal.
People who care about speed in I/O use unformatted I/O,
and there is a big advantage to using an array slice:

$ cat tst.f90
module x
   implicit none
contains
   double precision function v2s(v)
     integer, dimension(8), intent(in) :: v
     v2s = v(8)*1d-3+v(7)+v(6)*60.d0+v(5)*3600.d0
   end function v2s
end module x
program main
   use x
   implicit none
   integer, parameter :: n=10**7
   real, dimension(n) :: a
   real:: t1, t2
   integer :: i
   integer, dimension(8) :: v1, v2

   call random_number(a)
   open(unit=10,file="test.dat",form="unformatted")
   call cpu_time(t1)
   call date_and_time(values=v1)
   write (10) (a(i),i=1,n)
   call date_and_time(values=v2)
   call cpu_time(t2)
   print *,"CPU time implied DO loop = ", t2-t1
   print *,"Wall time = ", v2s(v2)-v2s(v1)

   call cpu_time(t1)
   call date_and_time(values=v1)
   write (10) a(1:i:1)
   call cpu_time(t2)
   call date_and_time(values=v2)
   print *,"CPU time Array= ", t2-t1
   print *,"Wall time = ", v2s(v2)-v2s(v1)
   close(10,status="delete")
end program main

$ gfortran -O3 tst.f90
$ ./a.out
  CPU time implied DO loop =   0.374823004
  Wall time =   0.50600000000122236
  CPU time Array=    6.18300140E-02
  Wall time =   0.10599999999976717
$



WARNING: multiple messages have this Message-ID
From: Thomas Koenig <tkoenig@netcologne.de>
To: Nicolas Koenig <koenigni@student.ethz.ch>,
	Jerry DeLisle <jvdelisle@charter.net>
Cc: GCC-Fortran-ML <fortran@gcc.gnu.org>
Subject: Re: [Patch, fortran] PR35339 Optimize implied do loops in io statements
Date: Mon, 29 May 2017 14:06:00 -0000	[thread overview]
Message-ID: <f68088b9-2eb9-7a14-2984-77a6b7fd9835@netcologne.de> (raw)
Message-ID: <20170529140600.e6VIdTP2MoY52YR_Xf2-_Cu5UGyNWo8NqqI5029ZUhk@z> (raw)
In-Reply-To: <4bf3850e-393c-6ef8-3895-4a17931c1b9b@student.ethz.ch>

Hi Nicolas,

> gcc@dcm-linux:~/pr/35339> gfortran -O3 perf_test.f90
> gcc@dcm-linux:~/pr/35339> time ./a.out
> 
> real    0m1.879s
> user    0m1.838s
> sys     0m0.040s
> gcc@dcm-linux:~/pr/35339> gfortran-7 -O3 perf_test.f90
> gcc@dcm-linux:~/pr/35339> time ./a.out
> 
> real    0m1.929s
> user    0m1.901s
> sys     0m0.028s

For formatted I/O, the advantage will not be large because
of the CPU time needed for converting numbers to decimal.
People who care about speed in I/O use unformatted I/O,
and there is a big advantage to using an array slice:

$ cat tst.f90
module x
   implicit none
contains
   double precision function v2s(v)
     integer, dimension(8), intent(in) :: v
     v2s = v(8)*1d-3+v(7)+v(6)*60.d0+v(5)*3600.d0
   end function v2s
end module x
program main
   use x
   implicit none
   integer, parameter :: n=10**7
   real, dimension(n) :: a
   real:: t1, t2
   integer :: i
   integer, dimension(8) :: v1, v2

   call random_number(a)
   open(unit=10,file="test.dat",form="unformatted")
   call cpu_time(t1)
   call date_and_time(values=v1)
   write (10) (a(i),i=1,n)
   call date_and_time(values=v2)
   call cpu_time(t2)
   print *,"CPU time implied DO loop = ", t2-t1
   print *,"Wall time = ", v2s(v2)-v2s(v1)

   call cpu_time(t1)
   call date_and_time(values=v1)
   write (10) a(1:i:1)
   call cpu_time(t2)
   call date_and_time(values=v2)
   print *,"CPU time Array= ", t2-t1
   print *,"Wall time = ", v2s(v2)-v2s(v1)
   close(10,status="delete")
end program main

$ gfortran -O3 tst.f90
$ ./a.out
  CPU time implied DO loop =   0.374823004
  Wall time =   0.50600000000122236
  CPU time Array=    6.18300140E-02
  Wall time =   0.10599999999976717
$



  reply	other threads:[~2017-05-29  6:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-27 19:49 Nicolas Koenig
2017-05-28 22:07 ` Jerry DeLisle
2017-05-28 23:32   ` Nicolas Koenig
2017-05-29  6:40     ` Thomas Koenig [this message]
2017-05-29 14:06       ` Thomas Koenig
2017-05-29 15:32     ` Jerry DeLisle
2017-05-29 15:49 Dominique d'Humières
2017-05-29 16:24 ` Nicolas Koenig
2017-05-29 16:51   ` Dominique d'Humières
2017-05-31 15:40   ` Bernhard Reutner-Fischer
2017-05-31 15:49     ` Dominique d'Humières
2017-05-31 19:03       ` Dominique d'Humières
2017-05-31 23:15         ` Nicolas Koenig
2017-06-01  9:31           ` Dominique d'Humières
2017-06-01 14:19             ` Dominique d'Humières
2017-06-01 14:37               ` Dominique d'Humières
2017-06-01 18:26                 ` Nicolas Koenig
2017-06-03 13:48                 ` Nicolas Koenig
2017-06-03 16:25                   ` Jerry DeLisle
2017-06-03 18:12                     ` Bernhard Reutner-Fischer
2017-06-05 20:39                     ` Nicolas Koenig
2017-06-06 11:05                       ` Markus Trippelsdorf
2017-06-07 15:13                         ` Renlin Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f68088b9-2eb9-7a14-2984-77a6b7fd9835@netcologne.de \
    --to=tkoenig@netcologne.de \
    --cc=fortran@gcc.gnu.org \
    --cc=jvdelisle@charter.net \
    --cc=koenigni@student.ethz.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).