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
42 changes: 42 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 $<$<BOOL:${OpenMP_C_FOUND}>:OpenMP::OpenMP_C>)
if(CMAKE_C_COMPILER_ID MATCHES "(GNU|Clang|Intel)")
target_compile_options(stream_c PUBLIC "$<$<CONFIG:RELEASE>:${STREAM_UNIX_RELEASE_FLAGS}>")
elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
target_compile_options(stream_c PUBLIC "$<$<CONFIG:RELEASE>:${STREAM_MSVC_RELEASE_FLAGS}>")
endif()
endif()

if(CMAKE_Fortran_COMPILER)
add_executable(stream_f stream.f mysecond.c)
target_link_libraries(stream_f PRIVATE $<$<BOOL:${OpenMP_Fortran_FOUND}>:OpenMP::OpenMP_Fortran>)
if(CMAKE_Fortran_COMPILER_ID MATCHES "(GNU|Clang|Intel)")
target_compile_options(stream_f PUBLIC "$<$<CONFIG:RELEASE>:${STREAM_UNIX_RELEASE_FLAGS}>")
endif()
endif()
13 changes: 12 additions & 1 deletion mysecond.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
and without appended underscores, so it *should*
automagically link with FORTRAN */

#include <sys/time.h>
#ifndef _WIN32
# include <sys/time.h>
#else
# define WIN32_LEAN_AND_MEAN
# include <Windows.h>
#endif

double mysecond()
{
Expand All @@ -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();}
Expand Down
18 changes: 15 additions & 3 deletions stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@
/* 5. Absolutely no warranty is expressed or implied. */
/*-----------------------------------------------------------------------*/
# include <stdio.h>
# include <unistd.h>
# include <math.h>
# include <float.h>
# include <limits.h>

#ifndef _WIN32
# include <sys/time.h>
# include <unistd.h>
#else
# include <BaseTsd.h> // for SSIZE_T
typedef SSIZE_T ssize_t;
# define WIN32_LEAN_AND_MEAN
# include <Windows.h>
#endif

/*-----------------------------------------------------------------------
* INSTRUCTIONS:
Expand Down Expand Up @@ -415,16 +423,20 @@ checktick()
/* A gettimeofday routine to give access to the wall
clock timer on most UNIX-like systems. */

#include <sys/time.h>

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
Expand Down