diff --git a/.gitignore b/.gitignore index 801010414..79e7da401 100644 --- a/.gitignore +++ b/.gitignore @@ -138,3 +138,5 @@ vignettes/*.pdf /*_files/ # End of https://www.toptal.com/developers/gitignore/api/c,c++,r,cmake + +build/ diff --git a/CMake/FindR.cmake b/CMake/FindR.cmake new file mode 100644 index 000000000..f07d36bd3 --- /dev/null +++ b/CMake/FindR.cmake @@ -0,0 +1,25 @@ +# prepare R environment (Rcpp + RInside) +find_program(R_EXE "R") + +# search for R executable, R header file and library path +if(R_EXE) + execute_process(COMMAND ${R_EXE} RHOME + OUTPUT_VARIABLE R_ROOT_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + find_path(R_INCLUDE_DIR R.h + HINTS ${R_ROOT_DIR} + PATHS /usr/inlcude /usr/local/include /usr/share + PATH_SUFFIXES include/R R/include + ) + + find_library(R_LIBRARY R + HINTS ${R_ROOT_DIR}/lib + ) +else() + message(FATAL_ERROR "No R runtime found!") +endif() + +set(R_LIBRARIES ${R_LIBRARY}) +set(R_INCLUDE_DIRS ${R_INCLUDE_DIR}) \ No newline at end of file diff --git a/CMake/FindRInside.cmake b/CMake/FindRInside.cmake new file mode 100644 index 000000000..c7757700f --- /dev/null +++ b/CMake/FindRInside.cmake @@ -0,0 +1,23 @@ +# find RInside libraries and include path +execute_process(COMMAND echo "cat(find.package('RInside'))" + COMMAND ${R_EXE} --vanilla --slave + RESULT_VARIABLE RINSIDE_NOT_FOUND + ERROR_QUIET + OUTPUT_VARIABLE RINSIDE_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +if(RInside_NOT_FOUND) + message(FATAL_ERROR "RInside not found!") +endif() + +find_library(R_RInside_LIBRARY libRInside.so + HINTS ${RINSIDE_PATH}/lib) + +list(APPEND R_LIBRARIES ${R_RInside_LIBRARY}) + +find_path(R_RInside_INCLUDE_DIR RInside.h + HINTS ${RINSIDE_PATH} + PATH_SUFFIXES include) + +list(APPEND R_INCLUDE_DIRS ${R_RInside_INCLUDE_DIR}) \ No newline at end of file diff --git a/CMake/FindRcpp.cmake b/CMake/FindRcpp.cmake new file mode 100644 index 000000000..be88a3780 --- /dev/null +++ b/CMake/FindRcpp.cmake @@ -0,0 +1,23 @@ +# find Rcpp include directory +execute_process(COMMAND echo "cat(find.package('Rcpp'))" + COMMAND ${R_EXE} --vanilla --slave + RESULT_VARIABLE RCPP_NOT_FOUND + ERROR_QUIET + OUTPUT_VARIABLE RCPP_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +if(RCPP_NOT_FOUND) + message(FATAL_ERROR "Rcpp not found!") +endif() + +# find_library(R_Rcpp_LIBRARY Rcpp.so +# HINTS ${RCPP_PATH}/libs) + +# list(APPEND R_LIBRARIES ${R_Rcpp_LIBRARY}) + +find_path(R_Rcpp_INCLUDE_DIR Rcpp.h + HINTS ${RCPP_PATH} + PATH_SUFFIXES include) + +list(APPEND R_INCLUDE_DIRS ${R_Rcpp_INCLUDE_DIR}) \ No newline at end of file diff --git a/CMake/POET_Scripts.cmake b/CMake/POET_Scripts.cmake new file mode 100644 index 000000000..69760cc44 --- /dev/null +++ b/CMake/POET_Scripts.cmake @@ -0,0 +1,28 @@ +# Set or get version +macro(get_POET_version) + if(EXISTS ${PROJECT_SOURCE_DIR}/.git) + find_program(GIT_EXECUTABLE git DOC "git executable") + mark_as_advanced(GIT_EXECUTABLE) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE POET_GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --always + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE POET_GIT_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT POET_GIT_BRANCH STREQUAL "master") + set(POET_VERSION "${POET_GIT_BRANCH}/${POET_GIT_VERSION}") + else() + set(POET_VERSION "${POET_GIT_VERSION}") + endif() + elseif(EXISTS ${PROJECT_SOURCE_DIR}/.svn) + file(STRINGS .gitversion POET_VERSION) + else() + set(POET_VERSION "0.1") + endif() + + message(STATUS "Configuring POET version ${POET_VERSION}") +endmacro(get_POET_version) diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..3f1a0f4fb --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,31 @@ +# Version 3.9+ offers new MPI package variables +cmake_minimum_required(VERSION 3.9) + +project(POET CXX C) + +# specify the C++ standard +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + +include("CMake/POET_Scripts.cmake") +list(APPEND CMAKE_MODULE_PATH "${POET_SOURCE_DIR}/CMake") + +# set(GCC_CXX_FLAGS "-D STRICT_R_HEADERS") add_definitions(${GCC_CXX_FLAGS}) + +find_package(MPI REQUIRED) + +find_package(R REQUIRED) +find_package(Rcpp REQUIRED) +find_package(RInside REQUIRED) + +add_subdirectory(src) +add_subdirectory(R_lib) +add_subdirectory(data) + +option(BUILD_DOC "Build documentation with doxygen" ON) + +if(BUILD_DOC) + add_subdirectory(docs) +endif(BUILD_DOC) diff --git a/README.md b/README.md index 66bfabe01..3663e87dd 100644 --- a/README.md +++ b/README.md @@ -1,63 +1,201 @@ - + -# install libraries from MDL +# POET - library(devtools) - devtools::install_gitlab("delucia/RedModRphree", host="https://git.gfz-potsdam.de") - devtools::install_gitlab("delucia/Rmufits", host="https://git.gfz-potsdam.de") - -# USAGE +POET is a coupled reactive transport simulator implementing a parallel +architecture and a fast, original MPI-based Distributed Hash Table. -mpirun ./kin +## External Libraries -OPTIONS: +The following external header library is shipped with POET: ---work-package-size=<1-n> ... size of work packages (default 5) +- **argh** - https://github.com/adishavit/argh (BSD license) ---ignore-result ... disables store of simulation resuls +## Installation -DHT: +### Requirements ---dht ... enable dht (default is off) +To compile POET you need several software to be installed: ---dht-log ... enable logarithm application before rounding (default is off) +- C/C++ compiler (tested with GCC) +- MPI-Implementation (tested with OpenMPI and MVAPICH) +- R language and environment +- CMake 3.9+ ---dht-signif=<1-n> ... set rounding to number of significant digits (default 5) - (only used if no vector is given in setup file) - (for individual values per column use R vector "signif_vector" in setup file) +If you want to build documentation during compilation, `doxygen`and `graphviz` must be provided too. ---dht-strategy=<0-1> ... change dht strategy, not implemented yet (default 0, dht on workers) +The following R libraries must then be installed, which will get the needed dependencies automatically: ---dht-size=<1-n> ... size of dht per process involved (see dht-strategy) in byte (default 1GiB) +- [devtools](https://www.r-project.org/nosvn/pandoc/devtools.html) +- [Rcpp](https://cran.r-project.org/web/packages/Rcpp/index.html) +- [RInside](https://cran.r-project.org/web/packages/RInside/index.html) +- [RedModRphree](https://git.gfz-potsdam.de/delucia/RedModRphree) +- [Rmufits](https://git.gfz-potsdam.de/delucia/Rmufits) ---dht-snaps=<0-2> ... enable or disable storage of DHT snapshots - 0 = snapshots are disabled - 1 = only stores snapshot at the end of the simulation with name .dht - 2 = stores snapshot at the end and after each iteration - iteration snapshot files are stored in /iter.dht +### Compiling source code ---dht-file= ... initializes DHT with the given snapshot file +The generation of makefiles is done with CMake. If you obtained POET from git, you should be able to generate Makefiles by running -############################################################################### +```sh +mkdir build && cd build +cmake .. +``` +This will create the directory `build` and processes the CMake files and generate Makefiles from it. You're now able to run `make` to start build +process. -# about the usage of MPI_Wtime() -From the OpenMPI Man Page: +If POET was obtained from the official SVN repository or the redmine at the branch or tag to be used have to be set via -For example, on platforms that support it, the clock_gettime() function will be used -to obtain a monotonic clock value with whatever precision is supported on that platform (e.g., nanoseconds). +```sh +mkdir build && cd build +cmake -D POET_SET_BRANCH="" .. +``` -# External Libraries -Cmdline Parsing -> https://github.com/adishavit/argh +where currently available branches/tags are: +- dev -# Examples included (more to come) -1) SimDol2D.R ... simple chemistry (Calcite/Dolomite) on a 50x50 2D grid, 20 time steps -2) SimDolKtz.R ... simple chemistry (Calcite/Dolomite) on Ketzin grid (~650k elements), 20 time steps - The flow snapshots are NOT INCLUDED in svn but must be provided separately +If everything went well you'll find the executable at `build/src/poet`, but it is recommended to install the POET project structure to a desired `CMAKE_INSTALL_PREFIX` with `make install`. +During the generation of Makefiles, various options can be specified via `cmake -D