File: example_sum.f90

package info (click to toggle)
fortran-stdlib 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 34,008 kB
  • sloc: f90: 24,178; ansic: 1,244; cpp: 623; python: 119; makefile: 13
file content (17 lines) | stat: -rw-r--r-- 481 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
program example_sum
    use stdlib_kinds, only: sp
    use stdlib_intrinsics, only: stdlib_sum, stdlib_sum_kahan
    implicit none

    real(sp), allocatable :: x(:)
    real(sp) :: total_sum(3)

    allocate( x(1000) )
    call random_number(x)

    total_sum(1) = sum(x)       !> compiler intrinsic
    total_sum(2) = stdlib_sum(x)      !> chunked summation
    total_sum(3) = stdlib_sum_kahan(x)!> chunked kahan summation
    print *, total_sum(1:3)
    
end program example_sum