timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
dmp_get.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2020, The Regents of the University of California,
4// through Lawrence Berkeley National Laboratory (subject to receipt of any
5// required approvals from the U.S. Dept. of Energy). All rights reserved.
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in all
15// copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23// SOFTWARE.
24
25/**
26 * \file timemory/operations/types/finalize_get.hpp
27 * \brief Definition for various functions for finalize_get in operations
28 */
29
30#pragma once
31
36
37#include <map>
38#include <vector>
39
40namespace tim
41{
42namespace operation
43{
44namespace finalize
45{
46//
47//--------------------------------------------------------------------------------------//
48//
49template <typename Type>
50struct dmp_get<Type, true>
51{
52 static constexpr bool value = true;
53 using storage_type = impl::storage<Type, value>;
54 using result_type = typename storage_type::result_array_t;
55 using distrib_type = typename storage_type::dmp_result_t;
56 using result_node = typename storage_type::result_node;
57 using graph_type = typename storage_type::graph_t;
58 using graph_node = typename storage_type::graph_node;
59 using hierarchy_type = typename storage_type::uintvector_t;
61 using basic_tree_type = typename get_type::basic_tree_vector_type;
62 using basic_tree_vector_type = std::vector<basic_tree_type>;
63 using basic_tree_map_type = std::map<std::string, basic_tree_vector_type>;
64
65 explicit TIMEMORY_COLD dmp_get(storage_type& _storage)
66 : m_storage(&_storage)
67 {}
68
69 TIMEMORY_COLD distrib_type& operator()(distrib_type&);
70 TIMEMORY_COLD basic_tree_vector_type& operator()(basic_tree_vector_type&);
71 TIMEMORY_COLD basic_tree_map_type& operator()(basic_tree_map_type&);
72
73 template <typename Archive>
75 operator()(Archive&);
76
77private:
78 storage_type* m_storage = nullptr;
79};
80//
81//--------------------------------------------------------------------------------------//
82//
83template <typename Type>
84struct dmp_get<Type, false>
85{
86 static constexpr bool value = false;
87 using storage_type = impl::storage<Type, value>;
88
90
91 template <typename Tp>
92 Tp& operator()(Tp&)
93 {}
94};
95//
96//--------------------------------------------------------------------------------------//
97//
98template <typename Type>
101{
102 if(!m_storage)
103 return results;
104
105 auto& data = *m_storage;
106 auto _sz = results.size();
107#if defined(TIMEMORY_USE_UPCXX) && defined(TIMEMORY_USE_MPI)
108 results.clear();
109 auto _mpi = (mpi::is_initialized()) ? data.mpi_get() : distrib_type{};
110 auto _upc = (upc::is_initialized()) ? data.upc_get() : distrib_type{};
111 for(auto&& itr : _mpi)
112 results.emplace_back(std::move(itr));
113 for(auto&& itr : _upc)
114 results.emplace_back(std::move(itr));
115#elif defined(TIMEMORY_USE_UPCXX)
116 if(upc::is_initialized())
117 {
118 for(auto&& itr : data.upc_get())
119 results.emplace_back(std::move(itr));
120 }
121#elif defined(TIMEMORY_USE_MPI)
122 if(mpi::is_initialized())
123 {
124 for(auto&& itr : data.mpi_get())
125 results.emplace_back(std::move(itr));
126 }
127#endif
128 // if none of the above added any data, add the serial results
129 if(_sz == results.size())
130 results.emplace_back(std::move(data.get()));
131 return results;
132}
133//
134//--------------------------------------------------------------------------------------//
135//
136template <typename Type>
139{
140 if(!m_storage)
141 return bt;
142
143 auto& data = *m_storage;
144 bool empty = true;
145
146#if defined(TIMEMORY_USE_UPCXX)
147 if(upc::is_initialized())
148 {
149 empty = false;
150 data.upc_get(bt);
151 }
152#endif
153
154#if defined(TIMEMORY_USE_MPI)
155 if(mpi::is_initialized())
156 {
157 empty = false;
158 data.mpi_get(bt);
159 }
160#endif
161
162 // if none of the above added any data, add the serial results
163 if(empty)
164 data.get(bt);
165
166 return bt;
167}
168//
169//--------------------------------------------------------------------------------------//
170//
171template <typename Type>
174{
175 if(!m_storage)
176 return bt;
177
178 auto& data = *m_storage;
179 bool empty = true;
180
181#if defined(TIMEMORY_USE_UPCXX)
182 if(upc::is_initialized())
183 {
184 empty = false;
185 basic_tree_vector_type& _val = bt["upcxx"];
186 data.upc_get(_val);
187 }
188#endif
189
190#if defined(TIMEMORY_USE_MPI)
191 if(mpi::is_initialized())
192 {
193 empty = false;
194 basic_tree_vector_type& _val = bt["mpi"];
195 data.mpi_get(_val);
196 }
197#endif
198
199 // if none of the above added any data, add the serial results
200 if(empty)
201 {
202 basic_tree_vector_type& _val = bt["process"];
203 data.get(_val);
204 }
205
206 return bt;
207}
208//
209//--------------------------------------------------------------------------------------//
210//
211template <typename Type>
212template <typename Archive>
215{
216 if(!m_storage)
217 return ar;
218
219 auto& data = *m_storage;
220 bool empty = true;
221
222#if defined(TIMEMORY_USE_UPCXX)
223 if(upc::is_initialized())
224 {
225 empty = false;
226 data.upc_get(ar);
227 }
228#endif
229
230#if defined(TIMEMORY_USE_MPI)
231 if(mpi::is_initialized())
232 {
233 empty = false;
234 data.mpi_get(ar);
235 }
236#endif
237
238 // if none of the above added any data, add the serial results
239 if(empty)
240 data.get(ar);
241
242 return ar;
243}
244//
245//--------------------------------------------------------------------------------------//
246//
247} // namespace finalize
248} // namespace operation
249} // namespace tim
return false
Definition: definition.hpp:326
Definition: kokkosp.cpp:39
typename std::enable_if< B, T >::type enable_if_t
Alias template for enable_if.
Definition: types.hpp:190
void finalize()
Definition: types.hpp:119
The declaration for the types for operations without definitions.
Include the macros for operations.
Declare the operations types.
impl::storage< Type, value > storage_type
Definition: dmp_get.hpp:87
typename storage_type::graph_t graph_type
Definition: dmp_get.hpp:57
typename storage_type::dmp_result_t distrib_type
Definition: dmp_get.hpp:55
typename storage_type::result_node result_node
Definition: dmp_get.hpp:56
impl::storage< Type, value > storage_type
Definition: dmp_get.hpp:53
std::vector< basic_tree_type > basic_tree_vector_type
Definition: dmp_get.hpp:62
typename storage_type::uintvector_t hierarchy_type
Definition: dmp_get.hpp:59
typename storage_type::graph_node graph_node
Definition: dmp_get.hpp:58
typename get_type::basic_tree_vector_type basic_tree_type
Definition: dmp_get.hpp:61
std::map< std::string, basic_tree_vector_type > basic_tree_map_type
Definition: dmp_get.hpp:63
typename storage_type::result_array_t result_type
Definition: dmp_get.hpp:54