Skip to content

Commit

Permalink
CMake: add support for 3D nodal projection.
Browse files Browse the repository at this point in the history
Add support for Algoim and Blitz libraries if nodal projection is
required. CMake will download and install these libraries if
no installation paths is given for them.
  • Loading branch information
mic84 committed Nov 7, 2018
1 parent 6475a69 commit 266b169
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 36 deletions.
41 changes: 26 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
cmake_minimum_required (VERSION 3.5)


project (AMReX)

enable_language (C)
enable_language (CXX)
enable_language (Fortran)


#
# Load required modules
#
set ( AMREX_CMAKE_MODULES_PATH "${CMAKE_CURRENT_LIST_DIR}/Tools/CMake" CACHE INTERNAL "" )
set ( CMAKE_MODULE_PATH ${AMREX_CMAKE_MODULES_PATH} )

include ( AMReX_Utils )

include ( AMReX_Options )

include ( AMReX_Machines )

#
# Set CMAKE_<LANG>_FLAGS_<CONFIG> if not already defined
#
set_default_config_flags ()
set( AMREX_CMAKE_MODULES_PATH "${CMAKE_CURRENT_LIST_DIR}/Tools/CMake" CACHE INTERNAL "" )
set( CMAKE_MODULE_PATH ${AMREX_CMAKE_MODULES_PATH} )

#
# Provide a default install directory
Expand All @@ -33,6 +20,18 @@ if ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
CACHE PATH "AMReX installation directory" FORCE)
endif ()

#
# Include options, utilities and other stuff we need
#
include( AMReX_Utils )
include( AMReX_Options )
include( AMReX_Machines )

#
# Set CMAKE_<LANG>_FLAGS_<CONFIG> if not already defined
#
set_default_config_flags ()

#
# Set variable for AMReX versioning
#
Expand All @@ -58,6 +57,18 @@ endif ()
set ( AMREX_GIT_VERSION "${TMP}" CACHE INTERNAL "" )
unset (TMP)

#
# Install Blitz and Algoim at configuration time
# if needed.
# This is only required if ENABLE_3D_NODAL_MLMG is ON
# and external libraries paths are not given
#
if ( ENABLE_3D_NODAL_MLMG AND
NOT ( ALGOIM_INSTALL_DIR AND BLITZ_INSTALL_DIR ) )
include(AMReX_InstallExternalLibs)
endif ()


#
# Source files for all binaries and libraries found under src
#
Expand Down
6 changes: 5 additions & 1 deletion Src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ if (ENABLE_PROFPARSER)
endif ()

if (ENABLE_LINEAR_SOLVERS)
include (LinearSolvers/CMakeLists.txt)
include(LinearSolvers/CMakeLists.txt)
endif ()

if (ENABLE_3D_NODAL_MLMG)
include(Extern/Algoim/CMakeLists.txt)
endif ()

if (ENABLE_FORTRAN_INTERFACES)
Expand Down
1 change: 1 addition & 0 deletions Src/Extern/Algoim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_sources(AMReX_algoim_integrals.cpp AMReX_algoim_integrals.H)
31 changes: 21 additions & 10 deletions Tools/CMake/AMReX_Compilers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ function ( set_amrex_compiler_flags )
endif ()

