Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <vector>
20 
21 namespace thrill {
22 namespace api {
23 
24 /*!
25  * \ingroup api_layer
26  */
27 template <typename ValueType>
28 class ConcatToDIANode final : public SourceNode<ValueType>
29 {
30 public:
32  using Super::context_;
33 
35  const std::vector<ValueType>& in_vector)
36  : Super(ctx, "ConcatToDIA"),
37  in_vector_(in_vector)
38  { }
39 
41  std::vector<ValueType>&& in_vector)
42  : Super(ctx, "ConcatToDIA"),
43  in_vector_(std::move(in_vector))
44  { }
45 
46  void PushData(bool /* consume */) final {
47  for (size_t i = 0; i < in_vector_.size(); ++i) {
48  this->PushItem(in_vector_[i]);
49  }
50  }
51 
52  void Dispose() final {
53  std::vector<ValueType>().swap(in_vector_);
54  }
55 
56 private:
57  //! Vector pointer to read elements from.
58  std::vector<ValueType> in_vector_;
59 };
60 
61 /*!
62  * ConcatToDIA is a Source-DOp, which takes a vector of data on all workers, and
63  * CONCATENATES them into a DIA. Use Distribute to actually distribute data from
64  * a single worker, ConcatToDIA is a wrapper if the data is already distributed.
65  *
66  * \param ctx Reference to the Context object
67  *
68  * \param in_vector Vector to concatenate into a DIA, the contents is COPIED
69  * into the DIANode.
70  *
71  * \ingroup dia_sources
72  */
73 template <typename ValueType>
74 auto ConcatToDIA(Context& ctx,
75  const std::vector<ValueType>& in_vector) {
76 
78 
79  return DIA<ValueType>(tlx::make_counting<ConcatToDIANode>(ctx, in_vector));
80 }
81 
82 /*!
83  * ConcatToDIA is a Source-DOp, which takes a vector of data on all workers, and
84  * CONCATENATES them into a DIA. Use Distribute to actually distribute data from
85  * a single worker, ConcatToDIA is a wrapper if the data is already distributed.
86  *
87  * \param ctx Reference to the Context object
88  *
89  * \param in_vector Vector to concatenate into a DIA, the contents is MOVED into
90  * the DIANode.
91  */
92 template <typename ValueType>
93 auto ConcatToDIA(Context& ctx,
94  std::vector<ValueType>&& in_vector) {
95 
97 
98  return DIA<ValueType>(
99  tlx::make_counting<ConcatToDIANode>(ctx, std::move(in_vector)));
100 }
101 
102 } // namespace api
103 
104 //! imported from api namespace
105 using api::ConcatToDIA;
106 
107 } // namespace thrill
108 
109 #endif // !THRILL_API_CONCAT_TO_DIA_HEADER
110 
111 /******************************************************************************/
DIA is the interface between the user and the Thrill framework.
Definition: dia.hpp:141
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 ...
The Context of a job is a unique instance per worker which holds references to all underlying parts o...
Definition: context.hpp:218
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 PushItem(const ValueType &item) const
Method for derived classes to Push a single item to all children.
Definition: dia_node.hpp:147
void swap(CountingPtr< A, D > &a1, CountingPtr< A, D > &a2) noexcept
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