time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

sasum.f (3095B)


      1 !>
      2 ! @license Apache-2.0
      3 !
      4 ! Copyright (c) 2018 The Stdlib Authors.
      5 !
      6 ! Licensed under the Apache License, Version 2.0 (the "License");
      7 ! you may not use this file except in compliance with the License.
      8 ! You may obtain a copy of the License at
      9 !
     10 !    http://www.apache.org/licenses/LICENSE-2.0
     11 !
     12 ! Unless required by applicable law or agreed to in writing, software
     13 ! distributed under the License is distributed on an "AS IS" BASIS,
     14 ! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 ! See the License for the specific language governing permissions and
     16 ! limitations under the License.
     17 !<
     18 
     19 !> Computes the sum of absolute values.
     20 !
     21 ! ## Notes
     22 !
     23 ! * Modified version of reference BLAS level1 routine (version 3.7.0). Updated to "free form" Fortran 95.
     24 !
     25 ! ## Authors
     26 !
     27 ! * Univ. of Tennessee
     28 ! * Univ. of California Berkeley
     29 ! * Univ. of Colorado Denver
     30 ! * NAG Ltd.
     31 !
     32 ! ## History
     33 !
     34 ! * Jack Dongarra, linpack, 3/11/78.
     35 !
     36 !   - modified 3/93 to return if incx .le. 0.
     37 !   - modified 12/3/93, array(1) declarations changed to array(*)
     38 !
     39 ! ## License
     40 !
     41 ! From <http://netlib.org/blas/faq.html>:
     42 !
     43 ! > The reference BLAS is a freely-available software package. It is available from netlib via anonymous ftp and the World Wide Web. Thus, it can be included in commercial software packages (and has been). We only ask that proper credit be given to the authors.
     44 ! >
     45 ! > Like all software, it is copyrighted. It is not trademarked, but we do ask the following:
     46 ! >
     47 ! > * If you modify the source for these routines we ask that you change the name of the routine and comment the changes made to the original.
     48 ! >
     49 ! > * We will gladly answer any questions regarding the software. If a modification is done, however, it is the responsibility of the person who modified the routine to provide support.
     50 !
     51 ! @param {integer} N - number of values to sum
     52 ! @param {Array<real>} sx - input array
     53 ! @param {integer} stride - stride length
     54 ! @returns {real} sum of absolute values
     55 !<
     56 real function sasum( N, sx, stride )
     57   implicit none
     58   ! ..
     59   ! Scalar arguments:
     60   integer :: stride, N
     61   ! ..
     62   ! Array arguments:
     63   real :: sx(*)
     64   ! ..
     65   ! Local scalars:
     66   real :: stemp
     67   integer :: nstride, mp1, m, i
     68   ! ..
     69   ! Intrinsic functions:
     70   intrinsic abs, mod
     71   ! ..
     72   sasum = 0.0e0
     73   stemp = 0.0e0
     74   ! ..
     75   if ( N <= 0 .OR. stride <= 0 ) then
     76     return
     77   end if
     78   ! ..
     79   ! If the stride is equal to `1`, use unrolled loops...
     80   if ( stride == 1 ) then
     81     m = mod( N, 6 )
     82     ! ..
     83     ! If we have a remainder, do a clean-up loop...
     84     if ( m /= 0 ) then
     85       do i = 1, m
     86         stemp = stemp + abs( sx( i ) )
     87       end do
     88       if ( N < 6 ) then
     89         sasum = stemp
     90         return
     91       end if
     92     end if
     93     mp1 = m + 1
     94     do i = mp1, N, 6
     95       stemp = stemp + &
     96         abs( sx( i ) ) + abs( sx( i+1 ) ) + &
     97         abs( sx( i+2 ) ) + abs( sx( i+3 ) ) + &
     98         abs( sx( i+4 ) ) + abs( sx( i+5 ) )
     99     end do
    100   else
    101     nstride = N * stride
    102     do i = 1, nstride, stride
    103       stemp = stemp + abs( sx( i ) )
    104     end do
    105   end if
    106   sasum = stemp
    107   return
    108 end function sasum