1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 | // *****************************************************************************
/*!
\file src/Statistics/PDFReducer.cpp
\copyright 2012-2015 J. Bakosi,
2016-2018 Los Alamos National Security, LLC.,
2019-2021 Triad National Security, LLC.
All rights reserved. See the LICENSE file for details.
\brief Custom Charm++ reducer for merging PDFs across PEs
\details Custom Charm++ reducer for merging PDFs across PEs.
*/
// *****************************************************************************
#include <memory>
#include "PDFReducer.hpp"
namespace tk {
std::pair< int, std::unique_ptr<char[]> >
serialize( std::size_t meshid, const std::vector< tk::UniPDF >& u )
// *****************************************************************************
// Serialize univariate PDFs to raw memory stream
//! \param[in] meshid Mesh ID
//! \param[in] u Univariate PDFs
//! \return Pair of the length and the raw stream containing the serialized PDFs
// *****************************************************************************
{
// Prepare for serializing PDF to a raw binary stream, compute size
PUP::sizer sizer;
sizer | meshid;<--- Uninitialized variable: meshid
sizer | const_cast< std::vector< tk::UniPDF >& >( u );
// Create raw character stream to store the serialized PDF
std::unique_ptr<char[]> flatData = std::make_unique<char[]>( sizer.size() );
// Serialize PDF, the message will contain a univariate PDF
PUP::toMem packer( flatData.get() );
packer | meshid;<--- Uninitialized variable: meshid
packer | const_cast< std::vector< tk::UniPDF >& >( u );
// Return size of and raw stream
return { sizer.size(), std::move(flatData) };
}
CkReductionMsg*
mergeUniPDFs( int nmsg, CkReductionMsg **msgs )
// *****************************************************************************
// Charm++ custom reducer for merging a univariate PDFs during reduction across
// PEs
//! \param[in] nmsg Number of messages in msgs
//! \param[in] msgs Charm++ reduction message containing the serialized PDF
//! \return Aggregated PDF built for further aggregation if needed
// *****************************************************************************
{
// Will store deserialized univariate PDFs
std::size_t meshid;
std::vector< tk::UniPDF > updf;
// Create PUP deserializer based on message passed in
PUP::fromMem creator( msgs[0]->getData() );
// Deserialize PDFs from raw stream
creator | meshid;<--- Uninitialized variable: meshid
creator | updf;
for (int m=1; m<nmsg; ++m) {
// Unpack PDF
std::size_t mid;
std::vector< tk::UniPDF > u;
PUP::fromMem curCreator( msgs[m]->getData() );
curCreator | mid;<--- Uninitialized variable: mid
curCreator | u;
// Merge PDFs
meshid = mid;<--- Assignment 'meshid=mid', assigned value is <--- Assignment 'meshid=mid', assigned value is <--- Uninitialized variable: mid<--- Assignment 'meshid=mid', assigned value is
std::size_t i = 0;
for (const auto& p : u) updf[i++].addPDF( p );<--- Access out of bounds<--- Iterating over container 'u' that is always empty.
}
// Serialize vector of merged PDF to raw stream
auto stream = tk::serialize( meshid, updf );<--- Calling function 'serialize', 1st argument 'meshid' value is <--- Calling function 'serialize', 1st argument 'meshid' value is <--- Uninitialized variable: meshid
// Forward serialized PDFs
return CkReductionMsg::buildNew( stream.first, stream.second.get() );
}
std::pair< int, std::unique_ptr<char[]> >
serialize( const std::vector< tk::UniPDF >& u,
const std::vector< tk::BiPDF >& b,
const std::vector< tk::TriPDF >& t )
// *****************************************************************************
// Serialize vectors of PDFs to raw memory stream
//! \param[in] u Vector of univariate PDFs
//! \param[in] b Vector of bivariate PDFs
//! \param[in] t Vector of trivariate PDFs
//! \return Pair of the length and the raw stream containing the serialized PDFs
// *****************************************************************************
{
// Prepare for serializing PDFs to a raw binary stream, compute size
PUP::sizer sizer;
sizer | const_cast< std::vector< tk::UniPDF >& >( u );
sizer | const_cast< std::vector< tk::BiPDF >& >( b );
sizer | const_cast< std::vector< tk::TriPDF >& >( t );
// Create raw character stream to store the serialized PDFs
std::unique_ptr<char[]> flatData = std::make_unique<char[]>( sizer.size() );
// Serialize PDFs, each message will contain a vector of PDFs
PUP::toMem packer( flatData.get() );
packer | const_cast< std::vector< tk::UniPDF >& >( u );
packer | const_cast< std::vector< tk::BiPDF >& >( b );
packer | const_cast< std::vector< tk::TriPDF >& >( t );
// Return size of and raw stream
return { sizer.size(), std::move(flatData) };
}
CkReductionMsg*
mergePDF( int nmsg, CkReductionMsg **msgs )
// *****************************************************************************
// Charm++ custom reducer for merging PDFs during reduction across PEs
//! \param[in] nmsg Number of messages in msgs
//! \param[in] msgs Charm++ reduction message containing the serialized PDFs
//! \return Aggregated PDFs built for further aggregation if needed
// *****************************************************************************
{
// Will store deserialized uni-, bi-, and tri-variate PDFs
std::vector< tk::UniPDF > updf;
std::vector< tk::BiPDF > bpdf;
std::vector< tk::TriPDF > tpdf;
// Create PUP deserializer based on message passed in
PUP::fromMem creator( msgs[0]->getData() );
// Deserialize PDFs from raw stream
creator | updf;
creator | bpdf;
creator | tpdf;
for (int m=1; m<nmsg; ++m) {
// Unpack PDFs
std::vector< tk::UniPDF > u;
std::vector< tk::BiPDF > b;
std::vector< tk::TriPDF > t;
PUP::fromMem curCreator( msgs[m]->getData() );
curCreator | u;
curCreator | b;
curCreator | t;
// Merge PDFs
std::size_t i = 0;
for (const auto& p : u) updf[i++].addPDF( p );<--- Access out of bounds<--- Iterating over container 'u' that is always empty.
i = 0;
for (const auto& p : b) bpdf[i++].addPDF( p );<--- Access out of bounds<--- Iterating over container 'b' that is always empty.
i = 0;
for (const auto& p : t) tpdf[i++].addPDF( p );<--- Access out of bounds<--- Iterating over container 't' that is always empty.
}
// Serialize vector of merged PDFs to raw stream
auto stream = tk::serialize( updf, bpdf, tpdf );
// Forward serialized PDFs
return CkReductionMsg::buildNew( stream.first, stream.second.get() );
}
} // tk::
|