Skip to content

Commit

Permalink
#2216: Fix namespace issues and remove uneeded custom formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Apr 30, 2024
1 parent 6e52faf commit 963ad18
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 205 deletions.
6 changes: 4 additions & 2 deletions cmake_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@
#define INCLUDE_FMT_RANGES <fmt/ranges.h>
#define INCLUDE_FMT_OSTREAM <fmt/ostream.h>

#define VT_FMT_NAMESPACE namespace fmt
#define VT_FMT_NAMESPACE_BEGIN namespace fmt {
#define VT_FMT_NAMESPACE_END }
#else
#define INCLUDE_FMT_CORE <fmt-vt/core.h>
#define INCLUDE_FMT_FORMAT <fmt-vt/format.h>
#define INCLUDE_FMT_RANGES <fmt-vt/ranges.h>
#define INCLUDE_FMT_OSTREAM <fmt-vt/ostream.h>

#define VT_FMT_NAMESPACE namespace fmt::vt
#define VT_FMT_NAMESPACE_BEGIN namespace fmt { inline namespace vt {
#define VT_FMT_NAMESPACE_END } }
#endif
4 changes: 2 additions & 2 deletions src/vt/elm/elm_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct hash<vt::elm::ElementIDStruct> {
#include "vt/cmake_config.h"
#include INCLUDE_FMT_FORMAT

namespace fmt {
VT_FMT_NAMESPACE_BEGIN

/// Custom fmt formatter/print for \c vt::elm::ElementIDStruct
template <>
Expand Down Expand Up @@ -138,6 +138,6 @@ struct formatter<::vt::elm::ElementIDStruct> {
}
};

} /* end namespace fmt */
VT_FMT_NAMESPACE_END

#endif /*INCLUDED_VT_ELM_ELM_ID_H*/
4 changes: 2 additions & 2 deletions src/vt/epoch/epoch_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct hash<vt::epoch::EpochType> {
#include "vt/cmake_config.h"
#include INCLUDE_FMT_FORMAT

namespace fmt {
VT_FMT_NAMESPACE_BEGIN

/// Custom fmt formatter/print for \c EpochType
template <>
Expand Down Expand Up @@ -151,7 +151,7 @@ struct formatter<::vt::epoch::EpochType> {
}
};

} /* end namespace fmt */
VT_FMT_NAMESPACE_END

namespace vt {

Expand Down
51 changes: 28 additions & 23 deletions src/vt/rdma/rdma_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,30 +117,35 @@ static constexpr ByteType rdma_default_byte_size = sizeof(char);

}} //end namespace vt::rdma

VT_FMT_NAMESPACE {
template <>
struct formatter<::vt::rdma::Type> : formatter<std::string_view> {
template <typename FormatContext>
auto format(::vt::rdma::Type t, FormatContext& ctx) {
std::string_view name = "Unknown";
switch (t) {
case ::vt::rdma::Type::Get:
name = "Get";
break;
case ::vt::rdma::Type::Put:
name = "Put";
break;
case ::vt::rdma::Type::GetOrPut:
name = "GetOrPut";
break;
case ::vt::rdma::Type::Uninitialized:
name = "Uninitialized";
break;
}
return formatter<std::string_view>::format(name, ctx);
VT_FMT_NAMESPACE_BEGIN

template <>
struct formatter<::vt::rdma::Type> : formatter<std::string_view> {
template <typename FormatContext>
auto format(::vt::rdma::Type t, FormatContext& ctx) {
std::string_view name = "Unknown";
switch (t) {
case ::vt::rdma::Type::Get:
name = "Get";
break;
case ::vt::rdma::Type::Put:
name = "Put";
break;
case ::vt::rdma::Type::GetOrPut:
name = "GetOrPut";
break;
case ::vt::rdma::Type::Uninitialized:
name = "Uninitialized";
break;
default:
name = fmt::format(
"{}", static_cast<std::underlying_type_t<::vt::rdma::Type>>(t));
}
};
} // VT_FMT_NAMESPACE
return formatter<std::string_view>::format(name, ctx);
}
};

VT_FMT_NAMESPACE_END

#define PRINT_CHANNEL_TYPE(rdma_op_type) ( \
rdma_op_type == vt::rdma::Type::Get ? "rdma::Get" : ( \
Expand Down
28 changes: 15 additions & 13 deletions src/vt/termination/interval/interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,20 @@ struct Interval;

}}}

