Skip to content

Commit

Permalink
Move function definitions to cpp file
Browse files Browse the repository at this point in the history
This allows making charm++ a PRIVATE dependency for the System library.
  • Loading branch information
kidder committed Nov 11, 2023
1 parent 0630f5e commit 7ea610f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/Utilities/System/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spectre_target_sources(
${LIBRARY}
PRIVATE
Abort.cpp
Exit.cpp
ParallelInfo.cpp
Prefetch.cpp
)
Expand Down
18 changes: 18 additions & 0 deletions src/Utilities/System/Exit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

#include "Utilities/System/Exit.hpp"

#include <charm++.h>
#include <exception>

namespace sys {

[[noreturn]] void exit(const int exit_code) {
CkExit(exit_code);
// the following call is never reached, but suppresses the warning that
// a 'noreturn' function does return
std::terminate(); // LCOV_EXCL_LINE
}

} // namespace sys
10 changes: 1 addition & 9 deletions src/Utilities/System/Exit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@

#pragma once

#include <charm++.h>
#include <exception>

namespace sys {

/// \ingroup UtilitiesGroup
/// \brief Exit the program normally.
/// This should only be called once over all processors.
[[noreturn]] inline void exit(const int exit_code = 0) {
CkExit(exit_code);
// the following call is never reached, but suppresses the warning that
// a 'noreturn' function does return
std::terminate(); // LCOV_EXCL_LINE
}
[[noreturn]] void exit(int exit_code = 0);

} // namespace sys
28 changes: 28 additions & 0 deletions src/Utilities/System/ParallelInfo.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

#include <charm++.h>
#include <iomanip>
#include <sstream>

#include "Utilities/System/ParallelInfo.hpp"

namespace sys {
int number_of_procs() { return CkNumPes(); }

int my_proc() { return CkMyPe(); }

int number_of_nodes() { return CkNumNodes(); }

int my_node() { return CkMyNode(); }

int procs_on_node([[maybe_unused]] const int node_index) {
return CkNodeSize(node_index);
}

int my_local_rank() { return CkMyRank(); }

int first_proc_on_node([[maybe_unused]] const int node_index) {
return CkNodeFirst(node_index);
}

int node_of([[maybe_unused]] const int proc_index) {
return CkNodeOf(proc_index);
}

int local_rank_of([[maybe_unused]] const int proc_index) {
return CkRankOf(proc_index);
}

double wall_time() { return CkWallTimer(); }

std::string pretty_wall_time(const double total_seconds) {
// Subseconds don't really matter so just ignore them. This gives nice round
Expand Down
41 changes: 10 additions & 31 deletions src/Utilities/System/ParallelInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,90 +9,69 @@

#pragma once

#include <charm++.h>
#include <string>

namespace sys {
/*!
* \ingroup UtilitiesGroup
* \brief Number of processing elements.
*/
inline int number_of_procs() { return CkNumPes(); }
int number_of_procs();

/*!
* \ingroup UtilitiesGroup
* \brief %Index of my processing element.
*/
inline int my_proc() { return CkMyPe(); }
int my_proc();

/*!
* \ingroup UtilitiesGroup
* \brief Number of nodes.
*/
inline int number_of_nodes() { return CkNumNodes(); }
int number_of_nodes();

/*!
* \ingroup UtilitiesGroup
* \brief %Index of my node.
*/
inline int my_node() { return CkMyNode(); }
int my_node();

/*!
* \ingroup UtilitiesGroup
* \brief Number of processing elements on the given node.
*/
inline int procs_on_node(const int node_index) {
// When using the verbs-linux-x86_64 non-SMP build of Charm++ these
// functions have unused-parameter warnings. This is remedied by
// casting the integer to a void which results in no extra assembly
// code being generated. We use this instead of pragmas because we
// would require one pragma for GCC and one for clang, which would
// result in code duplication. Commenting out the variable
// nodeIndex gives compilation failures on most Charm++ builds since
// they actually use the variable. Charm++ plz...
static_cast<void>(node_index);
return CkNodeSize(node_index);
}
int procs_on_node(int node_index);

/*!
* \ingroup UtilitiesGroup
* \brief The local index of my processing element on my node.
* This is in the interval 0, ..., procs_on_node(my_node()) - 1.
*/
inline int my_local_rank() { return CkMyRank(); }
int my_local_rank();

/*!
* \ingroup UtilitiesGroup
* \brief %Index of first processing element on the given node.
*/
inline int first_proc_on_node(const int node_index) {
static_cast<void>(node_index);
return CkNodeFirst(node_index);
}
int first_proc_on_node(int node_index);

/*!
* \ingroup UtilitiesGroup
* \brief %Index of the node for the given processing element.
*/
inline int node_of(const int proc_index) {
static_cast<void>(proc_index);
return CkNodeOf(proc_index);
}
int node_of(int proc_index);

/*!
* \ingroup UtilitiesGroup
* \brief The local index for the given processing element on its node.
*/
inline int local_rank_of(const int proc_index) {
static_cast<void>(proc_index);
return CkRankOf(proc_index);
}
int local_rank_of(int proc_index);

/*!
* \ingroup UtilitiesGroup
* \brief The elapsed wall time in seconds.
*/
inline double wall_time() { return CkWallTimer(); }
double wall_time();

/// @{
/// \ingroup UtilitiesGroup
Expand Down

0 comments on commit 7ea610f

Please sign in to comment.