Skip to content

Commit e088e96

Browse files
OmerMajNitiontanneberger
authored andcommitted
mutation fixes
Signed-off-by: tanneberger <[email protected]>
1 parent 2e4c112 commit e088e96

File tree

17 files changed

+69
-50
lines changed

17 files changed

+69
-50
lines changed

examples/multiport_mutation/consumer.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ private:
1818

1919
[[maybe_unused]] const Inner& __lf_inner = *this;
2020

21-
void reaction_1([[maybe_unused]] const Input<unsigned>& scale) {
22-
std::cout << "consumer: " << index_ << " received value!" << std::endl;
21+
void reaction_1([[maybe_unused]] const Input<unsigned>& in) {
22+
std::cout << "consumer: " << index_ << " received value:" << *in.get() << std::endl;
2323
}
2424

2525
friend Consumer;

examples/multiport_mutation/load_balancer.hh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ private:
2424
if (rand() % 30 == 0) {
2525
scale_action.schedule(rand() % 20 + 1);
2626
}
27-
28-
std::cout << "multiport size: " << outbound.size() << std::endl;
29-
outbound[rand() % outbound.size()].set(inbound.get());
27+
unsigned sel = rand() % outbound.size();
28+
std::cout << "Sending out to:" << sel << std::endl;
29+
outbound[sel].set(inbound.get());
3030
}
3131

3232
void reaction_2(ModifableMultiport<Output<unsigned>>&outbound, [[maybe_unused]] const LogicalAction<unsigned>& scale, Output<unsigned>& scale_bank) {
@@ -74,6 +74,7 @@ public:
7474
}
7575
process.declare_trigger(&inbound);
7676
scale.declare_trigger(&scale_action);
77+
scale.declare_antidependency(&scale_bank);
7778
}
7879
};
7980

