Skip to content

Commit 626423c

Browse files
committed
Merge PR #197 into development
* upstream/pr/197/head: config: Add `get_rank()` helper. When building with MPI, build all tests/examples. build: Enable pfasst_WITH_MPI by default. Signed-off-by: Torbjörn Klatt <[email protected]>
2 parents 40c36e8 + f297bdf commit 626423c

File tree

11 files changed

+182
-189
lines changed

11 files changed

+182
-189
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ option(pfasst_BUILD_EXAMPLES "Build example programs."
1919
CMAKE_DEPENDENT_OPTION(pfasst_INSTALL_EXAMPLES "Install example programs." ON
2020
"pfasst_BUILD_EXAMPLES" OFF)
2121
option(pfasst_BUILD_TESTS "Build test suite for PFASST." ON )
22-
option(pfasst_WITH_MPI "Build with MPI enabled." OFF)
22+
option(pfasst_WITH_MPI "Build with MPI enabled." ON )
2323
option(pfasst_WITH_GCC_PROF "Enable excessive debugging & profiling output with GCC." OFF)
2424
option(pfasst_DEFAULT_RAND_SEED "Using a hardcoded random seed" ON )
2525

2626
if(${pfasst_WITH_MPI})
2727
find_package(MPI REQUIRED)
28-
if(NOT "${CMAKE_CXX_COMPILER}" STREQUAL "${MPI_CXX_COMPILER}" OR
28+
if(NOT "${CMAKE_CXX_COMPILER}" STREQUAL "${MPI_CXX_COMPILER}" OR
2929
NOT "${CMAKE_C_COMPILER}" STREQUAL "${MPI_C_COMPILER}")
3030
message(STATUS "C++ Compiler: ${CMAKE_CXX_COMPILER}")
3131
message(STATUS "MPI C++ Compiler Wrapper: ${MPI_CXX_COMPILER}")

examples/advection_diffusion/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if(${pfasst_WITH_MPI})
1919
set(advec_mpi_examples
2020
mpi_pfasst
2121
)
22-
set(all_advec_examples ${advec_mpi_examples})
22+
set(all_advec_examples ${advec_examples} ${advec_mpi_examples})
2323
else()
2424
set(all_advec_examples ${advec_examples})
2525
endif()

examples/scalar/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ include_directories(
66
${3rdparty_INCLUDES}
77
)
88

9-
if(NOT ${pfasst_WITH_MPI})
10-
set(scalar_examples
11-
scalar_sdc
12-
)
13-
endif()
9+
set(scalar_examples
10+
scalar_sdc
11+
)
1412

1513
foreach(example ${scalar_examples})
1614
add_executable(${example} ${CMAKE_CURRENT_SOURCE_DIR}/${example}.cpp)

examples/vanderpol/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ include_directories(
66
${3rdparty_INCLUDES}
77
)
88

9-
if(NOT ${pfasst_WITH_MPI})
10-
set(vanderpol_examples
11-
vdp_sdc
12-
)
13-
endif()
9+
set(vanderpol_examples
10+
vdp_sdc
11+
)
1412

1513
foreach(example ${vanderpol_examples})
1614
add_executable(${example} ${CMAKE_CURRENT_SOURCE_DIR}/${example}.cpp)

include/pfasst/config.hpp

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ namespace pfasst
2626
*/
2727
namespace config
2828
{
29+
/**
30+
* Get MPI rank during initialization.
31+
*
32+
* When running without MPI (ie, without using mpirun/mpiexec), returns 0. When running with
33+
* MPI, returns the MPI rank.
34+
*
35+
* If the user is running with MPI and MPI_Init hasn't been called yet, this will return 0. I
36+
* hope this is rare.
37+
*/
38+
int get_rank()
39+
{
40+
#ifdef WITH_MPI
41+
int initialized = 0, rank = 0;
42+
// if we're not running under "mpirun/mpiexec", just assume rank 0.
43+
MPI_Initialized(&initialized);
44+
if (initialized) {
45+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
46+
}
47+
return rank;
48+
#else
49+
return 0;
50+
#endif
51+
}
52+
2953
/**
3054
* Runtime config options provider.
3155
*
@@ -76,7 +100,7 @@ namespace pfasst
76100
* @param[in] option Name of the command line parameter.
77101
* It is possible to specify a long and optional short option name by comma-separation.
78102
* Short option names are identified by being only a single character.
79-
* They are automatically parsed as '`-[SHORT]`' by `boost::program_options` in contrast
103+
* They are automatically parsed as '`-[SHORT]`' by `boost::program_options` in contrast
80104
* to '`--[LONG]`'.
81105
* @param[in] help help text to be displayed in the help and usage information
82106
*/
@@ -90,7 +114,7 @@ namespace pfasst
90114
* @param[in] option Name of the command line parameter.
91115
* It is possible to specify a long and optional short option name by comma-separation.
92116
* Short option names are identified by being only a single character.
93-
* They are automatically parsed as '`-[SHORT]`' by `boost::program_options` in contrast
117+
* They are automatically parsed as '`-[SHORT]`' by `boost::program_options` in contrast
94118
* to '`--[LONG]`'.
95119
* @param[in] help help text to be displayed in the help and usage information
96120
*
@@ -193,21 +217,11 @@ namespace pfasst
193217
po::store(parsed, options::get_instance().get_variables_map());
194218
po::notify(options::get_instance().get_variables_map());
195219

196-
#ifdef WITH_MPI
197-
int initialized = 0;
198-
MPI_Initialized(&initialized);
199-
assert((bool)initialized);
200-
int rank = 0;
201-
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
202-
#endif
203220
if (options::get_instance().get_variables_map().count("help")) {
204-
#ifdef WITH_MPI
205-
if (rank == 0) {
206-
#endif
221+
if (get_rank() == 0) {
207222
cout << print_help() << endl;
208-
#ifdef WITH_MPI
209223
}
210-
#endif
224+
211225
if (exit_on_help) {
212226
#ifdef WITH_MPI
213227
MPI_Finalize();
@@ -263,7 +277,7 @@ namespace pfasst
263277
options::add_option<double>("Duration", "tend", "final time of simulation");
264278
options::add_option<size_t>("Duration", "num_steps", "number time steps");
265279
options::add_option<size_t>("Duration", "num_iter", "number of iterations");
266-
280+
267281
options::add_option<size_t>("Quadrature", "num_nodes", "number of quadrature nodes");
268282

269283
options::add_option<double>("Tolerances", "abs_res_tol", "absolute residual tolerance");

include/pfasst/logging.hpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ namespace pfasst
166166
* - `VLOG` - the verbose logging levels are used as follows:
167167
* - 0 to 8
168168
* - 9 for function enter and exit messages (cfg. @ref VLOG_FUNC_START and @ref VLOG_FUNC_END)
169-
*
169+
*
170170
* @see [easylogging++](https://github.com/easylogging/easyloggingpp)
171171
*/
172172
namespace log
@@ -213,12 +213,7 @@ namespace pfasst
213213
const string POSITION = "%fbase:%line";
214214
const string MESSAGE = "%msg";
215215
#ifdef WITH_MPI
216-
int initialized = 0;
217-
MPI_Initialized(&initialized);
218-
assert((bool)initialized);
219-
int rank = 0;
220-
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
221-
216+
const int rank = pfasst::config::get_rank();
222217
ostringstream frmter;
223218
frmter << std::setw(3) << rank;
224219
const string MPI_RANK = ", rank " + frmter.str();
@@ -290,11 +285,7 @@ namespace pfasst
290285
defaultConf.setGlobally(el::ConfigurationType::ToStandardOutput, "false");
291286
}
292287
#ifdef WITH_MPI
293-
int initialized = 0;
294-
MPI_Initialized(&initialized);
295-
assert((bool)initialized);
296-
int rank = 0;
297-
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
288+
int rank = pfasst::config::get_rank();
298289
defaultConf.setGlobally(el::ConfigurationType::ToFile, "true");
299290
defaultConf.setGlobally(el::ConfigurationType::Filename,
300291
string("mpi_run_") + to_string(rank) + string(".log"));

tests/CMakeLists.txt

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,35 @@ include_directories(
66
${CMAKE_CURRENT_SOURCE_DIR}
77
)
88

9-
if(NOT ${pfasst_WITH_MPI})
10-
set(TESTS
11-
test_quadrature
12-
test_polynomial
13-
)
9+
set(TESTS
10+
test_quadrature
11+
test_polynomial
12+
)
1413

15-
foreach(test ${TESTS})
16-
message(STATUS " ${test}")
17-
add_executable(${test} ${test}.cpp)
18-
if(${pfasst_NUM_DEPENDEND_TARGETS} GREATER 0)
19-
add_dependencies(${test} ${pfasst_DEPENDEND_TARGETS})
20-
endif()
21-
if(${pfasst_TESTS_NUM_DEPENDEND_TARGETS} GREATER 0)
22-
add_dependencies(${test} ${pfasst_TESTS_DEPENDEND_TARGETS})
23-
endif()
24-
target_link_libraries(${test}
25-
${3rdparty_DEPENDEND_LIBS}
26-
${TESTS_3rdparty_DEPENDEND_LIBS}
27-
${pfasst_DEPENDEND_LIBS}
28-
)
29-
if(pfasst_WITH_GCC_PROF AND ${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
30-
set_target_properties(${test}
31-
PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs"
32-
LINK_FLAGS "-fprofile-arcs"
33-
)
34-
endif()
35-
add_test(NAME ${test}
36-
COMMAND ${CMAKE_BINARY_DIR}/tests/${test} --gtest_output=xml:${test}_out.xml
14+
foreach(test ${TESTS})
15+
message(STATUS " ${test}")
16+
add_executable(${test} ${test}.cpp)
17+
if(${pfasst_NUM_DEPENDEND_TARGETS} GREATER 0)
18+
add_dependencies(${test} ${pfasst_DEPENDEND_TARGETS})
19+
endif()
20+
if(${pfasst_TESTS_NUM_DEPENDEND_TARGETS} GREATER 0)
21+
add_dependencies(${test} ${pfasst_TESTS_DEPENDEND_TARGETS})
22+
endif()
23+
target_link_libraries(${test}
24+
${3rdparty_DEPENDEND_LIBS}
25+
${TESTS_3rdparty_DEPENDEND_LIBS}
26+
${pfasst_DEPENDEND_LIBS}
27+
)
28+
if(pfasst_WITH_GCC_PROF AND ${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
29+
set_target_properties(${test}
30+
PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs"
31+
LINK_FLAGS "-fprofile-arcs"
3732
)
38-
endforeach(test)
39-
endif()
33+
endif()
34+
add_test(NAME ${test}
35+
COMMAND ${CMAKE_BINARY_DIR}/tests/${test} --gtest_output=xml:${test}_out.xml
36+
)
37+
endforeach(test)
4038

4139
if(${pfasst_BUILD_EXAMPLES})
4240
add_subdirectory(examples)

tests/examples/advection_diffusion/CMakeLists.txt

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,37 @@ if(${pfasst_WITH_MPI})
4242
COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ${CMAKE_BINARY_DIR}/tests/examples/advection_diffusion/${test} --gtest_output=xml:${test}_out.xml
4343
)
4444
endforeach(test)
45-
else()
46-
set(TESTS
47-
test_advection_diffusion
48-
)
45+
endif()
4946

50-
foreach(test ${TESTS})
51-
message(STATUS " ${test}")
52-
add_executable(${test} ${test}.cpp)
53-
if(NOT FFTW_FOUND)
54-
add_dependencies(${test} fftw3)
55-
endif()
56-
if(${pfasst_NUM_DEPENDEND_TARGETS} GREATER 0)
57-
add_dependencies(${test} ${pfasst_DEPENDEND_TARGETS})
58-
endif()
59-
if(${pfasst_TESTS_NUM_DEPENDEND_TARGETS} GREATER 0)
60-
add_dependencies(${test} ${pfasst_TESTS_DEPENDEND_TARGETS})
61-
endif()
62-
target_link_libraries(${test}
63-
${3rdparty_DEPENDEND_LIBS}
64-
${TESTS_3rdparty_DEPENDEND_LIBS}
65-
${FFTW_LIBRARIES}
66-
${pfasst_DEPENDEND_LIBS}
67-
)
68-
if(pfasst_WITH_GCC_PROF AND ${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
69-
set_target_properties(${test}
70-
PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs"
71-
LINK_FLAGS "-fprofile-arcs"
72-
)
73-
endif()
74-
add_test(NAME ${test}
75-
COMMAND ${CMAKE_BINARY_DIR}/tests/examples/advection_diffusion/${test} --gtest_output=xml:${test}_out.xml
47+
set(TESTS
48+
test_advection_diffusion
49+
)
50+
51+
foreach(test ${TESTS})
52+
message(STATUS " ${test}")
53+
add_executable(${test} ${test}.cpp)
54+
if(NOT FFTW_FOUND)
55+
add_dependencies(${test} fftw3)
56+
endif()
57+
if(${pfasst_NUM_DEPENDEND_TARGETS} GREATER 0)
58+
add_dependencies(${test} ${pfasst_DEPENDEND_TARGETS})
59+
endif()
60+
if(${pfasst_TESTS_NUM_DEPENDEND_TARGETS} GREATER 0)
61+
add_dependencies(${test} ${pfasst_TESTS_DEPENDEND_TARGETS})
62+
endif()
63+
target_link_libraries(${test}
64+
${3rdparty_DEPENDEND_LIBS}
65+
${TESTS_3rdparty_DEPENDEND_LIBS}
66+
${FFTW_LIBRARIES}
67+
${pfasst_DEPENDEND_LIBS}
68+
)
69+
if(pfasst_WITH_GCC_PROF AND ${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
70+
set_target_properties(${test}
71+
PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs"
72+
LINK_FLAGS "-fprofile-arcs"
7673
)
77-
endforeach(test)
78-
endif()
74+
endif()
75+
add_test(NAME ${test}
76+
COMMAND ${CMAKE_BINARY_DIR}/tests/examples/advection_diffusion/${test} --gtest_output=xml:${test}_out.xml
77+
)
78+
endforeach(test)

tests/examples/boris/CMakeLists.txt

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,35 @@ include_directories(
44
${pfasst_INCLUDES}
55
)
66

7-
if(NOT ${pfasst_WITH_MPI})
8-
set(TESTS
9-
test_boris_particle_util
10-
# test_boris_physics
11-
test_boris_sweeper
12-
)
7+
set(TESTS
8+
test_boris_particle_util
9+
# test_boris_physics
10+
test_boris_sweeper
11+
)
1312

14-
foreach(test ${TESTS})
15-
message(STATUS " ${test}")
16-
add_executable(${test} ${test}.cpp)
17-
if(${pfasst_NUM_DEPENDEND_TARGETS} GREATER 0)
18-
add_dependencies(${test} ${pfasst_DEPENDEND_TARGETS})
19-
endif()
20-
if(${pfasst_TESTS_NUM_DEPENDEND_TARGETS} GREATER 0)
21-
add_dependencies(${test} ${pfasst_TESTS_DEPENDEND_TARGETS})
22-
endif()
23-
target_link_libraries(${test}
24-
${3rdparty_DEPENDEND_LIBS}
25-
${TESTS_3rdparty_DEPENDEND_LIBS}
26-
${pfasst_DEPENDEND_LIBS}
27-
)
28-
if(pfasst_WITH_GCC_PROF AND ${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
29-
set_target_properties(${test}
30-
PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs"
31-
LINK_FLAGS "-fprofile-arcs"
32-
)
33-
endif()
34-
add_test(NAME ${test}
35-
COMMAND ${CMAKE_BINARY_DIR}/tests/examples/boris/${test} --gtest_output=xml:${test}_out.xml
13+
foreach(test ${TESTS})
14+
message(STATUS " ${test}")
15+
add_executable(${test} ${test}.cpp)
16+
if(${pfasst_NUM_DEPENDEND_TARGETS} GREATER 0)
17+
add_dependencies(${test} ${pfasst_DEPENDEND_TARGETS})
18+
endif()
19+
if(${pfasst_TESTS_NUM_DEPENDEND_TARGETS} GREATER 0)
20+
add_dependencies(${test} ${pfasst_TESTS_DEPENDEND_TARGETS})
21+
endif()
22+
target_link_libraries(${test}
23+
${3rdparty_DEPENDEND_LIBS}
24+
${TESTS_3rdparty_DEPENDEND_LIBS}
25+
${pfasst_DEPENDEND_LIBS}
26+
)
27+
if(pfasst_WITH_GCC_PROF AND ${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
28+
set_target_properties(${test}
29+
PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs"
30+
LINK_FLAGS "-fprofile-arcs"
3631
)
37-
endforeach(test)
32+
endif()
33+
add_test(NAME ${test}
34+
COMMAND ${CMAKE_BINARY_DIR}/tests/examples/boris/${test} --gtest_output=xml:${test}_out.xml
35+
)
36+
endforeach(test)
3837

39-
target_link_libraries(test_boris_sweeper simple_physics_solver)
40-
endif()
38+
target_link_libraries(test_boris_sweeper simple_physics_solver)

0 commit comments

Comments
 (0)