Thrill  0.1
concat_to_dia.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * thrill/api/concat_to_dia.hpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2015 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
9  ******************************************************************************/
10 
11 #pragma once
12 #ifndef THRILL_API_CONCAT_TO_DIA_HEADER
13 #define THRILL_API_CONCAT_TO_DIA_HEADER
14 
15 #include <thrill/api/dia.hpp>
17 #include <thrill/common/logger.hpp>
18 
19 #include <tlx/vector_free.hpp>
20 
21 #include <vector>
22 
23 namespace thrill {
24 namespace api {
25 
26 /*!
27  * \ingroup api_layer
28  */
29 template <typename ValueType>
30 class ConcatToDIANode final : public SourceNode<ValueType>
31 {
32 public:
34  using Super::context_;
35 
37  const std::vector<ValueType>& in_vector)
38  : Super(ctx, "ConcatToDIA"),
39  in_vector_(in_vector)
40  { }
41 
43  std::vector<ValueType>&& in_vector)
44  : Super(ctx, "ConcatToDIA"),
45  in_vector_(std::move(in_vector))
46  { }
47 
48  void PushData(bool /* consume */) final {
49  for (size_t i = 0; i < in_vector_.size(); ++i) {
50  this->PushItem(in_vector_[i]);
51  }
52  }
53 
54  void Dispose() final {
56  }
57 
58 private:
59  //! Vector pointer to read elements from.
60  std::vector<ValueType> in_vector_;
61 };
62 
63 /*!
64  * ConcatToDIA is a Source-DOp, which takes a vector of data on all workers, and
65  * CONCATENATES them into a DIA. Use Distribute to actually distribute data from
66  * a single worker, ConcatToDIA is a wrapper if the data is already distributed.
67  *
68  * \image html dia_ops/ConcatToDIA.svg
69  *
70  * \param ctx Reference to the Context object
71  *
72  * \param in_vector Vector to concatenate into a DIA, the contents is COPIED
73  * into the DIANode.
74  *
75  * \ingroup dia_sources
76  */
77 template <typename ValueType>
78 auto ConcatToDIA(Context& ctx,
79  const std::vector<ValueType>& in_vector) {
80 
82 
83  return DIA<ValueType>(tlx::make_counting<ConcatToDIANode>(ctx, in_vector));
84 }
85 
86 /*!
87  * ConcatToDIA is a Source-DOp, which takes a vector of data on all workers, and
88  * CONCATENATES them into a DIA. Use Distribute to actually distribute data from
89  * a single worker, ConcatToDIA is a wrapper if the data is already distributed.
90  *
91  * \image html dia_ops/ConcatToDIA.svg
92  *
93  * \param ctx Reference to the Context object
94  *
95  * \param in_vector Vector to concatenate into a DIA, the contents is MOVED into
96  * the DIANode.
97  */
98 template <typename ValueType>
99 auto ConcatToDIA(Context& ctx,
100  std::vector<ValueType>&& in_vector) {
101 
103 
104  return DIA<ValueType>(
105  tlx::make_counting<ConcatToDIANode>(ctx, std::move(in_vector)));
106 }
107 
108 } // namespace api
109 
110 //! imported from api namespace
111 using api::ConcatToDIA;
112 
113 } // namespace thrill
114 
115 #endif // !THRILL_API_CONCAT_TO_DIA_HEADER
116 
117 /******************************************************************************/
DIA is the interface between the user and the Thrill framework.
Definition: dia.hpp:141
void PushItem(const ValueType &item) const
Method for derived classes to Push a single item to all children.
Definition: dia_node.hpp:147
ConcatToDIANode(Context &ctx, const std::vector< ValueType > &in_vector)
auto ConcatToDIA(Context &ctx, const std::vector< ValueType > &in_vector)
ConcatToDIA is a Source-DOp, which takes a vector of data on all workers, and CONCATENATES them into ...
STL namespace.
The Context of a job is a unique instance per worker which holds references to all underlying parts o...
Definition: context.hpp:221
void Dispose() final
Virtual clear method. Triggers actual disposing in sub-classes.
void PushData(bool) final
Virtual method for pushing data. Triggers actual pushing in sub-classes.
void vector_free(std::vector< Type > &v)
Definition: vector_free.hpp:21
std::vector< ValueType > in_vector_
Vector pointer to read elements from.
ConcatToDIANode(Context &ctx, std::vector< ValueType > &&in_vector)
Context & context_
associated Context
Definition: dia_base.hpp:293