examples/multiport_mutation/main.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ class Inner: public MutableScope {
4747
}
4848
} else {
4949
std::cout << "load_balancer size:" << load_balancer.size() << " bank size: " << reactor_bank.size() << std::endl;
50-
for (auto i = 0; i < new_size - old_size; i++) {
51-
std::cout << "add connection: " << i + old_size << std::endl;
52-
MutationAddConnection<Output<unsigned>, Input<unsigned>> add_conn{&load_balancer[i + old_size], &reactor_bank[i + old_size].get()->in, reactor_};
50+
for (auto i = 0; i < new_size; i++) {
51+
std::cout << "add connection: " << i << std::endl;
52+
MutationAddConnection<Output<unsigned>, Input<unsigned>> add_conn{&load_balancer[i], &reactor_bank[i].get()->in, reactor_};
5353
add_to_transaction(&add_conn);
54-
commit_transaction();
5554
}
55+
commit_transaction(true);
5656
}
5757

5858
std::cout << "new bank size:" << reactor_bank.size() << std::endl;
@@ -90,7 +90,7 @@ class Inner: public MutableScope {
9090

9191
auto main() -> int {
9292
//srand(time(nullptr));
93-
Environment env{4};
93+
Environment env{4, true};
9494
auto deployment = std::make_unique<Deployment>("c1", &env);
9595
env.optimize();
9696
env.assemble();

examples/multiport_mutation/producer.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ private:
1616
Reaction r_timer{"r_timer", 1, this, [this]() { __lf_inner.reaction_1(this->value);}};
1717

1818
class Inner: public Scope {
19+
unsigned itr = 0;
1920
[[maybe_unused]] const Inner& __lf_inner = *this;
2021
void reaction_1([[maybe_unused]] Output<unsigned>& out) {
21-
std::cout << "producing value" << std::endl;
22-
out.set(42);
22+
std::cout << "producing value:" << itr << std::endl;
23+
out.set(itr++);
2324
}
2425
explicit Inner(Reactor* reactor) : Scope(reactor) {}
2526

include/reactor-cpp/environment.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public:
8484
//TODO: fix visebility
8585
void calculate_indexes();
8686
void build_dependency_graph(Reactor* reactor);
87+
void clear_dependency_graph();
8788

8889

8990
explicit Environment(unsigned int num_workers, bool fast_fwd_execution = default_fast_fwd_execution,

include/reactor-cpp/graph.hh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ public:
5454
std::vector<std::pair<P, E>> edges{std::make_pair(properties, destination)};
5555
graph_[source] = edges;
5656
} else {
57-
graph_[source].emplace_back(properties, destination);
57+
auto &edges = graph_[source];
58+
auto duplicate = std::find_if(edges.begin(), edges.end(),
59+
[&](const std::pair<P, E>& edge) {
60+
return edge.first == properties && edge.second == destination;
61+
});
62+
if (duplicate == edges.end()) {
63+
graph_[source].emplace_back(properties, destination);
64+
}
5865
}
5966
}
6067

include/reactor-cpp/reaction.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ private:
2727
std::set<BasePort*> dependencies_;
2828

2929
const int priority_ = -1;
30-
const bool mutation_;
3130
unsigned int index_ = -1;
3231

3332
std::function<void(void)> body_{nullptr};
@@ -53,6 +52,7 @@ public:
5352
[[nodiscard]] auto port_triggers() const noexcept -> const auto& { return port_trigger_; }
5453

5554
[[maybe_unused]] [[nodiscard]] auto antidependencies() const noexcept -> const auto& { return antidependencies_; }
55+
[[maybe_unused]] void clear_antidependencies() noexcept { antidependencies_.clear(); }
5656

5757
[[nodiscard]] auto dependencies() const noexcept -> const auto& { return dependencies_; }
5858

include/reactor-cpp/scopes.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public:
4343
explicit MutableScope(Reactor* reactor) : Scope(reactor), transaction_(reactor), reactor_(reactor), env_(reactor->environment()) {}
4444
~MutableScope() = default;
4545

46-
void commit_transaction();
46+
void commit_transaction(bool recalculate = false);
4747
void add_to_transaction(Mutation* mutation);
4848

4949
};

include/reactor-cpp/transaction.hh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class Environment;
2121

2222
class Transaction {
2323
private:
24-
Reactor* parent_ = nullptr;
2524
Environment* environment_ = nullptr;
2625
std::vector<Mutation*> mutations_{};
2726

@@ -30,7 +29,7 @@ public:
3029
~Transaction() = default;
3130

3231
void push_back(Mutation* mutation);
33-
auto execute() -> MutationResult;
32+
auto execute(bool recalculate = false) -> MutationResult;
3433
};
3534
}
3635
#endif // REACTOR_CPP_TRANSACTION_HH

lib/environment.cc

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ void Environment::assemble() { // NOLINT(readability-function-cognitive-complexi
144144
}
145145
}
146146

147+
void Environment::clear_dependency_graph() {
148+
dependencies_.clear();
149+
reactions_.clear();
150+
}
151+
147152
void Environment::build_dependency_graph(Reactor* reactor) {
148153
// obtain dependencies from each contained reactor
149154
for (auto* sub_reactor : reactor->reactors()) {
@@ -157,23 +162,14 @@ void Environment::build_dependency_graph(Reactor* reactor) {
157162
validate(result.second, "priorities must be unique for all reactions_ of the same reactor");
158163
}
159164

160-
dependencies_.clear(); //TODO: fix
161-
162165
// connect all reactions_ this reaction depends on
163166
for (auto* reaction : reactor->reactions()) {
164-
std::set<BasePort*> dependencies = reaction->dependencies();
165-
for (auto* dependency : dependencies) {
166-
if (dependency <= (BasePort*)0x100) {
167-
std::cout << "FUCK" << std::endl;
168-
}
169-
while (dependency->has_inward_binding()) {
170-
if (dependency <= (BasePort*)0x100) {
171-
std::cout << "FUCK" << std::endl;
172-
}
173-
dependency = dependency->inward_binding();
167+
for (auto* dependency : reaction->dependencies()) {
168+
auto* source = dependency;
169+
while (source->has_inward_binding()) {
170+
source = source->inward_binding();
174171
}
175-
std::cout << "anti deps of: " << dependency->fqn() << "(" << dependency << ")" << std::endl;
176-
for (auto* antidependency : dependency->anti_dependencies()) {
172+
for (auto* antidependency : source->anti_dependencies()) {
177173
dependencies_.emplace_back(reaction, antidependency);
178174
}
179175
}

0 commit comments

Comments
 (0)