#
# Set REQUIRED fortran flags (only amrdata needs this)
# Set REQUIRED fortran flags
#
target_compile_options ( amrex
PRIVATE
# GNU
$<$<STREQUAL:"${CMAKE_Fortran_COMPILER_ID}","GNU">:$<$<COMPILE_LANGUAGE:Fortran>:
-ffixed-line-length-none>>
-ffixed-line-length-none -ffree-line-length-none >>
# Intel
$<$<STREQUAL:"${CMAKE_Fortran_COMPILER_ID}","Intel">:$<$<COMPILE_LANGUAGE:Fortran>:
-extend_source>>
Expand Down Expand Up @@ -118,14 +118,25 @@ function ( set_amrex_compiler_flags )
# C++ REQUIRED flags
# Until "cxx_std_11" and similar options are available (CMake >= 3.8 )
# add c++11 support manually in order to have transitive property
target_compile_options ( amrex
PUBLIC
$<$<CXX_COMPILER_ID:Cray>:$<$<COMPILE_LANGUAGE:CXX>:-h std=c++11 -h list=a>>
$<$<CXX_COMPILER_ID:PGI>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>>
$<$<CXX_COMPILER_ID:Clang>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>>
$<$<CXX_COMPILER_ID:AppleClang>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>>
$<$<CXX_COMPILER_ID:GNU>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>>
$<$<CXX_COMPILER_ID:Intel>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>> )
if (NOT ENABLE_3D_NODAL_MLMG)
target_compile_options ( amrex
PUBLIC
$<$<CXX_COMPILER_ID:Cray>:$<$<COMPILE_LANGUAGE:CXX>:-h std=c++11 -h list=a>>
$<$<CXX_COMPILER_ID:PGI>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>>
$<$<CXX_COMPILER_ID:Clang>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>>
$<$<CXX_COMPILER_ID:AppleClang>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>>
$<$<CXX_COMPILER_ID:GNU>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>>
$<$<CXX_COMPILER_ID:Intel>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>> )
else ()
target_compile_options ( amrex
PUBLIC
$<$<CXX_COMPILER_ID:Cray>:$<$<COMPILE_LANGUAGE:CXX>:-h std=c++14 -h list=a>>
$<$<CXX_COMPILER_ID:PGI>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++14>>
$<$<CXX_COMPILER_ID:Clang>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++14>>
$<$<CXX_COMPILER_ID:AppleClang>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++14>>
$<$<CXX_COMPILER_ID:GNU>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++14>>
$<$<CXX_COMPILER_ID:Intel>:$<$<COMPILE_LANGUAGE:CXX>:-std=c++14>> )
endif ()


#
Expand Down
34 changes: 25 additions & 9 deletions Tools/CMake/AMReX_Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ function (configure_amrex)
#
# Include the required modules
#
include ( AMReX_ThirdPartyProfilers )
include ( AMReX_Defines )
include ( AMReX_Compilers )
include ( AMReX_Utils )
include( AMReX_ThirdPartyProfilers )
include( AMReX_Defines )
include( AMReX_Compilers )
include( AMReX_Utils )
include( AMReX_ThirdPartyLibraries )

#
# Set properties for target "amrex"
Expand All @@ -46,8 +47,9 @@ function (configure_amrex)
set_target_properties ( amrex PROPERTIES POSITION_INDEPENDENT_CODE True )
endif ()


#
# Location for Fortran modules
# Location of Fortran modules
#
set ( AMREX_Fortran_MODULE_DIR ${PROJECT_BINARY_DIR}/mod_files )

Expand Down Expand Up @@ -120,14 +122,28 @@ function (configure_amrex)
strip (OpenMP_CXX_FLAGS)
target_link_libraries ( amrex PUBLIC ${OpenMP_CXX_FLAGS} )
else ()
# Cray compiler has OMP turned on by default
target_compile_options ( amrex PUBLIC $<$<CXX_COMPILER_ID:Cray>:-h;noomp> $<$<C_COMPILER_ID:Cray>:-h;noomp> )
# Cray compiler has OMP turned on by default
target_compile_options ( amrex PUBLIC $<$<CXX_COMPILER_ID:Cray>:-h;noomp> $<$<C_COMPILER_ID:Cray>:-h;noomp> )
endif()


#
# Add third party libraries
#
if (ENABLE_3D_NODAL_MLMG)
# Add Algoim dependency
# add_dependencies(amrex algoim)
target_include_directories( amrex PRIVATE ${ALGOIM_INSTALL_DIR}/src )
# Blitz dependency
# add_dependencies( amrex blitz )
target_include_directories( amrex PRIVATE ${BLITZ_INSTALL_DIR}/include )
target_link_libraries( amrex PUBLIC ${BLITZ_INSTALL_DIR}/lib/libblitz.a)
# add_amrex_third_party_libraries()
endif()

#
# Setup third-party profilers
#
set_amrex_profilers ()
set_amrex_profilers()

#
# Setup SENSEI
Expand Down
5 changes: 4 additions & 1 deletion Tools/CMake/AMReX_Defines.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ function ( set_amrex_defines )
endif ()
endif ()

# External libraries for nodal MLMG
add_amrex_define( USE_ALGOIM IF ENABLE_3D_NODAL_MLMG)

# Assertions
add_amrex_define( AMREX_USE_ASSERTION IF ENABLE_ASSERTIONS )
add_amrex_define( AMREX_USE_EB IF ENABLE_EB )
Expand Down Expand Up @@ -151,7 +154,7 @@ function ( set_amrex_defines )
add_amrex_define( AMREX_FORT_USE_${FORTLINK} )

# SENSEI Insitu
add_amrex_define ( AMREX_USE_SENSEI_INSITU IF ENABLE_SENSEI_INSITU )
add_amrex_define( AMREX_USE_SENSEI_INSITU IF ENABLE_SENSEI_INSITU )

endfunction ()

Expand Down
123 changes: 123 additions & 0 deletions Tools/CMake/AMReX_InstallExternalLibs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
set(EXTERNAL_LIBS_PATH ${CMAKE_BINARY_DIR}/external)
file(MAKE_DIRECTORY ${EXTERNAL_LIBS_PATH})

#
# Build and install blitz if required
#
if (NOT BLITZ_INSTALL_DIR)

set(BLITZ_REPO https://github.com/blitzpp/blitz.git )
set(BLITZ_GIT_TAG 0d5d1feaad1b1b31aa9881da00bad68f7036ff63 )
set(BLITZ_ROOT_DIR ${EXTERNAL_LIBS_PATH}/blitz )
set(BLITZ_INSTALL_DIR ${BLITZ_ROOT_DIR}/installdir CACHE PATH
"Path to Blitz installation directory")

# Configure command
set(BLITZ_CONFIG_COMMAND
CC=${CMAKE_C_COMPILER}
FC=${CMAKE_Fortran_COMPILER}
CXX=${CMAKE_CXX_COMPILER}
./configure --prefix=${BLITZ_INSTALL_DIR}
)
# if (DDEBUG)
# set(BLITZ_CONFIGURE_COMMAND ${BLITZ_CONFIGURE_COMMAND} --enable-debug)
# else ()
# set(BLITZ_CONFIGURE_COMMAND ${BLITZ_CONFIGURE_COMMAND} --enable-optimize)
# endif ()

# Clone
message(STATUS "Cloning Blitz")
execute_process(
COMMAND git clone -q ${BLITZ_REPO} # -q to have it quiet
WORKING_DIRECTORY ${EXTERNAL_LIBS_PATH}
RESULT_VARIABLE RVAR
OUTPUT_QUIET
)

if (NOT "${RVAR}" STREQUAL "0")
message(FATAL_ERROR "Fatal error when cloning BLITZ repo")
endif()

# Configure
message(STATUS "Configuring Blitz")
execute_process(
COMMAND git checkout ${BLITZ_GIT_TAG}
COMMAND autoreconf -fiv
OUTPUT_FILE ${BLITZ_ROOT_DIR}/cmake_autoreconf.log
ERROR_FILE ${BLITZ_ROOT_DIR}/cmake_autoreconf.error
WORKING_DIRECTORY ${BLITZ_ROOT_DIR}
RESULT_VARIABLE RVAR
)

if (NOT "${RVAR}" STREQUAL "0")
message(FATAL_ERROR "Fatal error when running autoreconf for BLITZ ")
endif()

execute_process(
COMMAND ${BLITZ_ROOT_DIR}/configure --prefix=${BLITZ_INSTALL_DIR}
OUTPUT_FILE ${BLITZ_ROOT_DIR}/cmake_configure.log
ERROR_FILE ${BLITZ_ROOT_DIR}/cmake_configure.error
WORKING_DIRECTORY ${BLITZ_ROOT_DIR}
RESULT_VARIABLE RVAR
)

if (NOT "${RVAR}" STREQUAL "0")
message(FATAL_ERROR "Fatal error when running configure for BLITZ ")
endif()

# Install
message(STATUS "Installing Blitz")
execute_process(
COMMAND make install
OUTPUT_FILE ${BLITZ_ROOT_DIR}/cmake_install.log
ERROR_FILE ${BLITZ_ROOT_DIR}/cmake_install.error
WORKING_DIRECTORY ${BLITZ_ROOT_DIR}
RESULT_VARIABLE RVAR
)

if (NOT "${RVAR}" STREQUAL "0")
message(FATAL_ERROR "Fatal error when installing BLITZ ")
endif()

endif()


#
# Download algoim if required
#
if (NOT ALGOIM_INSTALL_DIR)

set(ALGOIM_REPO https://github.com/algoim/algoim.git )
set(ALGOIM_GIT_TAG a3d0b7bb2872cd414f77dbe7e77b25b9e707eaf3 )
set(ALGOIM_INSTALL_DIR ${EXTERNAL_LIBS_PATH}/algoim CACHE PATH
"Path to Algoim installation directory")

# Clone
message(STATUS "Cloning Algoim")
execute_process(
COMMAND git clone -q ${ALGOIM_REPO} # -q to have it quiet
WORKING_DIRECTORY ${EXTERNAL_LIBS_PATH}/
RESULT_VARIABLE RVAR
OUTPUT_QUIET
)

if (NOT "${RVAR}" STREQUAL "0")
message(FATAL_ERROR "Fatal error when cloning ALGOIM repo")
endif()

# Fix source code
execute_process(
COMMAND sed -i /tinyvec-et.h/d ${ALGOIM_INSTALL_DIR}/src/algoim_blitzinc.hpp
WORKING_DIRECTORY ${ALGOIM_INSTALL_DIR}
RESULT_VARIABLE RVAR
OUTPUT_QUIET
)

if (NOT "${RVAR}" STREQUAL "0")
message(FATAL_ERROR "Fatal error when fixing ALGOIM source code")
endif()

endif ()

set( BLITZ_INSTALL_DIR "" CACHE PATH
"Path to Blitz installation directory (leave empty for superbuild)")
17 changes: 17 additions & 0 deletions Tools/CMake/AMReX_Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,23 @@ endif ()
option ( ENABLE_SENSEI_INSITU "Enable SENSEI in situ infrastructure" OFF )
print_option ( ENABLE_SENSEI_INSITU )

if (ENABLE_LINEAR_SOLVERS AND (DIM EQUAL 3) AND (NOT USE_XSDK_DEFAULTS) )
option(ENABLE_3D_NODAL_MLMG "Enable 3D nodal MLMG" OFF)
print_option(ENABLE_3D_NODAL_MLMG)
else ()
set(ENABLE_3D_NODAL_MLMG OFF)
endif ()

#
# This options are paths to external libraries installation directories
#
if (USE_XSDK_DEFAULTS)
set( ALGOIM_INSTALL_DIR "" CACHE PATH
"Path to Algoim installation directory")
set( BLITZ_INSTALL_DIR "" CACHE PATH
"Path to Blitz installation directory")
endif ()

#
# Compilation options
#
Expand Down

0 comments on commit 266b169

Please sign in to comment.