@@ -82,6 +82,7 @@ namespace detail
8282 struct BufferedGet ;
8383 struct BufferedAttributeRead ;
8484 struct BufferedAttributeWrite ;
85+ struct RunUniquePtrPut ;
8586} // namespace detail
8687
8788namespace ADIOS2Schema
@@ -124,6 +125,7 @@ class ADIOS2IOHandlerImpl
124125 friend struct detail ::WriteDataset;
125126 friend struct detail ::BufferedActions;
126127 friend struct detail ::BufferedAttributeRead;
128+ friend struct detail ::RunUniquePtrPut;
127129
128130public:
129131#if openPMD_HAVE_MPI
@@ -188,8 +190,8 @@ class ADIOS2IOHandlerImpl
188190 void deleteAttribute (
189191 Writable *, Parameter<Operation::DELETE_ATT> const &) override ;
190192
191- void writeDataset (
192- Writable *, Parameter<Operation::WRITE_DATASET> const &) override ;
193+ void
194+ writeDataset ( Writable *, Parameter<Operation::WRITE_DATASET> &) override ;
193195
194196 void writeAttribute (
195197 Writable *, Parameter<Operation::WRITE_ATT> const &) override ;
@@ -544,11 +546,7 @@ namespace detail
544546 struct WriteDataset
545547 {
546548 template <typename T>
547- static void call (
548- ADIOS2IOHandlerImpl *impl,
549- BufferedPut &bp,
550- adios2::IO &IO,
551- adios2::Engine &engine);
549+ static void call (BufferedActions &ba, BufferedPut &bp);
552550
553551 template <int n, typename ... Params>
554552 static void call (Params &&...);
@@ -916,6 +914,17 @@ namespace detail
916914 void run (BufferedActions &) override ;
917915 };
918916
917+ struct BufferedUniquePtrPut
918+ {
919+ std::string name;
920+ Offset offset;
921+ Extent extent;
922+ UniquePtrWithLambda<void > data;
923+ Datatype dtype;
924+
925+ void run (BufferedActions &);
926+ };
927+
919928 struct OldBufferedAttributeRead : BufferedAction
920929 {
921930 Parameter<Operation::READ_ATT> param;
@@ -967,6 +976,8 @@ namespace detail
967976 {
968977 friend struct BufferedGet ;
969978 friend struct BufferedPut ;
979+ friend struct RunUniquePtrPut ;
980+ friend struct WriteDataset ;
970981
971982 using FlushTarget = ADIOS2IOHandlerImpl::FlushTarget;
972983
@@ -1023,6 +1034,13 @@ namespace detail
10231034 * penalty, once preloadAttributes has been filled.
10241035 */
10251036 std::vector<BufferedAttributeRead> m_attributeReads;
1037+ /* *
1038+ * When receiving a unique_ptr, we know that the buffer is ours and
1039+ * ours alone. So, for performance reasons, show the buffer to ADIOS2 as
1040+ * late as possible and avoid unnecessary data copies in BP5 triggered
1041+ * by PerformDataWrites().
1042+ */
1043+ std::vector<BufferedUniquePtrPut> m_uniquePtrPuts;
10261044 /* *
10271045 * This contains deferred actions that have already been enqueued into
10281046 * ADIOS2, but not yet performed in ADIOS2.
@@ -1116,24 +1134,26 @@ namespace detail
11161134 * * adios2::Engine::EndStep
11171135 * * adios2::Engine::Perform(Puts|Gets)
11181136 * * adios2::Engine::Close
1119- * @param writeAttributes If using the new attribute layout, perform
1120- * deferred attribute writes now.
1137+ * @param writeLatePuts Some things are deferred until right before
1138+ * Engine::EndStep() or Engine::Close():
1139+ * 1) Writing attributes in new ADIOS2 schema.
1140+ * 2) Running unique_ptr Put()s.
11211141 * @param flushUnconditionally Whether to run the functor even if no
11221142 * deferred IO tasks had been queued.
11231143 */
11241144 template <typename F>
11251145 void flush_impl (
11261146 ADIOS2FlushParams flushParams,
11271147 F &&performPutsGets,
1128- bool writeAttributes ,
1148+ bool writeLatePuts ,
11291149 bool flushUnconditionally);
11301150
11311151 /* *
11321152 * Overload of flush() that uses adios2::Engine::Perform(Puts|Gets)
11331153 * and does not flush unconditionally.
11341154 *
11351155 */
1136- void flush_impl (ADIOS2FlushParams, bool writeAttributes = false );
1156+ void flush_impl (ADIOS2FlushParams, bool writeLatePuts = false );
11371157
11381158 /* *
11391159 * @brief Begin or end an ADIOS step.
0 commit comments