Skip to content

Commit

Permalink
Benchmark refactoring for use with Jenkins Workflow Multibranch jobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
bilke committed Jan 25, 2016
1 parent 567af77 commit 4982dfe
Show file tree
Hide file tree
Showing 31 changed files with 2,551 additions and 70 deletions.
36 changes: 3 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ endif()
### General project setup ###
include(scripts/cmake/GeneralProjectSetup.cmake)

include(scripts/cmake/test/Test.cmake)

# Set default configuration when no other config is given
if (NOT (OGS_FEM OR OGS_FEM_SP OR OGS_FEM_GEMS OR OGS_FEM_PETSC_GEMS OR OGS_FEM_PQC OR OGS_FEM_IPQC OR OGS_FEM_BRNS OR OGS_FEM_CHEMAPP OR OGS_FEM_LIS OR OGS_FEM_MKL OR OGS_FEM_MPI OR OGS_FEM_PETSC OR OGS_FEM_CAP))
message (STATUS "No configuration specified. Default confuguration is used.")
set (OGS_FEM ON)
set (OGS_FEM ON CACHE BOOL "" FORCE)
endif ()

# Check if a valid OGS configuration is given (see Macros.cmake)
CHECK_CONFIG()

# Additional options
option(OGS_PYTHON "Enable python scripting interface" OFF)
option(OGS_BUILD_UTILITIES "Build additional utility programs?" OFF)
Expand Down Expand Up @@ -97,15 +96,6 @@ set (OGS_VERSION "${OGS_VERSION_MAJOR}.${OGS_VERSION_MINOR}(${OGS_RELEASE_PERSON
# should we use ISO dates: 2010-12-31 ?
set (OGS_DATE "07.07.2015")

# Check for number of processors
include(ProcessorCount)
ProcessorCount(PROCESSOR_COUNT)
if(PROCESSOR_COUNT EQUAL 0)
message(WARNING "Processor count could not be detected. Setting to one processor.")
set(PROCESSOR_COUNT 1)
else()
message(STATUS "Number of processors: ${PROCESSOR_COUNT}")
endif() # PROCESSOR_COUNT

###################
### Fem configs ###
Expand Down Expand Up @@ -320,10 +310,6 @@ add_subdirectory( OGS )
configure_file (Base/Configure.h.in ${PROJECT_BINARY_DIR}/Base/Configure.h)
configure_file (Base/BuildInfo.h.in ${PROJECT_BINARY_DIR}/Base/BuildInfo.h)

if (BENCHMARK_DIR_FOUND OR GTEST_FOUND)
enable_testing()
endif ()

if (EXAMPLEDATA_DIR_FOUND)
install (DIRECTORY ${EXAMPLEDATA_DIR_FOUND} DESTINATION . PATTERN .svn EXCLUDE)
endif ()
Expand All @@ -339,22 +325,6 @@ if (OGS_CMAKE_DEBUG)
list_all_cmake_variable_values()
endif ()

if (BENCHMARK_DIR_FOUND)
set(BENCHMARK_TIMEOUT 1800) # in s, 30 minutes timeout on normal benchmarks
set(EXCEEDING_BENCHMARK_TIMEOUT 86400) # 1 day timeout on exceeding benchmarks
string (COMPARE EQUAL "$ENV{HOSTNAME}" "dev2.intern.ufz.de" HOST_IS_DEV2)
if (${HOST_IS_DEV2})
message (STATUS "On dev2: file comparing enabled")
endif ()

file (GLOB BENCHMARK_CONFIGS "${PROJECT_SOURCE_DIR}/../benchmarks/*.cmake")
foreach (BENCHMARK_CONFIG ${BENCHMARK_CONFIGS})
include ("${BENCHMARK_CONFIG}")
endforeach()

unset (COPY_BENCHMARKS_TO_REF CACHE)
endif ()

if (OGS_BUILD_UTILITIES)
add_subdirectory (UTL/MSHGEOTOOLS/)
add_subdirectory (UTL/GIS2FEM/)
Expand Down
4 changes: 4 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node('master') {
checkout scm
load 'scripts/jenkins/linux.groovy'
}
42 changes: 21 additions & 21 deletions scripts/cmake/AddBenchmark.cmake
Original file line number Diff line number Diff line change
@@ -1,61 +1,49 @@
# This script is called from AddBenchmark in Macros.cmake
# It deletes the benchmark output files and then runs the benchmark.
if (WIN32)

separate_arguments(FILES_TO_DELETE_VARS WINDOWS_COMMAND ${FILES_TO_DELETE})
set(BENCHMARK_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/benchmarks/${benchmarkDir})
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ${BENCHMARK_OUTPUT_DIRECTORY})
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${BENCHMARK_OUTPUT_DIRECTORY})

