Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.15)

project(
STREAM
VERSION 1.0
DESCRIPTION "STREAM benchmark"
LANGUAGES C Fortran)

enable_testing()

if(CMAKE_C_COMPILER_ID MATCHES "(GNU|Clang)")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-O3;-march=native>")
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-O3;-xHost>")
endif()

if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:-O3;-march=native;-Werror=line-truncation>")
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:-O3;-xHost>")
endif()

# The C STREAM benchmark only requires
# stream.c
add_executable(stream_c stream.c)

add_test(NAME STREAM_C COMMAND stream_c)

# The Fortran STREAM benchmark requires
# stream.f and mysecond.o from mysecond.c
add_executable(stream_f stream.f mysecond.c)

add_test(NAME STREAM_Fortran COMMAND stream_f)

# Look for OpenMP support is found, link it to the executables
# Note that if you are using clang on macOS, you will need to
# install libomp via Homebrew and then set the following
# environment variables:
# export OpenMP_ROOT=$(brew --prefix)/opt/libomp
# see https://www.scivision.dev/cmake-openmp/ for more details

find_package(OpenMP COMPONENTS C Fortran)
target_link_libraries(stream_c PRIVATE $<$<BOOL:${OpenMP_C_FOUND}>:OpenMP::OpenMP_C>)
target_link_libraries(stream_f PRIVATE $<$<BOOL:${OpenMP_Fortran_FOUND}>:OpenMP::OpenMP_Fortran>)

# Per @scivision, ignore the build directory
# (see https://www.scivision.dev/cmake-auto-gitignore-build-dir/)
if(NOT PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
file(GENERATE OUTPUT .gitignore CONTENT "*")
endif()
16 changes: 8 additions & 8 deletions stream.f
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,8 @@ PROGRAM stream
C
INTRINSIC dble,max,min,nint,sqrt
C ..
C .. Arrays in Common ..
DOUBLE PRECISION a(ndim),b(ndim),c(ndim)
C ..
C .. Common blocks ..
* COMMON a,b,c
C .. Allocatable arrays
DOUBLE PRECISION, ALLOCATABLE :: a(:),b(:),c(:)
C ..
C .. Data statements ..
DATA avgtime/4*0.0D0/,mintime/4*1.0D+36/,maxtime/4*0.0D0/
Expand All @@ -146,6 +143,8 @@ PROGRAM stream
WRITE (*,FMT=9030) 'The *best* time for each test is used'
WRITE (*,FMT=9030) '*EXCLUDING* the first and last iterations'

ALLOCATE (a(ndim),b(ndim),c(ndim))

!$OMP PARALLEL
!$OMP MASTER
PRINT *,'----------------------------------------------'
Expand Down Expand Up @@ -233,7 +232,7 @@ PROGRAM stream
WRITE (*,FMT=9040)
DO 100 j = 1,4
avgtime(j) = avgtime(j)/dble(ntimes-1)
WRITE (*,FMT=9050) label(j),n*bytes(j)*nbpw/mintime(j)/1.0D6,
WRITE (*,FMT=9050) label(j),n/1.0D6*bytes(j)*nbpw/mintime(j),
$ avgtime(j),mintime(j),maxtime(j)
100 CONTINUE
PRINT *,'----------------------------------------------------'
Expand All @@ -244,9 +243,10 @@ PROGRAM stream
9010 FORMAT (1x,a,i10)
9020 FORMAT (1x,a,i4,a)
9030 FORMAT (1x,a,i3,a,a)
9040 FORMAT ('Function',5x,'Rate (MB/s) Avg time Min time Max time'
9040 FORMAT ('Function',7x,'Rate (MB/s)',11x,'Avg time',
$ 9x,'Min time',9x,'Max time'
$ )
9050 FORMAT (a,4 (f10.4,2x))
9050 FORMAT (a,4 (f15.4,2x))
END

*-------------------------------------
Expand Down