{"id":103,"date":"2017-09-13T10:06:37","date_gmt":"2017-09-13T13:06:37","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=103"},"modified":"2017-09-13T10:06:37","modified_gmt":"2017-09-13T13:06:37","slug":"funspeed-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/funspeed-f\/","title":{"rendered":"funspeed.f"},"content":{"rendered":"<pre>c&lt;html&gt;\r\nc&lt;body&gt;\r\nc&lt;pre&gt;\r\n      program speed\r\nc\r\nc    program to time 3 different methods of calculating\r\nc    the dot product of long vectors\r\nc\r\n      integer nrep,i\r\n      parameter (nrep=5000000)\r\n      real   b,c,cfac\r\n      common b,c,cfac\r\n      interface saxpy\r\n         function saxpy (a,x,y)\r\n            real x,y,a,saxpy\r\nc\r\nc    Declare x,y,a as input only to saxpy\r\nc\r\n            intent (in) x,y,a\r\n         end function saxpy\r\nc\r\n      end interface\r\nc\r\nc    The following is a Statement function\r\nc&lt;a name=\"sf\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      slaxpy(x,y,z)= x*y+z\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\nc\r\n      cfac=.25\r\n      b=1.\r\n      c=.1\r\nc\r\nc\r\nc    Use the Fortran 90 Intrinsic Subroutine to determine\r\nc    the current time in clock ticks (icount2), the clock\r\nc    rate in clicks per second, and the largest possible\r\nc    count before the clock resets.\r\nc\r\nc    CAUTION:  On this and probably most Unix work stations\r\nc    this clock is measuring real time, not time your program\r\nc    spends running.  If you are sharing the machine with others\r\nc    you will count the time they have the CPU also.  USE the\r\nc    unix \"users\" command to check for a situation when you are\r\nc    the only user on the machine before running the program.\r\nc    To filter out system activity run the program many times\r\nc    and select results with the lowest total times.\r\nc\r\n      call system_clock(icount1,irate,icmax)\r\nc\r\n      print *, 'clock rate = ',irate, ' ticks per second'\r\n      call system_clock(icount1,irate,icmax)\r\nc\r\nc     The \"1000\" loop just makes sure that I do lots of work\r\nc     to get good statistics.  Note that coding is set so\r\nc     results of each pass through the loop are a little\r\nc     different.  Without the \"+.00001*dotpro\" optimization\r\nc     features on many compilers will only execute the loop\r\nc     once.\r\nc\r\nc     Do a simple multiply and add many times\r\nc     I am intentially suppressing any vectorization and forcing\r\nc     a result that won't let the optimizer throw away unused\r\nc     calculations\r\nc\r\n      do 1000 i = 1,nrep\r\n         c = cfac*c +b\r\n 1000    continue\r\n      call system_clock(icount2,irate,icmax)\r\n      time = real(icount2-icount1)\/real(irate)\r\n      print *, 'Time for local evaluation = ', time,\r\n     $ ' seconds'\r\nc\r\nc    Repeat the same work using a standard function\r\nc\r\n      call system_clock(icount1,irate,icmax)\r\n      do 1001 i = 1,nrep\r\n         c = saxpy (cfac, c,b)\r\n 1001    continue\r\n      call system_clock(icount2,irate,icmax)\r\n      time = real(icount2-icount1)\/real(irate)\r\n      print *, 'Time for function evaluation = ', time,\r\n     $ ' seconds'\r\nc\r\nc    Repeat the same work using a Subroutine\r\nc\r\n      call system_clock(icount1,irate,icmax)\r\n      do 1002 i = 1,nrep\r\n         call ssaxpy(cfac,c,b,c)\r\n 1002    continue\r\n      call system_clock(icount2,irate,icmax)\r\n      time = real(icount2-icount1)\/real(irate)\r\n      print *, 'Time for Subroutine = ', time,\r\n     $ ' seconds'\r\nc\r\nc    Repeat the same work using a standard function\r\nc\r\n      call system_clock(icount1,irate,icmax)\r\n      do 1003 i = 1,nrep\r\n         c = slaxpy(cfac,c,b)\r\n 1003    continue\r\n      call system_clock(icount2,irate,icmax)\r\n      time = real(icount2-icount1)\/real(irate)\r\n      print *, 'Time for Statement Function = ', time,\r\n     $ ' seconds'\r\nc\r\nc    Repeat the same work using an internal function\r\nc\r\n      call system_clock(icount1,irate,icmax)\r\n      do 1004 i = 1,nrep\r\n         c = siaxpy(cfac,c,b)\r\n 1004    continue\r\n      call system_clock(icount2,irate,icmax)\r\n      time = real(icount2-icount1)\/real(irate)\r\n      print *, 'Time for Internal Function = ', time,\r\n     $ ' seconds'\r\nc\r\nc    Repeat the same work using a Subroutine with\r\nc    passing through COMMON\r\nc\r\n      call system_clock(icount1,irate,icmax)\r\n      do 1005 i = 1,nrep\r\n         call scsaxpy\r\n 1005    continue\r\n      call system_clock(icount2,irate,icmax)\r\n      time = real(icount2-icount1)\/real(irate)\r\n      print *, 'Time for Subroutine with COMMON = ', time,\r\n     $ ' seconds'\r\nc\r\nc    Do a baseline with just the DO loop and increment\r\nc\r\n      call system_clock(icount1,irate,icmax)\r\n      do 1006 i = 1,nrep\r\n 1006    continue\r\n      call system_clock(icount2,irate,icmax)\r\n      time = real(icount2-icount1)\/real(irate)\r\n      print *, 'Time for bare Loop = ', time,\r\n     $ ' seconds'\r\n      print *, c,i\r\n      stop\r\nc&lt;a name=\"1\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      contains\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n         function siaxpy(a1,x1,y1)\r\n         real a1,x1,y1,saxpy\r\n         siaxpy =  a1*x1 + y1\r\n         return\r\n         end function\r\n      end\r\n\r\n      function saxpy(a,x,y)\r\nc\r\nc   Multply all contents of  \"x\" by the scalar \"a\"\r\nc   then add the result to  \"y\"\r\nc\r\nc   John Mahaffy    4\/3\/96\r\nc\r\n      implicit none\r\n      real a,x,y,saxpy\r\n      intent (in) a,x,y\r\n      saxpy =  a*x + y\r\n      return\r\n      end\r\n      subroutine ssaxpy(a,x,y,z)\r\nc\r\nc   Multply all contents of  \"x\" by the scalar \"a\"\r\nc   then add the result to  \"y\"\r\nc\r\nc   John Mahaffy    4\/3\/96\r\nc\r\n      implicit none\r\n      real a,x,y,z\r\n      z     =  a*x + y\r\n      return\r\n      end\r\n      subroutine scsaxpy\r\nc\r\nc   Multply all contents of  \"c\" by the scalar \"cfac\"\r\nc   then add the result to  \"b\"\r\nc\r\nc   John Mahaffy    4\/3\/96\r\nc\r\n      implicit none\r\n      real   b,c,cfac\r\n      common b,c,cfac\r\n      c     =  cfac*c + b\r\n      return\r\n      end\r\nc&lt;\/pre&gt;\r\nc&lt;\/body&gt;\r\nc&lt;\/html&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>c&lt;html&gt; c&lt;body&gt; c&lt;pre&gt; program speed c c program to time 3 different methods of calculating c the dot product of long vectors c integer nrep,i parameter (nrep=5000000) real b,c,cfac common b,c,cfac interface saxpy function saxpy (a,x,y) real x,y,a,saxpy c c Declare x,y,a as input only to saxpy c intent (in) x,y,a end function saxpy c [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[],"tags":[],"class_list":["post-103","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/103\/revisions"}],"predecessor-version":[{"id":104,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/103\/revisions\/104"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}