Skip to content

Commit 8a8feae

Browse files
authored
Merge pull request #5028 from ornladios-robot/backport-to-release_212-5025
Backport #5025 to release_212
2 parents 8b6f8ad + f681c26 commit 8a8feae

3 files changed

Lines changed: 77 additions & 46 deletions

File tree

source/adios2/helper/adiosType.inl

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
87
#ifndef ADIOS2_HELPER_ADIOSTYPE_INL_
98
#define ADIOS2_HELPER_ADIOSTYPE_INL_
109
#ifndef ADIOS2_HELPER_ADIOSTYPE_H_
1110
#error "Inline file should only be included from it's header, never on it's own"
1211
#endif
1312

14-
#include <algorithm> //std::transform
15-
#include <sstream> //std::ostringstream
13+
#include <algorithm> //std::transform
14+
#include <sstream> //std::ostringstream
15+
#include <type_traits> //std::is_floating_point_v
1616

1717
#include "adios2/common/ADIOSMacros.h"
1818
#include "adiosLog.h"
@@ -110,8 +110,7 @@ template <class T, class U>
110110
std::vector<U> NewVectorTypeFromArray(const T *in, const size_t inSize)
111111
{
112112
std::vector<U> out(inSize);
113-
std::transform(in, in + inSize, out.begin(),
114-
[](T value) { return static_cast<U>(value); });
113+
std::transform(in, in + inSize, out.begin(), [](T value) { return static_cast<U>(value); });
115114
return out;
116115
}
117116

@@ -149,12 +148,12 @@ inline std::string ValueToString(const std::string value) noexcept
149148
return "\"" + value + "\"";
150149
}
151150