VT_FMT_NAMESPACE {
template <typename DomainT, DomainT sentinel>
struct formatter<::vt::term::interval::Interval<DomainT, sentinel>>
: formatter<std::string> {
template <typename FormatContext>
auto format(
const ::vt::term::interval::Interval<DomainT, sentinel>& interval,
FormatContext& ctx) {
return format_to(
ctx.out(), "Interval[{}, {}]", interval.lower(), interval.upper());
}
};
} // VT_FMT_NAMESPACE
VT_FMT_NAMESPACE_BEGIN

template <typename DomainT, DomainT sentinel>
struct formatter<::vt::term::interval::Interval<DomainT, sentinel>>
: formatter<std::string> {
template <typename FormatContext>
auto format(
const ::vt::term::interval::Interval<DomainT, sentinel>& interval,
FormatContext& ctx) {
return format_to(
ctx.out(), "Interval[{}, {}]", interval.lower(), interval.upper());
}
};

VT_FMT_NAMESPACE_END

#endif /*INCLUDED_VT_TERMINATION_INTERVAL_INTERVAL_H*/
18 changes: 10 additions & 8 deletions src/vt/timing/timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,7 @@ TimeType getCurrentTime();

}} /* end namespace vt::timing */

VT_FMT_NAMESPACE {
template <>
struct formatter<::vt::TimeTypeWrapper> {
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx) {
return ctx.begin();
}
VT_FMT_NAMESPACE_BEGIN

template <typename FormatContext>
auto format(::vt::TimeTypeWrapper const& t, FormatContext& ctx) {
Expand All @@ -80,6 +74,14 @@ VT_FMT_NAMESPACE {
}
};

} // VT_FMT_NAMESPACE
template <typename FormatContext>
auto format(::vt::TimeTypeWrapper const& t, FormatContext& ctx) {
return fmt::format_to(
ctx.out(), "{}",
to_engineering_string(t.seconds(), 3, eng_exponential, "s"));
}
};

VT_FMT_NAMESPACE_END

#endif /*INCLUDED_VT_TIMING_TIMING_H*/
26 changes: 14 additions & 12 deletions src/vt/topos/index/dense/dense_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,20 @@ static_assert(

}} // end namespace vt::index

VT_FMT_NAMESPACE {
template <typename IndexType, ::vt::index::NumDimensionsType ndim>
struct formatter<::vt::index::DenseIndexArray<IndexType, ndim>>
: formatter<std::array<IndexType, ndim>> {
template <typename FormatContext>
auto format(
const ::vt::index::DenseIndexArray<IndexType, ndim>& wrapper,
FormatContext& ctx) {
return formatter<std::array<IndexType, ndim>>::format(wrapper.dims, ctx);
}
};
} // VT_FMT_NAMESPACE
VT_FMT_NAMESPACE_BEGIN

template <typename IndexType, ::vt::index::NumDimensionsType ndim>
struct formatter<::vt::index::DenseIndexArray<IndexType, ndim>>
: formatter<std::array<IndexType, ndim>> {
template <typename FormatContext>
auto format(
const ::vt::index::DenseIndexArray<IndexType, ndim>& wrapper,
FormatContext& ctx) {
return formatter<std::array<IndexType, ndim>>::format(wrapper.dims, ctx);
}
};

VT_FMT_NAMESPACE_END

#include "vt/topos/index/dense/dense_array.impl.h"

Expand Down
52 changes: 30 additions & 22 deletions src/vt/vrt/collection/balance/greedylb/greedylb.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
//@HEADER
*/

#include <type_traits>
#if !defined INCLUDED_VT_VRT_COLLECTION_BALANCE_GREEDYLB_GREEDYLB_H
#define INCLUDED_VT_VRT_COLLECTION_BALANCE_GREEDYLB_GREEDYLB_H

