Skip to content

Commit 9f42a5f

Browse files
Optimize include time, push definitions to object files (#1774)
* WIP: Remove std::variant from public headers * Fix compile time and size * Fix tests * Fixes * Add loadChunkVariant again * Move load/storeChunk implementations to object file * Properly deactivate test * Fixes for old compilers * Move Memory.hpp implementations to .cpp * Move UniquePtr implementation to .cpp file * Move BaseRecord helpers to .cpp implementation file * Fixes * Move the rest of BaseRecord to .cpp * Fix UniquePtr stuff * Begin moving Container methods to .cpp * Continue with that * Finish moving Container implementation to cpp * CI fixes, cleanup * Implement Variant::index() * Cleanup * Doxygen * @doxygen stop it * CI fixes
1 parent fc44123 commit 9f42a5f

42 files changed

Lines changed: 2787 additions & 1641 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,15 @@ set(CORE_SOURCE
409409
src/auxiliary/Filesystem.cpp
410410
src/auxiliary/JSON.cpp
411411
src/auxiliary/JSONMatcher.cpp
412+
src/auxiliary/Memory.cpp
412413
src/auxiliary/Mpi.cpp
414+
src/auxiliary/UniquePtr.cpp
415+
src/auxiliary/Variant.cpp
413416
src/backend/Attributable.cpp
417+
src/backend/Attribute.cpp
418+
src/backend/BaseRecord.cpp
414419
src/backend/BaseRecordComponent.cpp
420+
src/backend/Container.cpp
415421
src/backend/MeshRecordComponent.cpp
416422
src/backend/PatchRecord.cpp
417423
src/backend/PatchRecordComponent.cpp

include/openPMD/Datatype.hpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -99,33 +99,6 @@ enum class Datatype : int
9999
*/
100100
std::vector<Datatype> openPMD_Datatypes();
101101

102-
namespace detail
103-
{
104-
struct bottom
105-
{};
106-
107-
// std::variant, but ignore first template parameter
108-
// little trick to avoid trailing commas in the macro expansions below
109-
template <typename Arg, typename... Args>
110-
using variant_tail_t = std::variant<Args...>;
111-
} // namespace detail
112-
113-
#define OPENPMD_ENUMERATE_TYPES(type) , type
114-
115-
using dataset_types =
116-
detail::variant_tail_t<detail::bottom OPENPMD_FOREACH_DATASET_DATATYPE(
117-
OPENPMD_ENUMERATE_TYPES)>;
118-
119-
using non_vector_types =
120-
detail::variant_tail_t<detail::bottom OPENPMD_FOREACH_NONVECTOR_DATATYPE(
121-
OPENPMD_ENUMERATE_TYPES)>;
122-
123-
using attribute_types =
124-
detail::variant_tail_t<detail::bottom OPENPMD_FOREACH_DATATYPE(
125-
OPENPMD_ENUMERATE_TYPES)>;
126-
127-
#undef OPENPMD_ENUMERATE_TYPES
128-
129102
/** @brief Fundamental equivalence check for two given types T and U.
130103
*
131104
* This checks whether the fundamental datatype (i.e. that of a single value
@@ -451,7 +424,7 @@ inline size_t toBits(Datatype d)
451424
* @param d Datatype to test
452425
* @return true if vector type, else false
453426
*/
454-
inline bool isVector(Datatype d)
427+
constexpr inline bool isVector(Datatype d)
455428
{
456429
using DT = Datatype;
457430

@@ -777,6 +750,12 @@ void warnWrongDtype(std::string const &key, Datatype store, Datatype request);
777750

778751
std::ostream &operator<<(std::ostream &, openPMD::Datatype const &);
779752

753+
template <typename T>
754+
constexpr auto datatypeIndex() -> size_t
755+
{
756+
return static_cast<size_t>(static_cast<int>(determineDatatype<T>()));
757+
}
758+
780759
/**
781760
* Generalizes switching over an openPMD datatype.
782761
*

include/openPMD/DatatypeMacros.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,27 @@ using openpmd_array_double_7 = std::array<double, 7>;
9595
MACRO(std::string) \
9696
MACRO(bool)
9797

98+
#define OPENPMD_FOREACH_VECTOR_DATATYPE(MACRO) \
99+
MACRO(std::vector<char>) \
100+
MACRO(std::vector<short>) \
101+
MACRO(std::vector<int>) \
102+
MACRO(std::vector<long>) \
103+
MACRO(std::vector<long long>) \
104+
MACRO(std::vector<unsigned char>) \
105+
MACRO(std::vector<unsigned short>) \
106+
MACRO(std::vector<unsigned int>) \
107+
MACRO(std::vector<unsigned long>) \
108+
MACRO(std::vector<unsigned long long>) \
109+
MACRO(std::vector<float>) \
110+
MACRO(std::vector<double>) \
111+
MACRO(std::vector<long double>) \
112+
MACRO(std::vector<std::complex<float>>) \
113+
MACRO(std::vector<std::complex<double>>) \
114+
MACRO(std::vector<std::complex<long double>>) \
115+
MACRO(std::vector<signed char>) \
116+
MACRO(std::vector<std::string>) \
117+
MACRO(openpmd_array_double_7)
118+
98119
#define OPENPMD_FOREACH_DATASET_DATATYPE(MACRO) \
99120
MACRO(char) \
100121
MACRO(unsigned char) \

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "openPMD/ThrowError.hpp"
3737
#include "openPMD/auxiliary/JSON_internal.hpp"
3838
#include "openPMD/auxiliary/StringManip.hpp"
39+
#include "openPMD/backend/Variant_internal.hpp"
3940
#include "openPMD/backend/Writable.hpp"
4041
#include "openPMD/config.hpp"
4142
#include <stdexcept>
@@ -659,7 +660,7 @@ namespace detail
659660
size_t step,
660661
adios2::IO &IO,
661662
std::string name,
662-
Attribute::resource &resource,
663+
Parameter<Operation::READ_ATT> &,
663664
detail::AdiosAttributes const &);
664665

665666
template <int n, typename... Params>

include/openPMD/IO/IOTask.hpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
#include "openPMD/Streaming.hpp"
2727
#include "openPMD/auxiliary/Export.hpp"
2828
#include "openPMD/auxiliary/Memory.hpp"
29-
#include "openPMD/auxiliary/TypeTraits.hpp"
3029
#include "openPMD/auxiliary/Variant.hpp"
3130
#include "openPMD/backend/Attribute.hpp"
3231
#include "openPMD/backend/ParsePreference.hpp"
3332

33+
#include <any>
3434
#include <cstddef>
3535
#include <memory>
3636
#include <optional>
@@ -621,7 +621,12 @@ struct OPENPMDAPI_EXPORT
621621
IfPossible
622622
};
623623
ChangesOverSteps changesOverSteps = ChangesOverSteps::No;
624-
Attribute::resource resource;
624+
// attribute_types
625+
std::any m_resource;
626+
template <typename T>
627+
void setResource(T val);
628+
template <typename variant_t>
629+
variant_t const &resource() const;
625630
};
626631

627632
template <>
@@ -642,8 +647,13 @@ struct OPENPMDAPI_EXPORT
642647

643648
std::string name = "";
644649
std::shared_ptr<Datatype> dtype = std::make_shared<Datatype>();
645-
std::shared_ptr<Attribute::resource> resource =
646-
std::make_shared<Attribute::resource>();
650+
651+
// attribute_types
652+
std::shared_ptr<std::any> m_resource = std::make_shared<std::any>();
653+
template <typename variant_t>
654+
variant_t const &resource() const;
655+
template <typename T>
656+
void setResource(T val);
647657
};
648658

649659
template <>
@@ -665,17 +675,14 @@ struct OPENPMDAPI_EXPORT
665675
std::string name = "";
666676
std::shared_ptr<Datatype> dtype = std::make_shared<Datatype>();
667677

668-
struct to_vector_type
669-
{
670-
template <typename T>
671-
using type = std::vector<T>;
672-
};
673-
// std::variant<std::vector<T_1>, std::vector<T_2>, ...>
674-
// for all T_i in openPMD::Datatype.
675-
using result_type = typename auxiliary::detail::
676-
map_variant<to_vector_type, Attribute::resource>::type;
677-
678-
std::shared_ptr<result_type> resource = std::make_shared<result_type>();
678+
// vector_of_attributes_type
679+
std::shared_ptr<std::any> m_resource = std::make_shared<std::any>();
680+
template <typename variant_t>
681+
variant_t const &resource() const;
682+
template <typename variant_t>
683+
variant_t &resource();
684+
template <typename T>
685+
void setResource(std::vector<T> val);
679686
};
680687

681688
template <>

include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "openPMD/IO/JSON/JSONFilePosition.hpp"
2828
#include "openPMD/auxiliary/Filesystem.hpp"
2929
#include "openPMD/auxiliary/JSON_internal.hpp"
30+
#include "openPMD/backend/Variant_internal.hpp"
3031
#include "openPMD/config.hpp"
3132

3233
#include <istream>
@@ -473,7 +474,7 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl
473474
struct AttributeWriter
474475
{
475476
template <typename T>
476-
static void call(nlohmann::json &, Attribute::resource const &);
477+
static void call(nlohmann::json &, attribute_types const &);
477478

478479
static constexpr char const *errorMsg = "JSON: writeAttribute";
479480
};

include/openPMD/RecordComponent.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#include "openPMD/backend/Attributable.hpp"
2929
#include "openPMD/backend/BaseRecordComponent.hpp"
3030

31+
// comment to prevent this include from being moved by clang-format
32+
#include "openPMD/DatatypeMacros.hpp"
33+
3134
#include <array>
3235
#include <cmath>
3336
#include <limits>
@@ -38,6 +41,7 @@
3841
#include <string>
3942
#include <type_traits>
4043
#include <utility>
44+
#include <variant>
4145
#include <vector>
4246

4347
// expose private and protected members for invasive testing
@@ -229,8 +233,11 @@ class RecordComponent : public BaseRecordComponent
229233
template <typename T>
230234
std::shared_ptr<T> loadChunk(Offset = {0u}, Extent = {-1u});
231235

232-
using shared_ptr_dataset_types = auxiliary::detail::
233-
map_variant<auxiliary::detail::as_shared_pointer, dataset_types>::type;
236+
#define OPENPMD_ENUMERATE_TYPES(type) , std::shared_ptr<type>
237+
using shared_ptr_dataset_types = auxiliary::detail::variant_tail_t<
238+
auxiliary::detail::bottom OPENPMD_FOREACH_DATASET_DATATYPE(
239+
OPENPMD_ENUMERATE_TYPES)>;
240+
#undef OPENPMD_ENUMERATE_TYPES
234241

235242
/** std::variant-based version of allocating loadChunk<T>(Offset, Extent)
236243
*
@@ -546,4 +553,6 @@ OPENPMD_protected
546553

547554
} // namespace openPMD
548555

556+
#include "openPMD/UndefDatatypeMacros.hpp"
557+
// comment to prevent these includes from being moved by clang-format
549558
#include "RecordComponent.tpp"

0 commit comments

Comments
 (0)