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
51 changes: 51 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: cmake

on:
push:
paths:
- "**.c"
- "**.f"
- "**/CMakeLists.txt"
- ".github/workflows/cmake.yml"

env:
CTEST_NO_TESTS_ACTION: error


jobs:

unix:
timeout-minutes: 5

strategy:
matrix:
cc: [gcc-12, clang]
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}

env:
CC: ${{ matrix.cc }}
FC: gfortran-12

steps:
- uses: actions/checkout@v4

- run: cmake -B build

- run: cmake --build build --parallel

- run: ctest --test-dir build -V


windows-msvc:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- run: cmake -G "Visual Studio 17 2022" -B build -Dfortran=no

- run: cmake --build build --parallel --config Release

- run: ctest --test-dir build -V -C Release
69 changes: 69 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
cmake_minimum_required(VERSION 3.15)

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

enable_testing()

option(fortran "build fortran version" ON)

if(fortran)
enable_language(Fortran)
endif()

if(CMAKE_C_COMPILER_ID MATCHES "(GNU|Clang)")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-O3;-march=native;-Wall>")
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-O3;-Wall>")
if(WIN32)
add_compile_options("$<$<COMPILE_LANGUAGE:C>:/QxHost>")
else()
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-xHost>")
endif()
elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:/W3>")
endif()

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

# 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)

# --- C stream_c

add_executable(stream_c stream.c)
target_link_libraries(stream_c PRIVATE $<$<BOOL:${OpenMP_C_FOUND}>:OpenMP::OpenMP_C>)

add_test(NAME STREAM_C COMMAND stream_c)

# --- Fortran stream_f

if(fortran)
add_executable(stream_f stream.f)
target_link_libraries(stream_f PRIVATE $<$<BOOL:${OpenMP_Fortran_FOUND}>:OpenMP::OpenMP_Fortran>)

add_test(NAME STREAM_Fortran COMMAND stream_f)
endif()

# --- ignore build directory
if(NOT PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
file(GENERATE OUTPUT .gitignore CONTENT "*")
endif()
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ FFLAGS = -O2 -fopenmp

all: stream_f.exe stream_c.exe

stream_f.exe: stream.f mysecond.o
$(CC) $(CFLAGS) -c mysecond.c
stream_f.exe: stream.f
$(FC) $(FFLAGS) -c stream.f
$(FC) $(FFLAGS) stream.o mysecond.o -o stream_f.exe
$(FC) $(FFLAGS) stream.o -o stream_f.exe

stream_c.exe: stream.c
$(CC) $(CFLAGS) stream.c -o stream_c.exe
Expand Down
27 changes: 0 additions & 27 deletions mysecond.c

This file was deleted.

Loading