Skip to content

Commit

Permalink
more cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed Jan 21, 2025
1 parent 046acb4 commit 2b4c640
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 47 deletions.
8 changes: 8 additions & 0 deletions examples/multiport_mutation/consumer.hh
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* Copyright (C) 2025 TU Dresden
* All rights reserved.
*
* Authors:
* Tassilo Tanneberger
*/

#ifndef CONSUMER_HH // NOLINT
#define CONSUMER_HH // NOLINT

Expand Down
28 changes: 16 additions & 12 deletions examples/multiport_mutation/load_balancer.hh
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#ifndef LOAD_BALANCER_HH // NOLINT
#define LOAD_BALANCER_HH // NOLINT
/*
* Copyright (C) 2025 TU Dresden
* All rights reserved.
*
* Authors:
* Tassilo Tanneberger
*/

#include <reactor-cpp/reactor-cpp.hh>
#ifndef MULTIPORT_MUTATION_LOAD_BALANCER_HH // NOLINT
#define MULTIPORT_MUTATION_LOAD_BALANCER_HH // NOLINT

#include "reactor-cpp/mutations/multiport.hh"
#include <reactor-cpp/mutations/multiport.hh>
#include <reactor-cpp/reactor-cpp.hh>

using namespace reactor;
using namespace std::chrono_literals;
Expand All @@ -19,24 +26,21 @@ class LoadBalancer final : public Reactor { // NOLINT
if (std::rand() % 15 == 0) { // NOLINT
scale_bank.set(std::rand() % 20 + 1); // NOLINT
}
const unsigned sel = std::rand() % outbound.size(); // NOLINT
// std::cout << "Sending out to:" << sel << '\n';
outbound[sel].set(inbound.get());
outbound[std::min(4ul, outbound.size() - 1)].set(inbound.get());
const unsigned outbound_port = std::rand() % outbound.size(); // NOLINT
outbound[outbound_port].set(inbound.get());
}

friend LoadBalancer;
};

Inner _lf_inner;
Reaction process{"process", 2, this, [this]() { Inner::reaction_1(this->inbound, this->scale_bank, this->out); }};
Reaction process{"process", 1, this, [this]() { Inner::reaction_1(this->inbound, this->scale_bank, this->out); }};

public:
LoadBalancer(const std::string& name, Environment* env)
: Reactor(name, env)
, _lf_inner(this) {
out.reserve(4);
std::cout << "creating instance of load balancer" << '\n';
for (size_t _lf_idx = 0; _lf_idx < 4; _lf_idx++) {
out.create_new_port();
}
Expand All @@ -45,16 +49,16 @@ public:

ModifableMultiport<Output<unsigned>> out{"out", this}; // NOLINT
std::size_t out_size_ = 0;

Input<unsigned> inbound{"inbound", this}; // NOLINT
Output<unsigned> scale_bank{"scale_bank", this}; // NOLINT

void assemble() override {
std::cout << "assemble LoadBalancer\n";
for (auto& _lf_port : out) {
process.declare_antidependency(&_lf_port);
}
process.declare_trigger(&inbound);
}
};

#endif // LOAD_BALANCER_HH
#endif // MULTIPORT_MUTATION_LOAD_BALANCER_HH
12 changes: 9 additions & 3 deletions examples/multiport_mutation/main.cc
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
/*
* Copyright (C) 2025 TU Dresden
* All rights reserved.
*
* Authors:
* Tassilo Tanneberger
*/

#include <iostream>
#include <memory>

#include <reactor-cpp/mutations/bank.hh>
#include <reactor-cpp/mutations/connection.hh>
#include <reactor-cpp/reactor-cpp.hh>

#include "./consumer.hh"
#include "./load_balancer.hh"
#include "./multiport_to_bank.hh"
#include "./producer.hh"
#include <reactor-cpp/reactor-cpp.hh>

class Deployment final : public Reactor { // NOLINT

Expand Down
16 changes: 10 additions & 6 deletions examples/multiport_mutation/multiport_to_bank.hh
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
//
// Created by tanneberger on 1/13/25.
//
/*
* Copyright (C) 2025 TU Dresden
* All rights reserved.
*
* Authors:
* Tassilo Tanneberger
*/

#ifndef MULTIPORT_TO_BANK_HH
#define MULTIPORT_TO_BANK_HH
#ifndef MULTIPORT_MUTATION_MULTIPORT_TO_BANK_HH
#define MULTIPORT_MUTATION_MULTIPORT_TO_BANK_HH

#include <reactor-cpp/multiport.hh>
#include <reactor-cpp/mutations.hh>
Expand Down Expand Up @@ -88,4 +92,4 @@ public:
};
} // namespace reactor