execute_process (
COMMAND del /S /Q ${FILES_TO_DELETE_VARS}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../benchmarks)
if (WIN32)

execute_process (
COMMAND ${EXECUTABLE_OUTPUT_PATH}/Release/ogs ${benchmarkStrippedName}
COMMAND ${EXECUTABLE_OUTPUT_PATH}/Release/ogs --output-directory ${BENCHMARK_OUTPUT_DIRECTORY} ${benchmarkStrippedName}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../benchmarks/${benchmarkDir}
TIMEOUT ${BENCHMARK_TIMEOUT}
RESULT_VARIABLE EXIT_CODE)

else ()

separate_arguments(FILES_TO_DELETE_VARS UNIX_COMMAND ${FILES_TO_DELETE})

if(OGS_FEM_CONFIG STREQUAL "OGS_FEM_PETSC" OR OGS_FEM_CONFIG STREQUAL "OGS_FEM_PETSC_GEMS" OR OGS_FEM_CONFIG STREQUAL "OGS_FEM_MPI")
set(MPI_RUN_COMMAND "mpirun" "-np" "${NUM_PROCESSES}")
else()
set(MPI_RUN_COMMAND "")
endif()

execute_process (
COMMAND rm -f ${FILES_TO_DELETE_VARS}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../benchmarks)
if(OGS_PROFILE AND NOT (OGS_FEM_CONFIG STREQUAL "OGS_FEM_PETSC" OR OGS_FEM_CONFIG STREQUAL "OGS_FEM_PETSC_GEMS" OR OGS_FEM_CONFIG STREQUAL "OGS_FEM_MPI"))
message(STATUS "Profiling benchmark")
if(OGS_OUTPUT_PROFILE)
message(STATUS "Executing gprof2dot.py")
execute_process (
COMMAND ${EXECUTABLE_OUTPUT_PATH}/ogs ${benchmarkStrippedName}
COMMAND ${EXECUTABLE_OUTPUT_PATH}/ogs --output-directory ${BENCHMARK_OUTPUT_DIRECTORY} ${benchmarkStrippedName}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../benchmarks/${benchmarkDir}
TIMEOUT ${BENCHMARK_TIMEOUT}
RESULT_VARIABLE EXIT_CODE)

# Run gprof2dot.py
execute_process (
COMMAND ${GPROF_PATH} ${EXECUTABLE_OUTPUT_PATH}/ogs
COMMAND ${GPROF_PATH} ${EXECUTABLE_OUTPUT_PATH}/ogs --output-directory ${BENCHMARK_OUTPUT_DIRECTORY}
COMMAND ${PROJECT_SOURCE_DIR}/scripts/gprof2dot.py -s -n 5.0 -e 1.0
COMMAND ${DOT_TOOL_PATH} -Tpng -o ${PROJECT_SOURCE_DIR}/../benchmarks/results/${benchmarkStrippedName}.png
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../benchmarks/${benchmarkDir})

else()
execute_process (
COMMAND ${GPROF_PATH} ${EXECUTABLE_OUTPUT_PATH}/ogs ${benchmarkStrippedName}
COMMAND ${GPROF_PATH} ${EXECUTABLE_OUTPUT_PATH}/ogs --output-directory ${BENCHMARK_OUTPUT_DIRECTORY} ${benchmarkStrippedName}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../benchmarks/${benchmarkDir}
TIMEOUT ${BENCHMARK_TIMEOUT}
RESULT_VARIABLE EXIT_CODE)
endif()
else()
execute_process (
COMMAND ${MPI_RUN_COMMAND} ${EXECUTABLE_OUTPUT_PATH}/ogs ${benchmarkStrippedName}
COMMAND ${MPI_RUN_COMMAND} ${EXECUTABLE_OUTPUT_PATH}/ogs --output-directory ${BENCHMARK_OUTPUT_DIRECTORY} ${benchmarkStrippedName}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../benchmarks/${benchmarkDir}
TIMEOUT ${BENCHMARK_TIMEOUT}
RESULT_VARIABLE EXIT_CODE)
endif()

