functional-dag
Loading...
Searching...
No Matches
dag_fanout_impl.hpp
1#pragma once
2// ---------------------------------------------
3// ___ .___
4// |_ \ __| _/____ ____
5// / \ ______ / __ |\__ \ / ___\
6// / /\ \ /_____/ / /_/ | / __ \_/ /_/ >
7// /_/ \__\ \____ |(____ /\___ /
8// \/ \//_____/
9// ---------------------------------------------
10// @author ndepalma@alum.mit.edu
11
12#include <string>
13#include <vector>
14#include <iostream>
15#include <future>
16#include <thread>
17
18#include <functional_dag/impl/dag_node_impl.hpp>
19#include <functional_dag/core/dag_utils.hpp>
20
21namespace fn_dag {
22
28 template <typename Type, typename IDType>
30 private:
31 const fn_dag::_dag_context &g_context; // Shared state
32 vector< _abstract_internal_dag_node<Type, IDType> *> m_children; // Children to fan-out to
33
39 m_children.push_back(_new_node);
40 }
41
42 public:
51 g_context(_context),
52 m_children() {}
55 for(auto internal_dag : m_children)
56 delete internal_dag;
57 m_children.clear();
58 }
59
72 if(!g_context.run_single_threaded) {
73 std::vector<thread> child_threads;
74
75 for(auto it : m_children)
76 child_threads.push_back(thread(&fn_dag::_abstract_internal_dag_node<Type, IDType>::run_filter, it, std::ref(_data)));
77
78 for(uint32_t i = 0;i < child_threads.size();i++)
80 } else
81 for(auto it : m_children)
82 it->run_filter(_data);
83
84 delete _data;
85 }
86
94 void print(string _indent) {
95 string plus = _indent+g_context.indent_str;
96 for(auto child : m_children) {
97 *g_context.log << _indent << "->";
99 }
100 }
101
114 template <typename In, typename Out>
116 const IDType _onto,
117 const IDType _parent_id) {
118 if(_onto == _parent_id) {
120 return true;
121 } else {
122 for(auto child = m_children.cbegin();child != m_children.cend();child++) {
123 auto *internal_child = static_cast<_internal_dag_node<In, Type, IDType> *>(*child);
125 if(fanout_node->add_node_to_subdag(_node_to_add, _onto, (*child)->get_id()))
126 return true;
127 }
128 }
129
130 return false;
131 }
132 };
133}
Internal node to take data from parent and run children.
Definition dag_fanout_impl.hpp:29
bool add_node_to_subdag(_internal_dag_node< In, Out, IDType > *_node_to_add, const IDType _onto, const IDType _parent_id)
Recursively adds a node to children.
Definition dag_fanout_impl.hpp:115
~dag_fanout_node()
Standard deconstructor.
Definition dag_fanout_impl.hpp:54
void print(string _indent)
Printing function
Definition dag_fanout_impl.hpp:94
dag_fanout_node(const _dag_context &_context)
This node uses data computed from the previous node to fan-out to it's children.
Definition dag_fanout_impl.hpp:50
void fan_out(Type *_data)
Function to do it's job.
Definition dag_fanout_impl.hpp:71
The main DAG function that encapulates generation and mapping of the data across the DAG.
Definition dag_impl.hpp:59
void print()
Simple print function to print the ID of this DAG and it's children.
Definition dag_impl.hpp:148
IDType get_id()
Simple getter for the ID of the DAG itself.
Definition dag_impl.hpp:102