152-
#define declare_template_instantiation(C) \
153-
template <> \
154-
inline std::string ValueToString(const C value) noexcept \
155-
{ \
156-
const int valueInt = static_cast<int>(value); \
157-
return std::to_string(valueInt); \
151+
#define declare_template_instantiation(C) \
152+
template <> \
153+
inline std::string ValueToString(const C value) noexcept \
154+
{ \
155+
const int valueInt = static_cast<int>(value); \
156+
return std::to_string(valueInt); \
158157
}
159158
ADIOS2_FOREACH_CHAR_TYPE_1ARG(declare_template_instantiation)
160159
#undef declare_template_instantiation
@@ -163,6 +162,10 @@ template <class T>
163162
inline std::string ValueToString(const T value) noexcept
164163
{
165164
std::ostringstream valueSS;
165+
if constexpr (std::is_floating_point_v<T>)
166+
{
167+
valueSS << std::scientific;
168+
}
166169
valueSS << value;
167170
const std::string valueStr(valueSS.str());
168171
return valueStr;
@@ -188,26 +191,26 @@ inline std::string VectorToCSV(const std::vector<std::string> &input) noexcept
188191
return csv;
189192
}
190193

191-
#define declare_template_instantiation(C) \
192-
template <> \
193-
inline std::string VectorToCSV(const std::vector<C> &input) noexcept \
194-
{ \
195-
if (input.empty()) \
196-
{ \
197-
return std::string(); \
198-
} \
199-
\
200-
std::ostringstream valueSS; \
201-
for (const auto &value : input) \
202-
{ \
203-
const int valueInt = static_cast<int>(value); \
204-
valueSS << valueInt << ", "; \
205-
} \
206-
std::string csv(valueSS.str()); \
207-
csv.pop_back(); \
208-
csv.pop_back(); \
209-
\
210-
return csv; \
194+
#define declare_template_instantiation(C) \
195+
template <> \
196+
inline std::string VectorToCSV(const std::vector<C> &input) noexcept \
197+
{ \
198+
if (input.empty()) \
199+
{ \
200+
return std::string(); \
201+
} \
202+
\
203+
std::ostringstream valueSS; \
204+
for (const auto &value : input) \
205+
{ \
206+
const int valueInt = static_cast<int>(value); \
207+
valueSS << valueInt << ", "; \
208+
} \
209+
std::string csv(valueSS.str()); \
210+
csv.pop_back(); \
211+
csv.pop_back(); \
212+
\
213+
return csv; \
211214
}
212215
ADIOS2_FOREACH_CHAR_TYPE_1ARG(declare_template_instantiation)
213216
#undef declare_template_instantiation
@@ -237,8 +240,7 @@ void CheckForNullptr(T *pointer, const std::string hint)
237240
{
238241
if (pointer == nullptr)
239242
{
240-
helper::Throw<std::invalid_argument>("Helper", "adiosType",
241-
"CheckForNullPtr",
243+
helper::Throw<std::invalid_argument>("Helper", "adiosType", "CheckForNullPtr",
242244
"found null pointer " + hint);
243245
}
244246
}

source/utils/bpls/bpls.cpp

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -918,15 +918,15 @@ int printAttributeValue(core::Engine *fp, core::IO *io, core::Attribute<T> *attr
918918
DataType adiosvartype = attribute->m_Type;
919919
if (attribute->m_IsSingleValue)
920920
{
921-
print_data((void *)&attribute->m_DataSingleValue, 0, adiosvartype, true);
921+
print_data((void *)&attribute->m_DataSingleValue, 0, adiosvartype, false);
922922
}
923923
else
924924
{
925925
fprintf(outf, "{");
926926
size_t nelems = attribute->m_DataArray.size();
927927
for (size_t j = 0; j < nelems; j++)
928928
{
929-
print_data((void *)&attribute->m_DataArray[j], 0, adiosvartype, true);
929+
print_data((void *)&attribute->m_DataArray[j], 0, adiosvartype, false);
930930
if (j < nelems - 1)
931931
{
932932
fprintf(outf, ", ");
@@ -953,7 +953,7 @@ int printAttributeValue(core::Engine *fp, core::IO *io, core::Attribute<std::str
953953
}
954954
if (printDataAnyway)
955955
{
956-
print_data((void *)&attribute->m_DataSingleValue, 0, adiosvartype, true);
956+
print_data((void *)&attribute->m_DataSingleValue, 0, adiosvartype, false);
957957
}
958958
}
959959
else
@@ -969,7 +969,7 @@ int printAttributeValue(core::Engine *fp, core::IO *io, core::Attribute<std::str
969969
}
970970
if (printDataAnyway)
971971
{
972-
print_data((void *)&attribute->m_DataArray[j], 0, adiosvartype, true);
972+
print_data((void *)&attribute->m_DataArray[j], 0, adiosvartype, false);
973973
}
974974
if (j < nelems - 1)
975975
{
@@ -3072,18 +3072,47 @@ int print_data(const void *data, int item, DataType adiosvartype, bool allowform
30723072
fprintf(outf, (f ? fmt : "%lld"), ((signed long long *)data)[item]);
30733073
break;
30743074

3075-
case DataType::Float:
3076-
fprintf(outf, (f ? fmt : "%g"), ((float *)data)[item]);
3075+
case DataType::Float: {
3076+
float v = ((float *)data)[item];
3077+
if (allowformat)
3078+
fprintf(outf, (f ? fmt : "%g"), v);
3079+
else
3080+
{
3081+
if (-10000.0 < v && v < 100000.0)
3082+
fprintf(outf, "%g", v);
3083+
else
3084+
fprintf(outf, "%e", v);
3085+
}
30773086
break;
3087+
}
30783088

3079-
case DataType::Double:
3080-
fprintf(outf, (f ? fmt : "%g"), ((double *)data)[item]);
3089+
case DataType::Double: {
3090+
double v = ((double *)data)[item];
3091+
if (allowformat)
3092+
fprintf(outf, (f ? fmt : "%g"), v);
3093+
else
3094+
{
3095+
if (-10000.0 < v && v < 100000.0)
3096+
fprintf(outf, "%g", v);
3097+
else
3098+
fprintf(outf, "%e", v);
3099+
}
30813100
break;
3101+
}
30823102

3083-
case DataType::LongDouble:
3084-
fprintf(outf, (f ? fmt : "%Lg"), ((long double *)data)[item]);
3085-
// fprintf(outf,(f ? fmt : "????????"));
3103+
case DataType::LongDouble: {
3104+
long double v = ((long double *)data)[item];
3105+
if (allowformat)
3106+
fprintf(outf, (f ? fmt : "%Lg"), v);
3107+
else
3108+
{
3109+
if (-10000.0 < v && v < 100000.0)
3110+
fprintf(outf, "%Lg", v);
3111+
else
3112+
fprintf(outf, "%Le", v);
3113+
}
30863114
break;
3115+
}
30873116

30883117
case DataType::FloatComplex:
30893118
fprintf(outf, (f ? fmt : "(%g,i%g)"), ((float *)data)[2 * item],

testing/utils/bpcmp/TestUtilsBPcmp.stats.expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
COMPARE : FILE : TestBPcmp_set1.bp : FILE : TestBPcmp_set2.bp
22
DIFFER : NUM_STEPS : 2 <> 3 : TestBPcmp_set1.bp : TestBPcmp_set2.bp
3-
DIFFER : VARIABLE : bpFloats : MIN : 4 <> 6 : TestBPcmp_set1.bp : TestBPcmp_set2.bp
4-
DIFFER : VARIABLE : bpFloats : MAX : 10 <> 11 : TestBPcmp_set1.bp : TestBPcmp_set2.bp
3+
DIFFER : VARIABLE : bpFloats : MIN : 4.000000e+00 <> 6.000000e+00 : TestBPcmp_set1.bp : TestBPcmp_set2.bp
4+
DIFFER : VARIABLE : bpFloats : MAX : 1.000000e+01 <> 1.100000e+01 : TestBPcmp_set1.bp : TestBPcmp_set2.bp
55
DIFFER : VARIABLE : bpFloats : STEP : 0 : VALUES_SUMMARY : 6 : TestBPcmp_set1.bp : TestBPcmp_set2.bp
66
DIFFER : VARIABLE : bpFloats : STEP : 1 : VALUES_SUMMARY : 6 : TestBPcmp_set1.bp : TestBPcmp_set2.bp
77
DIFFER : VARIABLE : bpStep : NUM_STEPS : 2 <> 3 : TestBPcmp_set1.bp : TestBPcmp_set2.bp

0 commit comments

Comments
 (0)