Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <string>
7 : #include <tuple>
8 : #include <vector>
9 :
10 : #include "DataStructures/DataBox/DataBox.hpp"
11 : #include "IO/Observer/ObserverComponent.hpp"
12 : #include "IO/Observer/ReductionActions.hpp"
13 : #include "Parallel/GlobalCache.hpp"
14 : #include "Parallel/Info.hpp"
15 : #include "Parallel/Invoke.hpp"
16 : #include "Parallel/Local.hpp"
17 : #include "Utilities/Serialization/Serialize.hpp"
18 :
19 : namespace mem_monitor {
20 : /*!
21 : * \brief Simple action meant to be run on a Singleton that writes the size of
22 : * the Singleton component to disk.
23 : *
24 : * \details The columns in the dat file are
25 : *
26 : * - %Time
27 : * - Proc
28 : * - Size (MB)
29 : *
30 : * The dat file will be placed in the `/MemoryMonitors/` group in the reduction
31 : * file. The name of the dat file is the `pretty_type::name` of the component.
32 : */
33 1 : struct ProcessSingleton {
34 : template <typename ParallelComponent, typename DbTags, typename Metavariables,
35 : typename ArrayIndex>
36 0 : static void apply(db::DataBox<DbTags>& /*box*/,
37 : Parallel::GlobalCache<Metavariables>& cache,
38 : const ArrayIndex& /*array_index*/, const double time) {
39 : static_assert(
40 : Parallel::is_singleton_v<ParallelComponent>,
41 : "ProcessSingleton can only be run on a Singleton parallel component.");
42 : auto& singleton_proxy =
43 : Parallel::get_parallel_component<ParallelComponent>(cache);
44 : const double size_in_bytes = static_cast<double>(
45 : size_of_object_in_bytes(*Parallel::local(singleton_proxy)));
46 : const double size_in_MB = size_in_bytes / 1.0e6;
47 :
48 : const std::vector<std::string> legend{{"Time", "Proc", "Size (MB)"}};
49 :
50 : auto& observer_writer_proxy = Parallel::get_parallel_component<
51 : observers::ObserverWriter<Metavariables>>(cache);
52 :
53 : Parallel::threaded_action<
54 : observers::ThreadedActions::WriteReductionDataRow>(
55 : // Node 0 is always the writer
56 : observer_writer_proxy[0], subfile_name<ParallelComponent>(), legend,
57 : std::make_tuple(
58 : time, Parallel::my_proc<size_t>(*Parallel::local(singleton_proxy)),
59 : size_in_MB));
60 : }
61 : };
62 : } // namespace mem_monitor
|