From 973f228c39b50ab0b153adba489911354f9ecd65 Mon Sep 17 00:00:00 2001 From: Ronny Brendel Date: Fri, 22 Mar 2024 13:26:04 +0100 Subject: [PATCH 1/2] add cmake --- CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9e39c9f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,42 @@ +cmake_minimum_required (VERSION 3.13) + +project(stream) + +include(CheckLanguage) + +check_language(C) +if(CMAKE_C_COMPILER) + enable_language(C) +endif() + +check_language(Fortran) +if(CMAKE_Fortran_COMPILER) + enable_language(Fortran) +endif() + +find_package(OpenMP COMPONENTS C Fortran) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +set(STREAM_UNIX_RELEASE_FLAGS "-O2") +set(STREAM_MSVC_RELEASE_FLAGS "/O2") + +if(CMAKE_C_COMPILER) + add_executable(stream_c stream.c) + target_link_libraries(stream_c PRIVATE $<$:OpenMP::OpenMP_C>) + if(CMAKE_C_COMPILER_ID MATCHES "(GNU|Clang|Intel)") + target_compile_options(stream_c PUBLIC "$<$:${STREAM_UNIX_RELEASE_FLAGS}>") + elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC") + target_compile_options(stream_c PUBLIC "$<$:${STREAM_MSVC_RELEASE_FLAGS}>") + endif() +endif() + +if(CMAKE_Fortran_COMPILER) + add_executable(stream_f stream.f mysecond.c) + target_link_libraries(stream_f PRIVATE $<$:OpenMP::OpenMP_Fortran>) + if(CMAKE_Fortran_COMPILER_ID MATCHES "(GNU|Clang|Intel)") + target_compile_options(stream_f PUBLIC "$<$:${STREAM_UNIX_RELEASE_FLAGS}>") + endif() +endif() \ No newline at end of file From f806a6d6ce0cb85b1961817623008e73abb9f8fc Mon Sep 17 00:00:00 2001 From: Ronny Brendel Date: Fri, 22 Mar 2024 13:28:05 +0100 Subject: [PATCH 2/2] add basic Windows support --- mysecond.c | 13 ++++++++++++- stream.c | 18 +++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/mysecond.c b/mysecond.c index d206a4a..d3c7d8b 100644 --- a/mysecond.c +++ b/mysecond.c @@ -5,7 +5,12 @@ and without appended underscores, so it *should* automagically link with FORTRAN */ -#include +#ifndef _WIN32 +# include +#else +# define WIN32_LEAN_AND_MEAN +# include +#endif double mysecond() { @@ -15,12 +20,18 @@ double mysecond() struct timezone { int tz_minuteswest; int tz_dsttime; }; */ +#ifndef _WIN32 struct timeval tp; struct timezone tzp; int i; i = gettimeofday(&tp,&tzp); return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 ); +#else + __int64 t; + GetSystemTimeAsFileTime((FILETIME*)&t); + return ((double)(t - 116444736000000000LL)) / 10000000.0; +#endif } double mysecond_() {return mysecond();} diff --git a/stream.c b/stream.c index 9bbd6ce..c156813 100644 --- a/stream.c +++ b/stream.c @@ -41,11 +41,19 @@ /* 5. Absolutely no warranty is expressed or implied. */ /*-----------------------------------------------------------------------*/ # include -# include # include # include # include + +#ifndef _WIN32 # include +# include +#else +# include // for SSIZE_T +typedef SSIZE_T ssize_t; +# define WIN32_LEAN_AND_MEAN +# include +#endif /*----------------------------------------------------------------------- * INSTRUCTIONS: @@ -415,16 +423,20 @@ checktick() /* A gettimeofday routine to give access to the wall clock timer on most UNIX-like systems. */ -#include - double mysecond() { +#ifndef _WIN32 struct timeval tp; struct timezone tzp; int i; i = gettimeofday(&tp,&tzp); return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 ); +#else + __int64 t; + GetSystemTimeAsFileTime((FILETIME*)&t); + return ((double)(t - 116444736000000000LL)) / 10000000.0; +#endif } #ifndef abs