Expand All @@ -64,3 +52,15 @@ endif ()
if(EXIT_CODE GREATER 0)
message(FATAL_ERROR "Benchmark exited with code: ${EXIT_CODE}")
endif()

# Simple file compare with CMake
foreach(OUTPUT_FILE ${OUTPUT_FILES})
execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files
${PROJECT_SOURCE_DIR}/../benchmarks/${benchmarkDir}/${OUTPUT_FILE}
${BENCHMARK_OUTPUT_DIRECTORY}/${OUTPUT_FILE}
RESULT_VARIABLE EXIT_CODE)

if(EXIT_CODE GREATER 0)
message(FATAL_ERROR "Benchmark file compare of ${OUTPUT_FILE} failed.")
endif()
endforeach()
110 changes: 110 additions & 0 deletions scripts/cmake/Benchmark.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#
# AddTest
# -------
#
# Creates application test runs. Order of arguments can be arbitrary.
#
# AddTest(
# NAME <name of the the test>
# PATH <working directory> # relative to SourceDir/Tests/Data
# EXECUTABLE <executable target> # optional, defaults to ogs
# EXECUTABLE_ARGS <arguments> # files referenced in the DATA argument can be used here
# WRAPPER <time|memcheck|callgrind> # optional, defaults to time
# TESTER <diff|memcheck> # optional
# DATA <list of all required data files, white-space separated, have to be in PATH>
# )
#
# Conditional arguments:
#
# diff-tester
# - DIFF_DATA <list of files to diff>
# # the given file is compared to [filename]_expected.[extension]
#
# numdiff-tester
# - DIFF_DATA <list of files to numdiff>
# # the given file is compared to [filename]_expected.[extension]
#
# vtkdiff-tester
# - DIFF_DATA <vtk file> <data array a name> <data array b name>
# # the given data arrays in the vtk file are compared
#

function(Benchmark)

# parse arguments
set(options NONE)
set(oneValueArgs AUTHOR PATH NUM_PROCESSORS TIMEOUT)
set(multiValueArgs REQUIRED_CMAKE_OPTIONS OUTPUT_FILES)
cmake_parse_arguments(Benchmark "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

# set defaults
if(NOT Benchmark_NUM_PROCESSORS)
set(Benchmark_NUM_PROCESSORS 1)
endif()

if(NOT Benchmark_TIMEOUT)
set(Benchmark_TIMEOUT ${BENCHMARK_TIMEOUT})
endif()

# Check required CMake configuration
foreach(REQUIRED_CMAKE_OPTION ${Benchmark_REQUIRED_CMAKE_OPTIONS})
if(NOT ${REQUIRED_CMAKE_OPTION})
return()
# message("Disabling benchmark ${Benchmark_NAME} because ${REQUIRED_CMAKE_OPTION} = ${${REQUIRED_CMAKE_OPTION}}")
endif()
endforeach()

string (REGEX MATCH "[^/]+$" benchmarkStrippedName ${Benchmark_PATH})
string (LENGTH ${Benchmark_PATH} benchmarkNameLength)
string (LENGTH ${benchmarkStrippedName} benchmarkStrippedNameLength)
math (EXPR substringLength ${benchmarkNameLength}-${benchmarkStrippedNameLength})
string (SUBSTRING ${Benchmark_PATH} 0 ${substringLength} benchmarkDir)
string (REPLACE "/" "_" benchmarkNameUnderscore ${Benchmark_PATH})
string (REPLACE "_LONG_" "_" benchmarkNameUnderscore ${benchmarkNameUnderscore})
string (REPLACE "_EXCEEDING_" "_" benchmarkNameUnderscore ${benchmarkNameUnderscore})

# Adds a benchmark run. This calls AddTest.cmake to execute several steps.
add_test(
${Benchmark_AUTHOR}-${Benchmark_PATH}
${CMAKE_COMMAND}
-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
-DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR}
-DEXECUTABLE_OUTPUT_PATH=${EXECUTABLE_OUTPUT_PATH}
-DbenchmarkStrippedName=${benchmarkStrippedName}
-DbenchmarkDir=${benchmarkDir}
-DOGS_PROFILE=${OGS_PROFILE}
-DOGS_OUTPUT_PROFILE=${OGS_OUTPUT_PROFILE}
-DGPROF_PATH=${GPROF_PATH}
-DDOT_TOOL_PATH=${DOT_TOOL_PATH}
-DNUM_PROCESSES=${Benchmark_NUM_PROCESSORS}
-DOUTPUT_FILES=${Benchmark_OUTPUT_FILES}
-P ${PROJECT_SOURCE_DIR}/scripts/cmake/AddBenchmark.cmake
)
set_tests_properties(${Benchmark_AUTHOR}-${Benchmark_PATH} PROPERTIES
PROCESSORS ${Benchmark_NUM_PROCESSORS}
TIMEOUT ${Benchmark_TIMEOUT}
)

