29#include <apex_api.hpp>
33#if defined(SIRIUS_GPU) && defined(SIRIUS_CUDA)
40using json = nlohmann::json;
41#if defined(SIRIUS_USE_POWER_COUNTER)
58extern json sirius_options_parser_;
67#if defined(SIRIUS_USE_POWER_COUNTER)
68inline static double& energy()
74inline static double& energy_acc()
84 PROFILE_START(
"sirius");
85 PROFILE(
"sirius::initialize");
87 RTE_THROW(
"SIRIUS library is already initialized");
89#if defined(SIRIUS_USE_POWER_COUNTER)
90 energy() = -power::energy();
91 energy_acc() = -power::device_energy();
93 if (call_mpi_init__) {
97 apex::init(
"sirius", Communicator::world().rank(), Communicator::world().size());
100 if (mpi::Communicator::world().rank() == 0) {
101 std::printf(
"SIRIUS %i.%i.%i, git hash: %s\n", sirius::major_version(), sirius::minor_version(),
102 sirius::revision(), sirius::git_hash().c_str());
104 std::printf(
"Warning! Compiled in 'debug' mode with assert statements enabled!\n");
116#if defined(SIRIUS_GPU)
117 acc::blas::create_stream_handles();
119#if defined(SIRIUS_CUDA)
120 acc::blas::xt::create_handle();
121 acc::cusolver::create_handle();
124 splablas::reset_handle();
126#if defined(SIRIUS_MAGMA)
129#if defined(SIRIUS_ELPA)
130 la::Eigensolver_elpa::initialize();
132#if defined(SIRIUS_DLAF)
136 RTE_ASSERT(
sizeof(
int) == 4);
137 RTE_ASSERT(
sizeof(
double) == 8);
143inline void finalize(
bool call_mpi_fin__ =
true,
bool reset_device__ =
true,
bool fftw_cleanup__ =
true)
145 PROFILE_START(
"sirius::finalize");
147 RTE_THROW(
"SIRIUS library was not initialized");
149#if defined(SIRIUS_MAGMA)
154 splablas::reset_handle();
156 sddk::get_memory_pool(sddk::memory_t::host).clear();
159 sddk::get_memory_pool(sddk::memory_t::host_pinned).clear();
160 sddk::get_memory_pool(sddk::memory_t::device).clear();
161#if defined(SIRIUS_GPU)
162 acc::blas::destroy_stream_handles();
164#if defined(SIRIUS_CUDA)
165 acc::cusolver::destroy_handle();
166 acc::blas::xt::destroy_handle();
169 if (reset_device__) {
177#if defined(SIRIUS_USE_POWER_COUNTER)
178 double e = energy() + power::energy();
179 double e_acc = energy_acc() + power::device_energy();
180 if (mpi::Communicator::world().rank() == 0) {
181 printf(
"=== Energy consumption (root MPI rank) ===\n");
182 printf(
"energy : %9.2f Joules\n", e);
183 printf(
"energy_acc : %9.2f Joules\n", e_acc);
185 mpi::Communicator::world().allreduce(&e, 1);
186 mpi::Communicator::world().allreduce(&e_acc, 1);
187 int nn = power::num_nodes();
188 if (Communicator::world().rank() == 0 && nn > 0) {
189 printf(
"=== Energy consumption (all nodes) ===\n");
190 printf(
"energy : %9.2f Joules\n", e * nn / Communicator::world().size());
191 printf(
"energy_acc : %9.2f Joules\n", e_acc * nn / Communicator::world().size());
194 auto rank = mpi::Communicator::world().rank();
195 if (call_mpi_fin__) {
198#if defined(SIRIUS_ELPA)
199 la::Eigensolver_elpa::finalize();
201#if defined(SIRIUS_DLAF)
207 PROFILE_STOP(
"sirius::finalize");
208 PROFILE_STOP(
"sirius");
210 auto pt = env::print_timing();
211 if (pt && rank == 0) {
212 auto timing_result = global_rtgraph_timer.process();
215 std::cout << timing_result.print({rt_graph::Stat::Count, rt_graph::Stat::Total, rt_graph::Stat::Percentage,
216 rt_graph::Stat::SelfPercentage, rt_graph::Stat::Median,
217 rt_graph::Stat::Min, rt_graph::Stat::Max});
220 timing_result = timing_result.flatten(1).sort_nodes();
221 std::cout << timing_result.print({rt_graph::Stat::Count, rt_graph::Stat::Total, rt_graph::Stat::Percentage,
222 rt_graph::Stat::SelfPercentage, rt_graph::Stat::Median,
223 rt_graph::Stat::Min, rt_graph::Stat::Max});
namespace for Niels Lohmann
static void initialize(int required__)
MPI initialization.
static void finalize()
MPI shut down.
Contains definition and implementation of cmd_args class.
Interface to CUDA eigen-solver library.
Contains definition and partial implementation of sirius::DFT_ground_state class.
Contains definition and implementation of various eigenvalue solver interfaces.
Contains definition and implementation of sirius::Gaunt class.
Contains definition and implementation of sirius::HDF5_tree class.
Interface to nlohmann::json library and helper functions.
Interface to SPLA library.
Declaration of sirius::Local_operator class.
void create_streams(int num_streams__)
Create CUDA streams.
int num_devices()
Get the number of devices.
void reset()
Reset device.
void set_device_id(int id__)
Set the GPU id.
void destroy_streams()
Destroy CUDA streams.
int get_device_id(int num_devices__)
Get GPU device id associated with the current rank.
int num_ranks_per_node()
Get number of ranks per node.
Namespace of the SIRIUS library.
void initialize(bool call_mpi_init__=true)
Initialize the library.
static bool & is_initialized()
Return the status of the library (initialized or not).
void finalize(bool call_mpi_fin__=true, bool reset_device__=true, bool fftw_cleanup__=true)
Shut down the library.
Add or substitute OMP functions.
Read power counters on Cray.
Contains declaration and partial implementation of sirius::Radial_solver class.
Contains declaration and particular implementation of sirius::SHT class.
Contains definition and implementation of Simulation_context class.
Get version number and related quantities.