Expand Down Expand Up @@ -126,29 +127,36 @@ struct GreedyLB : LoadSamplerBaseLB {

}}}} /* end namespace vt::vrt::collection::lb */

VT_FMT_NAMESPACE {
template <>
struct formatter<::vt::vrt::collection::lb::DataDistStrategy>
: formatter<std::string_view> {
template <typename FormatContext>
auto
format(::vt::vrt::collection::lb::DataDistStrategy c, FormatContext& ctx) {
std::string_view name = "Unknown";
switch (c) {
case ::vt::vrt::collection::lb::DataDistStrategy::scatter:
name = "scatter";
break;
case ::vt::vrt::collection::lb::DataDistStrategy::bcast:
name = "bcast";
break;
case ::vt::vrt::collection::lb::DataDistStrategy::pt2pt:
name = "pt2pt";
break;
}
return formatter<string_view>::format(name, ctx);
VT_FMT_NAMESPACE_BEGIN

template <>
struct formatter<::vt::vrt::collection::lb::DataDistStrategy>
: formatter<std::string_view> {
template <typename FormatContext>
auto
format(::vt::vrt::collection::lb::DataDistStrategy c, FormatContext& ctx) {
std::string_view name = "Unknown";
switch (c) {
case ::vt::vrt::collection::lb::DataDistStrategy::scatter:
name = "scatter";
break;
case ::vt::vrt::collection::lb::DataDistStrategy::bcast:
name = "bcast";
break;
case ::vt::vrt::collection::lb::DataDistStrategy::pt2pt:
name = "pt2pt";
break;
default:
name = fmt::format(
"{}",
static_cast<
std::underlying_type_t<::vt::vrt::collection::lb::DataDistStrategy>>(
c));
}
};
return formatter<string_view>::format(name, ctx);
}
};

} // VT_FMT_NAMESPACE
VT_FMT_NAMESPACE_END

#endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_GREEDYLB_GREEDYLB_H*/
2 changes: 1 addition & 1 deletion src/vt/vrt/collection/balance/lb_args_enum_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct LBArgsEnumConverter {
auto err = fmt::format(
"LBArgsEnumConverter: enum '{}' value '{}' corresponding to LB "
"argument '{}' does not have a string associated with it",
enum_type_, e, par_name_
enum_type_, static_cast<std::underlying_type_t<T>>(e), par_name_
);
vtAbort(err);
}
Expand Down
38 changes: 19 additions & 19 deletions src/vt/vrt/collection/balance/temperedlb/criterion.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,26 @@ struct Criterion {

}}}} /* end namespace vt::vrt::collection::lb */

VT_FMT_NAMESPACE {
template <>
struct formatter<::vt::vrt::collection::lb::CriterionEnum>
: formatter<std::string_view> {
template <typename FormatContext>
auto
format(::vt::vrt::collection::lb::CriterionEnum c, FormatContext& ctx) {
std::string_view name = "Unknown";
switch (c) {
case ::vt::vrt::collection::lb::CriterionEnum::Grapevine:
name = "Grapevine";
break;
case ::vt::vrt::collection::lb::CriterionEnum::ModifiedGrapevine:
name = "ModifiedGrapevine";
break;
}
return formatter<string_view>::format(name, ctx);
VT_FMT_NAMESPACE_BEGIN

template <>
struct formatter<::vt::vrt::collection::lb::CriterionEnum>
: formatter<std::string_view> {
template <typename FormatContext>
auto format(::vt::vrt::collection::lb::CriterionEnum c, FormatContext& ctx) {
std::string_view name = "Unknown";
switch (c) {
case ::vt::vrt::collection::lb::CriterionEnum::Grapevine:
name = "Grapevine";
break;
case ::vt::vrt::collection::lb::CriterionEnum::ModifiedGrapevine:
name = "ModifiedGrapevine";
break;
}
};
return formatter<string_view>::format(name, ctx);
}
};

} // VT_FMT_NAMESPACE
VT_FMT_NAMESPACE_END

#endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_TEMPEREDLB_CRITERION_H*/
Loading

0 comments on commit 963ad18

Please sign in to comment.