# compare file differences with python script
#if(PYTHONINTERP_FOUND)
# file (REMOVE ${PROJECT_SOURCE_DIR}/../benchmarks/results/temp/temp_${benchmarkNameUnderscore}.txt)
# foreach (entry ${OUTPUT_FILES})
# file (APPEND ${PROJECT_SOURCE_DIR}/../benchmarks/results/temp/temp_${benchmarkNameUnderscore}.txt "${entry}\n")
# endforeach ()
# add_test(
# ${Benchmark_AUTHORS}_FILECOMPARE_${Benchmark_PATH}
# ${CMAKE_COMMAND} -E chdir ${PROJECT_SOURCE_DIR}/../benchmarks/results
# ${PYTHON_EXECUTABLE}
# ${PROJECT_SOURCE_DIR}/scripts/compare.py
# temp/temp_${benchmarkNameUnderscore}.txt
# ../../benchmarks_ref/
# ${Benchmark_AUTHORS}_${benchmarkNameUnderscore}.html
# ../
# )
# set_tests_properties(${Benchmark_AUTHORS}_FILECOMPARE_${Benchmark_PATH} PROPERTIES
# DEPENDS ${Benchmark_AUTHORS}_BENCHMARK_${Benchmark_PATH})
#endif()



endfunction()
15 changes: 0 additions & 15 deletions scripts/cmake/Find.cmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
############################
### Find OGS directories ###
############################

if(DEFINED BENCHMARK_DIR)
find_path (BENCHMARK_DIR_FOUND copy.py ${BENCHMARK_DIR})
else()
find_path (BENCHMARK_DIR_FOUND copy.py ${PROJECT_SOURCE_DIR}/../benchmarks)
endif()

if(DEFINED EXAMPLEDATA_DIR)
find_path (EXAMPLEDATA_DIR_FOUND points.gli ${EXAMPLEDATA_DIR})
else()
find_path (EXAMPLEDATA_DIR_FOUND points.gli ${PROJECT_SOURCE_DIR}/../ExampleData)
endif()

if(DEFINED TESTDATA_DIR)
find_path(TESTDATA_DIR_FOUND testdata.dummy ${TESTDATA_DIR})
else()
find_path(TESTDATA_DIR_FOUND testdata.dummy ${PROJECT_SOURCE_DIR}/../testdata)
endif()

# Check if we have a git repository
set(SCM_IS_GIT OFF CACHE INTERNAL "")
Expand Down
12 changes: 11 additions & 1 deletion scripts/cmake/GeneralProjectSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@ if (OGS_BUILD_INFO)
endif () # OGS_BUILD_INFO

# This is for Configure.h which is generated later
include_directories( ${PROJECT_BINARY_DIR}/Base )
include_directories( ${PROJECT_BINARY_DIR}/Base )

# Check for number of processors
include(ProcessorCount)
ProcessorCount(PROCESSOR_COUNT)
if(PROCESSOR_COUNT EQUAL 0)
message(WARNING "Processor count could not be detected. Setting to one processor.")
set(PROCESSOR_COUNT 1)
else()
message(STATUS "Number of processors: ${PROCESSOR_COUNT}")
endif()
Loading

0 comments on commit 4982dfe

Please sign in to comment.