Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake Scripts #759

Merged
merged 13 commits into from
Jun 13, 2020
Merged
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
18 changes: 9 additions & 9 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
with:
path: 'warpx_directory/WarpX'
- name: install dependencies
run: |
set +e
Expand All @@ -24,10 +22,12 @@ jobs:
brew install openpmd-api
- name: build WarpX
run: |
cd warpx_directory
git clone --depth 1 https://bitbucket.org/berkeleylab/picsar.git
git clone --depth 1 --branch development https://github.com/AMReX-Codes/amrex.git
cd WarpX
export LDFLAGS="-lomp"
make -j 2 COMP=llvm USE_OMP=FALSE USE_OPENPMD=TRUE XTRA_CXXFLAGS="-Xpreprocessor -fopenmp"
make -j 2 COMP=llvm USE_OMP=FALSE USE_OPENPMD=TRUE XTRA_CXXFLAGS="-Xpreprocessor -fopenmp" PRECISION=FLOAT USE_SINGLE_PRECISION_PARTICLES=TRUE
mkdir build_dp && cd build_dp
cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON -DWarpX_COMPUTE=OMP -DWarpX_OPENPMD=ON -DWarpX_openpmd_internal=OFF
make -j 2

cd ..

mkdir build_sp && cd build_sp
cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON -DWarpX_COMPUTE=OMP -DWarpX_OPENPMD=ON -DWarpX_openpmd_internal=OFF -DENABLE_DP=OFF -DENABLE_DP_PARTICLES=OFF
make -j 2
20 changes: 11 additions & 9 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: 'warpx_directory/WarpX'
- name: install dependencies
run: |
export DEBIAN_FRONTEND=noninteractive
Expand All @@ -29,15 +27,19 @@ jobs:
CXX=$(which icpc) CC=$(which icc) cmake-easyinstall --prefix=/usr/local git+https://github.com/openPMD/openPMD-api.git -DopenPMD_USE_PYTHON=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF
- name: build WarpX
run: |
cd warpx_directory
git clone --depth 1 https://bitbucket.org/berkeleylab/picsar.git
git clone --depth 1 --branch development https://github.com/AMReX-Codes/amrex.git
cd WarpX
source /opt/intel/inteloneapi/setvars.sh
export CXX=$(which icpc)
export CC=$(which icc)
make -j 2 COMP=intel USE_MPI=FALSE USE_OPENPMD=TRUE
make -j 2 COMP=intel USE_MPI=FALSE USE_OPENPMD=TRUE PRECISION=FLOAT USE_SINGLE_PRECISION_PARTICLES=TRUE

mkdir build_dp && cd build_dp
cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON -DENABLE_MPI=OFF -DWarpX_COMPUTE=OMP -DWarpX_OPENPMD=ON -DWarpX_openpmd_internal=OFF
make -j 2

cd ..

mkdir build_sp && cd build_sp
cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON -DENABLE_MPI=OFF -DWarpX_COMPUTE=OMP -DWarpX_OPENPMD=ON -DWarpX_openpmd_internal=OFF -DENABLE_DP=OFF -DENABLE_DP_PARTICLES=OFF
make -j 2

build_dpcc:
name: oneAPI DPC++ SP [Linux]
Expand Down Expand Up @@ -66,7 +68,7 @@ jobs:
git clone https://github.com/openPMD/openPMD-api.git
mkdir openPMD-api/build
cd openPMD-api/build
CXX=$(which dpcpp) CC=$(which clang) cmake .. -DopenPMD_USE_PYTHON=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF
CXX=$(which dpcpp) CC=$(which clang) cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON -DopenPMD_USE_PYTHON=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF
make -j 2
sudo make install
- name: build WarpX
Expand Down
277 changes: 277 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
# Preamble ####################################################################
#
cmake_minimum_required(VERSION 3.14.0)
project(WarpX VERSION 0.20.5)

include(${WarpX_SOURCE_DIR}/cmake/WarpXFunctions.cmake)

