Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake support, use allocatable arrays in Fortran #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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>")
mathomp4 marked this conversation as resolved.
Show resolved Hide resolved
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()
9 changes: 4 additions & 5 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