Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
equal_to_dia.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * thrill/api/equal_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_EQUAL_TO_DIA_HEADER
13 #define THRILL_API_EQUAL_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 EqualToDIANode final : public SourceNode<ValueType>
29 {
30 public:
32  using Super::context_;
33 
35  const std::vector<ValueType>& in_vector)
36  : Super(ctx, "EqualToDIA"),
37  in_vector_(in_vector)
38  { }
39 
41  std::vector<ValueType>&& in_vector)
42  : Super(ctx, "EqualToDIA"),
43  in_vector_(std::move(in_vector))
44  { }
45 
46  void PushData(bool /* consume */) final {
48 
49  for (size_t i = local.begin; i < local.end; ++i) {
50  this->PushItem(in_vector_[i]);
51  }
52  }
53 
54  void Dispose() final {
55  std::vector<ValueType>().swap(in_vector_);
56  }
57 
58 private:
59  //! Vector pointer to read elements from.
60  std::vector<ValueType> in_vector_;
61 };
62 
63 /*!
64  * EqualToDIA is a Source-DOp, which takes a vector of data EQUAL on all
65  * workers, and returns the data in a DIA. Use Distribute to actually distribute
66  * data from a single worker, EqualToDIA is a wrapper if the data is already
67  * distributed.
68  *
69  * \param ctx Reference to the Context object
70  *
71  * \param in_vector Vector to convert to a DIA, the contents is COPIED into the
72  * DIANode.
73  *
74  * \ingroup dia_sources
75  */
76 template <typename ValueType>
77 auto EqualToDIA(Context& ctx,
78  const std::vector<ValueType>& in_vector) {
79 
81 
82  return DIA<ValueType>(tlx::make_counting<EqualToDIANode>(ctx, in_vector));
83 }
84 
85 /*!
86  * EqualToDIA is an Source-DOp, which takes a vector of data EQUAL on all
87  * workers, and returns the data in a DIA. Use Distribute to actually distribute
88  * data from a single worker, EqualToDIA is a wrapper if the data is already
89  * distributed.
90  *
91  * \param ctx Reference to the Context object
92  *
93  * \param in_vector Vector to convert to a DIA, the contents is MOVED into the
94  * DIANode.
95  *
96  * \ingroup dia_sources
97  */
98 template <typename ValueType>
99 auto EqualToDIA(Context& ctx,
100  std::vector<ValueType>&& in_vector) {
101 
103 
104  return DIA<ValueType>(
105  tlx::make_counting<EqualToDIANode>(ctx, std::move(in_vector)));
106 }
107 
108 } // namespace api
109 
110 //! imported from api namespace
111 using api::EqualToDIA;
112 
113 } // namespace thrill
114 
115 #endif // !THRILL_API_EQUAL_TO_DIA_HEADER
116 
117 /******************************************************************************/
void PushData(bool) final
Virtual method for pushing data. Triggers actual pushing in sub-classes.
DIA is the interface between the user and the Thrill framework.
Definition: dia.hpp:141
std::vector< ValueType > in_vector_
Vector pointer to read elements from.
auto EqualToDIA(Context &ctx, const std::vector< ValueType > &in_vector)
EqualToDIA is a Source-DOp, which takes a vector of data EQUAL on all workers, and returns the data i...
EqualToDIANode(Context &ctx, const std::vector< ValueType > &in_vector)
represents a 1 dimensional range (interval) [begin,end)
Definition: math.hpp:41
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 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
size_t end
end index
Definition: math.hpp:58
common::Range CalculateLocalRange(size_t global_size) const
Definition: context.hpp:336
EqualToDIANode(Context &ctx, std::vector< ValueType > &&in_vector)
size_t begin
begin index
Definition: math.hpp:56
Context & context_
associated Context
Definition: dia_base.hpp:293