#endif // MULTIPORT_TO_BANK_HH
#endif // MULTIPORT_MUTATION_MULTIPORT_TO_BANK_HH
14 changes: 11 additions & 3 deletions examples/multiport_mutation/producer.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#ifndef PRODUCER_HH // NOLINT
#define PRODUCER_HH // NOLINT
/*
* Copyright (C) 2025 TU Dresden
* All rights reserved.
*
* Authors:
* Tassilo Tanneberger
*/

#ifndef MULTIPORT_MUTATION_PRODUCER_HH // NOLINT
#define MULTIPORT_MUTATION_PRODUCER_HH // NOLINT

#include <reactor-cpp/reactor-cpp.hh>

Expand Down Expand Up @@ -44,4 +52,4 @@ public:
}
};

#endif // PRODUCER_HH
#endif // MULTIPORT_MUTATION_PRODUCER_HH
10 changes: 7 additions & 3 deletions include/reactor-cpp/mutations/bank.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//
// Created by tanneberger on 11/18/24.
//
/*
* Copyright (C) 2025 TU Dresden
* All rights reserved.
*
* Authors:
* Tassilo Tanneberger
*/

#ifndef REACTOR_CPP_MUTATIONS_BANK_HH
#define REACTOR_CPP_MUTATIONS_BANK_HH
Expand Down
10 changes: 7 additions & 3 deletions include/reactor-cpp/mutations/connection.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//
// Created by tanneberger on 11/18/24.
//
/*
* Copyright (C) 2025 TU Dresden
* All rights reserved.
*
* Authors:
* Tassilo Tanneberger
*/

#ifndef REACTOR_CPP_MUTATIONS_CONNECTION_HH
#define REACTOR_CPP_MUTATIONS_CONNECTION_HH
Expand Down
10 changes: 7 additions & 3 deletions include/reactor-cpp/mutations/multiport.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//
// Created by tanneberger on 11/11/24.
//
/*
* Copyright (C) 2025 TU Dresden
* All rights reserved.
*
* Authors:
* Tassilo Tanneberger
*/

#ifndef REACTOR_CPP_MUTATIONS_MULTIPORT_HH
#define REACTOR_CPP_MUTATIONS_MULTIPORT_HH
Expand Down
16 changes: 10 additions & 6 deletions lib/mutations/bank.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//
// Created by tanneberger on 11/11/24.
//
/*
* Copyright (C) 2025 TU Dresden
* All rights reserved.
*
* Authors:
* Tassilo Tanneberger
*/

#include "reactor-cpp/mutations/bank.hh"
#include "reactor-cpp/action.hh"
Expand All @@ -10,17 +14,17 @@ reactor::MutationChangeBankSize<T>::MutationChangeBankSize(
std::vector<T>* bank, Environment* env, std::size_t size,
std::function<T(Environment* env, std::size_t index)> create_lambda)
: bank_(bank)
, env_(env)
, desired_size_(size)
, env_(env)
, create_lambda_(std::move(create_lambda)) {}

template <class T> void reactor::MutationChangeBankSize<T>::change_size(std::size_t new_size) {
auto current_size = bank_->size();

if (current_size >= new_size) { // downscale
if (current_size >= new_size) { // down-size
bank_->resize(new_size);

} else { // upscale
} else { // up-size
bank_->reserve(new_size);

for (auto i = 0; i < new_size - current_size; i++) {
Expand Down
10 changes: 8 additions & 2 deletions lib/mutations/connection.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
/*
* Copyright (C) 2025 TU Dresden
* All rights reserved.
*
* Authors:
* Tassilo Tanneberger
*/

#include "reactor-cpp/mutations/connection.hh"
#include "reactor-cpp/reactor.hh"

#include <reactor-cpp/port.hh>

template <class A, class B>
reactor::MutationAddConnection<A, B>::MutationAddConnection(A* source, B* sink, Environment* env, bool add_connection)
: source_(source)
Expand Down
15 changes: 9 additions & 6 deletions lib/mutations/multiport.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// Created by tanneberger on 11/11/24.
//
/*
* Copyright (C) 2025 TU Dresden
* All rights reserved.
*
* Authors:
* Tassilo Tanneberger
*/

#include "reactor-cpp/mutations/multiport.hh"
#include "reactor-cpp/reaction.hh"

template <class T>
reactor::MutationChangeOutputMultiportSize<T>::MutationChangeOutputMultiportSize(
Expand All @@ -14,11 +17,11 @@ reactor::MutationChangeOutputMultiportSize<T>::MutationChangeOutputMultiportSize
template <class T> void reactor::MutationChangeOutputMultiportSize<T>::change_size(std::size_t new_size) {
auto current_size = multiport_->size();
if (current_size >= new_size) {
// downscale
// down-size
multiport_->resize(new_size);

} else {
// upscale
// up-size
multiport_->reserve(new_size);
for (auto i = 0; i < new_size - current_size; i++) {
std::string port_name_ = multiport_->name() + "_" + std::to_string(current_size + i);
Expand Down

0 comments on commit 2b4c640

Please sign in to comment.