# In-source tree builds are messy and can screw up the build system.
# Avoid building at least in the same dir as the root dir:
if(CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
message(FATAL_ERROR "Building in-source is not supported! "
"Create a build directory and remove "
"${CMAKE_SOURCE_DIR}/CMakeCache.txt ${CMAKE_SOURCE_DIR}/CMakeFiles/")
endif()


# CCache Support ##############################################################
#
# this is an optional tool that stores compiled object files; allows fast
# re-builds even with "make clean" in between. Mainly used to store AMReX
# objects
set_ccache()


# Output Directories ##########################################################
#
# temporary build directories
set_default_build_dirs()

# install directories
set_default_install_dirs()


# Options and Variants ########################################################
#
option(WarpX_OPENPMD "openPMD I/O" OFF)
option(WarpX_PSATD "spectral solver support" OFF)
option(WarpX_QED "PICSAR QED (requires Boost)" OFF)
# TODO: python, hdf5, sensei, conduit, ascent

set(WarpX_DIMS_VALUES 2 3 RZ)
set(WarpX_DIMS 3 CACHE STRING "Simulation dimensionality (2/3/RZ)")
set_property(CACHE WarpX_DIMS PROPERTY STRINGS ${WarpX_DIMS_VALUES})
if(NOT WarpX_DIMS IN_LIST WarpX_DIMS_VALUES)
message(FATAL_ERROR "WarpX_DIMS (${WarpX_DIMS}) must be one of ${WarpX_DIMS_VALUES}")
endif()

set(WarpX_PRECISION_VALUES double single)
set(WarpX_PRECISION double CACHE STRING "Floating point precision (single/double)")
set_property(CACHE WarpX_PRECISION PROPERTY STRINGS ${WarpX_PRECISION_VALUES})
if(NOT WarpX_PRECISION IN_LIST WarpX_PRECISION_VALUES)
message(FATAL_ERROR "WarpX_PRECISION (${WarpX_PRECISION}) must be one of ${WarpX_PRECISION_VALUES}")
endif()

set(WarpX_COMPUTE_VALUES NONE CUDA OMP) # HIP DPCPP
set(WarpX_COMPUTE NONE CACHE STRING "Parallel, on-node computing backend (NONE/CUDA/OMP)")
set_property(CACHE WarpX_COMPUTE PROPERTY STRINGS ${WarpX_COMPUTE_VALUES})
if(NOT WarpX_COMPUTE IN_LIST WarpX_COMPUTE_VALUES)
message(FATAL_ERROR "WarpX_PRECISION (${WarpX_COMPUTE}) must be one of ${WarpX_COMPUTE_VALUES}")
endif()

option(WarpX_amrex_internal "Download & build AMReX" ON)

# change the default build type to RelWithDebInfo (or Release) instead of Debug
set_default_build_type("RelWithDebInfo")

# this defined the variable BUILD_TESTING which is ON by default
include(CTest)


# Dependencies ################################################################
#

# AMReX
# builds AMReX from source (default) or finds an existing install
include(${WarpX_SOURCE_DIR}/cmake/dependencies/AMReX.cmake)
# suppress warnings in AMReX headers (use -isystem instead of -I)
make_third_party_includes_system(AMReX::amrex AMReX)

# PICSAR
# builds PICSAR from source
include(${WarpX_SOURCE_DIR}/cmake/dependencies/PICSAR.cmake)

# openPMD
# builds openPMD-api from source (default) or finds an existing install
include(${WarpX_SOURCE_DIR}/cmake/dependencies/openPMD.cmake)

# PSATD
if(WarpX_PSATD)
# FFTW (non-GPU) and cuFFT (GPU)
if(NOT ENABLE_CUDA)
find_package(PkgConfig REQUIRED QUIET)
if(WarpX_PRECISION STREQUAL "double")
pkg_check_modules(fftw3 REQUIRED IMPORTED_TARGET fftw3)
else()
pkg_check_modules(fftw3f REQUIRED IMPORTED_TARGET fftw3f)
endif()
endif()
# BLASPP and LAPACKPP
if(WarpX_DIMS STREQUAL RZ)
# FIXME send a couple of upstream PRs to those repos...
find_package(blaspp REQUIRED)
find_package(lapackpp REQUIRED)
find_package(OpenMP REQUIRED) # pulled by the two above
endif()
endif()


# Targets #####################################################################
#
# executable
add_executable(WarpX)
add_executable(WarpX::WarpX ALIAS WarpX)

# own headers
target_include_directories(WarpX PRIVATE
$<BUILD_INTERFACE:${WarpX_SOURCE_DIR}/Source>
)

# if we include <AMReX_buildInfo.H> we will need to call:
include(AMReXBuildInfo)
generate_buildinfo(WarpX "${WarpX_SOURCE_DIR}")

# add sources
target_sources(WarpX
PRIVATE
Source/main.cpp
Source/WarpX.cpp
)
add_subdirectory(Source/BoundaryConditions)
add_subdirectory(Source/Diagnostics)
add_subdirectory(Source/Evolve)
add_subdirectory(Source/FieldSolver)
add_subdirectory(Source/Filter)
add_subdirectory(Source/Initialization)
add_subdirectory(Source/Laser)
add_subdirectory(Source/Parallelization)
add_subdirectory(Source/Parser)
add_subdirectory(Source/Particles)
#add_subdirectory(Source/Python)
add_subdirectory(Source/Utils)

# C++ properties: at least a C++14 capable compiler is needed
target_compile_features(WarpX PUBLIC cxx_std_14)
set_target_properties(WarpX PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)

# link dependencies
# FIXME use AMReX::thirdparty::AMReX as soon as
# missing _deps/fetchedamrex-build/mod_files is solved
target_link_libraries(WarpX PUBLIC AMReX::amrex)

if(WarpX_PSATD)
if(ENABLE_CUDA)
# CUDA_ADD_CUFFT_TO_TARGET(WarpX)
target_link_libraries(WarpX PUBLIC cufft)
else()
if(WarpX_PRECISION STREQUAL "double")
target_link_libraries(WarpX PUBLIC PkgConfig::fftw3)
else()
target_link_libraries(WarpX PUBLIC PkgConfig::fftw3f)
endif()
endif()
if(WarpX_DIMS STREQUAL RZ)
# FIXME send a couple of upstream PRs to those repos...
target_link_libraries(WarpX PUBLIC blaspp)
target_link_libraries(WarpX PUBLIC lapackpp)
endif()
endif()

if(WarpX_OPENPMD)
target_compile_definitions(WarpX PUBLIC WARPX_USE_OPENPMD)
target_link_libraries(WarpX PUBLIC openPMD::openPMD)
endif()

if(WarpX_QED)
target_compile_definitions(WarpX PUBLIC WARPX_QED)
# FIXME WARPX_QED_TABLE_GEN
target_link_libraries(WarpX PUBLIC pxrmp_qed)
endif()

# AMReX helper function: propagate CUDA specific target & source properties
if(ENABLE_CUDA)
setup_target_for_cuda_compilation(WarpX)
target_compile_features(WarpX PUBLIC cuda_std_14)
set_target_properties(WarpX PROPERTIES
CUDA_EXTENSIONS OFF
CUDA_STANDARD_REQUIRED ON
)
endif()


# Defines #####################################################################
#
if(WarpX_DIMS STREQUAL 3)
target_compile_definitions(WarpX PRIVATE WARPX_DIM_3D)
elseif(WarpX_DIMS STREQUAL 2)
target_compile_definitions(WarpX PRIVATE WARPX_DIM_XZ)
elseif(WarpX_DIMS STREQUAL RZ)
target_compile_definitions(WarpX PRIVATE WARPX_DIM_RZ)
endif()

if(WarpX_OPENPMD)
target_compile_definitions(WarpX PRIVATE WARPX_USE_OPENPMD)
endif()

if(WarpX_QED)
target_compile_definitions(WarpX PRIVATE WARPX_QED)
if(WarpX_QED_TABLE_GEN)
target_compile_definitions(WarpX PRIVATE WarpX_QED_TABLE_GEN)
endif()
endif()

if(WarpX_PSATD)
target_compile_definitions(WarpX PRIVATE WARPX_USE_PSATD)
endif()


# Warnings ####################################################################
#
set_cxx_warnings()


# Generate Configuration and .pc Files ########################################
#
# these files are used if WarpX is installed and picked up by a downstream
# project (not needed yet)

#include(CMakePackageConfigHelpers)
#write_basic_package_version_file("WarpXConfigVersion.cmake"
# VERSION ${WarpX_VERSION}
# COMPATIBILITY SameMajorVersion
#)


# Installs ####################################################################
#
# headers, libraries and executables
set(WarpX_INSTALL_TARGET_NAMES WarpX)

install(TARGETS ${WarpX_INSTALL_TARGET_NAMES}
EXPORT WarpXTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

# CMake package file for find_package(WarpX::WarpX) in depending projects
#install(EXPORT WarpXTargets
# FILE WarpXTargets.cmake
# NAMESPACE WarpX::
# DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
#)
#install(
# FILES
# ${WarpX_BINARY_DIR}/WarpXConfig.cmake
# ${WarpX_BINARY_DIR}/WarpXConfigVersion.cmake
# DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
#)


# Tests #######################################################################
#

#if(BUILD_TESTING)
# enable_testing()
#
# add_test(...)
#endif()


# Status Summary for Build Options ############################################
#
warpx_print_summary()
5 changes: 5 additions & 0 deletions Source/BoundaryConditions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target_sources(WarpX
PRIVATE
PML.cpp
WarpXEvolvePML.cpp
)
17 changes: 17 additions & 0 deletions Source/Diagnostics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
target_sources(WarpX
PRIVATE
BackTransformedDiagnostic.cpp
Diagnostics.cpp
FieldIO.cpp
FullDiagnostics.cpp
MultiDiagnostics.cpp
ParticleIO.cpp
SliceDiagnostic.cpp
WarpXIO.cpp
WarpXOpenPMD.cpp
)

add_subdirectory(ComputeDiagFunctors)
add_subdirectory(FlushFormats)
add_subdirectory(ParticleDiag)
add_subdirectory(ReducedDiags)
8 changes: 8 additions & 0 deletions Source/Diagnostics/ComputeDiagFunctors/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
target_sources(WarpX
PRIVATE
CellCenterFunctor.cpp
DivBFunctor.cpp
DivEFunctor.cpp
PartPerCellFunctor.cpp
PartPerGridFunctor.cpp
)
13 changes: 13 additions & 0 deletions Source/Diagnostics/FlushFormats/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
target_sources(WarpX
PRIVATE
FlushFormatAscent.cpp
FlushFormatCheckpoint.cpp
FlushFormatPlotfile.cpp
)

if(WarpX_HAVE_OPENPMD)
target_sources(WarpX
PRIVATE
FlushFormatOpenPMD.cpp
)
endif()
Loading