Skip to content

Commit 56189c9

Browse files
svalatglesur
andauthored
Usage of ccache in the test suite (#364)
* test: add -cache option to the test script to accelerate the build * build: Add option -DIdefix_PROBLEM_DIR to allow using the standard out-of-source build way of cmake --------- Co-authored-by: Geoffroy Lesur <geoffroy.lesur@univ-grenoble-alpes.fr>
1 parent d83d694 commit 56189c9

File tree

4 files changed

+48
-15
lines changed

4 files changed

+48
-15
lines changed

.github/workflows/idefix-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ jobs:
2828
name: CPU Jobs (intel OneApi)
2929
uses: ./.github/workflows/idefix-ci-jobs.yml
3030
with:
31-
TESTME_OPTIONS: -intel -Werror
31+
TESTME_OPTIONS: -intel -Werror -ccache
3232
IDEFIX_COMPILER: icc
3333

3434
gcc-jobs:
3535
needs: Linter
3636
name: CPU Jobs (gcc)
3737
uses: ./.github/workflows/idefix-ci-jobs.yml
3838
with:
39-
TESTME_OPTIONS: -Werror
39+
TESTME_OPTIONS: -Werror -ccache
4040
IDEFIX_COMPILER: gcc
4141

4242
cuda-jobs:

CMakeLists.txt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ option(Idefix_DEBUG "Enable Idefix debug features (makes the code very slow)" OF
1616
option(Idefix_RUNTIME_CHECKS "Enable runtime sanity checks" OFF)
1717
option(Idefix_WERROR "Treat compiler warnings as errors" OFF)
1818
option(Idefix_PYTHON "Enable python bindings (requires pybind11)" OFF)
19+
set(Idefix_PROBLEM_DIR "${CMAKE_BINARY_DIR}" CACHE STRING "Problem directory to build for.")
1920
set(Idefix_CXX_FLAGS "" CACHE STRING "Additional compiler/linker flag")
2021
set(Idefix_DEFS "definitions.hpp" CACHE FILEPATH "Problem definition header file")
2122
option(Idefix_CUSTOM_EOS "Use custom equation of state" OFF)
@@ -34,7 +35,6 @@ set_property(CACHE Idefix_PRECISION PROPERTY STRINGS Double Single)
3435
set(Idefix_LOOP_PATTERN "Default" CACHE STRING "Loop pattern for idefix_for")
3536
set_property(CACHE Idefix_LOOP_PATTERN PROPERTY STRINGS Default SIMD Range MDRange TeamPolicy TeamPolicyInnerVector)
3637

37-
3838
# load git revision tools
3939
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
4040
include(GetGitRevisionDescription)
@@ -51,7 +51,7 @@ if(Kokkos_ENABLE_CUDA)
5151
endif()
5252

5353
# Add kokkos CMAKE files (required early since these set compiler options)
54-
add_subdirectory(src/kokkos build/kokkos)
54+
add_subdirectory(src/kokkos ${CMAKE_BINARY_DIR}/build/kokkos)
5555
include_directories(${Kokkos_INCLUDE_DIRS_RET})
5656

5757
# Add Idefix CXX Flags
@@ -75,20 +75,22 @@ endif()
7575
add_executable(idefix)
7676
add_subdirectory(src build)
7777

78-
if(EXISTS ${PROJECT_BINARY_DIR}/setup.cpp)
79-
target_sources(idefix PUBLIC ${PROJECT_BINARY_DIR}/setup.cpp)
78+
# make absolute
79+
get_filename_component(Idefix_PROBLEM_DIR_ABS ${Idefix_PROBLEM_DIR} ABSOLUTE BASE_DIR ${PROJECT_BINARY_DIR})
80+
81+
if(EXISTS ${Idefix_PROBLEM_DIR_ABS}/setup.cpp)
82+
target_sources(idefix PUBLIC ${Idefix_PROBLEM_DIR_ABS}/setup.cpp)
8083
else()
8184
message(WARNING "No specific setup.cpp found in the problem directory (this message can be ignored if using python to define your problem)")
8285
endif()
8386

8487
# If a CMakeLists.txt is in the problem dir (for problem-specific source files)
8588
# then read it
86-
if(EXISTS ${PROJECT_BINARY_DIR}/CMakeLists.txt)
87-
message(STATUS "Including problem-specific CMakeLists in '${PROJECT_BINARY_DIR}'")
88-
add_subdirectory(${PROJECT_BINARY_DIR} build/setup)
89+
if(EXISTS ${Idefix_PROBLEM_DIR_ABS}/CMakeLists.txt)
90+
message(STATUS "Including problem-specific CMakeLists in '${Idefix_PROBLEM_DIR_ABS}'")
91+
add_subdirectory(${Idefix_PROBLEM_DIR_ABS} build/setup)
8992
endif()
9093

91-
9294
if(Idefix_MHD)
9395
add_compile_definitions("MHD=YES")
9496
else()
@@ -210,7 +212,7 @@ if(${Idefix_PRECISION} STREQUAL "Single")
210212
endif()
211213

212214
target_include_directories(idefix PUBLIC
213-
"${PROJECT_BINARY_DIR}"
215+
"${Idefix_PROBLEM_DIR_ABS}"
214216
)
215217
target_include_directories(idefix PUBLIC
216218
src/kokkos/core/src
@@ -249,6 +251,7 @@ message(STATUS " Python: ${Idefix_PYTHON}")
249251
message(STATUS " Reconstruction: ${Idefix_RECONSTRUCTION}")
250252
message(STATUS " Precision: ${Idefix_PRECISION}")
251253
message(STATUS " Version: ${Idefix_VERSION}")
254+
message(STATUS " Problem directory: '${Idefix_PROBLEM_DIR}'")
252255
message(STATUS " Problem definitions: '${Idefix_DEFS}'")
253256
if(Idefix_CUSTOM_EOS)
254257
message(STATUS " EOS: Custom file '${Idefix_CUSTOM_EOS_FILE}'")

doc/source/reference/makefile.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ Several options can be enabled from the command line (or are accessible with ``c
5959
The number of ghost cells is automatically adjusted as a function of the order of the reconstruction scheme.
6060
*Idefix* uses 2 ghost cells when ``ORDER < 4`` and 3 ghost cells when ``ORDER = 4``
6161

62+
``-D Idefix_PROBLEM_DIR=.``
63+
Specify where to find the problem directory to build *Idefix* out of source.
64+
Place yourself in the ``build`` directory you want to build in and call the ``cmake`` by :
65+
+ pointing the *Idefix* source directory via ``IDEFIX_DIR`` as usual.
66+
+ using ``-D Idefix_PROBLEM_DIR`` to point the problem to build.
67+
6268
``-D Kokkos_ENABLE_OPENMP=ON``
6369
Enable OpenMP parallelisation on supported compilers. Note that this can be enabled simultaneously with MPI, resulting in a hybrid MPI+OpenMP compilation.
6470

pytools/idfx_test.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ def __init__ (self):
9999
help="Consider warnings as errors",
100100
action="store_true")
101101

102+
parser.add_argument("-ccache",
103+
help="Use ccache to reduce the build time over multiple run of the test suite.",
104+
action="store_true")
102105

103106
args, unknown=parser.parse_known_args()
104107

@@ -107,11 +110,19 @@ def __init__ (self):
107110
self.referenceDirectory = os.path.join(idefix_dir_env,"reference")
108111
# current directory relative to $IDEFIX_DIR/test (used to retrieve the path ot reference files)
109112
self.testDir=os.path.relpath(os.curdir,os.path.join(idefix_dir_env,"test"))
113+
# build directory, currently inside the test named build-test
114+
self.buildDir=os.path.abspath("./build-test")
115+
# store the full path of problem directory
116+
self.problemDir=os.path.abspath("./")
110117

111118
def configure(self,definitionFile=""):
112119
comm=["cmake"]
113120
# add source directory
114121
comm.append(self.idefixDir)
122+
123+
# we will build in ./build-test so problem dir is parent
124+
comm.append("-DIdefix_PROBLEM_DIR="+self.problemDir)
125+
115126
# add specific options
116127
for opt in self.cmake:
117128
comm.append("-D"+opt)
@@ -155,7 +166,7 @@ def configure(self,definitionFile=""):
155166
else:
156167
self.definitions="definitions.hpp"
157168

158-
comm.append("-DIdefix_DEFS="+self.definitions)
169+
comm.append("-DIdefix_DEFS="+os.path.join(self.problemDir, self.definitions))
159170

160171
if(self.mpi):
161172
comm.append("-DIdefix_MPI=ON")
@@ -169,19 +180,32 @@ def configure(self,definitionFile=""):
169180
elif(self.reconstruction==4):
170181
comm.append("-DIdefix_RECONSTRUCTION=Parabolic")
171182

183+
# export ccache env
184+
if self.ccache:
185+
comm.append("-DCMAKE_CXX_COMPILER_LAUNCHER=ccache")
172186

173187
try:
174-
cmake=subprocess.run(comm)
188+
# clean before configuring again
189+
self.clean()
190+
191+
# call cmake
192+
cmake=subprocess.run(comm, cwd=os.path.abspath(self.buildDir))
175193
cmake.check_returncode()
176194
except subprocess.CalledProcessError as e:
177195
print(bcolors.FAIL+"***************************************************")
178196
print("Cmake failed")
179197
print("***************************************************"+bcolors.ENDC)
180198
raise e
181199

200+
def clean(self):
201+
# remove the build directory before re-creating it
202+
if os.path.exists(self.buildDir):
203+
shutil.rmtree(self.buildDir)
204+
os.makedirs(self.buildDir, exist_ok=False)
205+
182206
def compile(self,jobs=8):
183207
try:
184-
make=subprocess.run(["make","-j"+str(jobs)])
208+
make=subprocess.run(["make","-j"+str(jobs)], cwd=os.path.abspath(self.buildDir))
185209
make.check_returncode()
186210
except subprocess.CalledProcessError as e:
187211
print(bcolors.FAIL+"***************************************************")
@@ -190,7 +214,7 @@ def compile(self,jobs=8):
190214
raise e
191215

192216
def run(self, inputFile="", np=2, nowrite=False, restart=-1):
193-
comm=["./idefix"]
217+
comm=[os.path.join(self.buildDir,"idefix")]
194218
if inputFile:
195219
comm.append("-i")
196220
comm.append(inputFile)

0 commit comments

Comments
 (0)