From 21c18406f090040c0c2215aa1738a9afaa93c51e Mon Sep 17 00:00:00 2001 From: KyleKlenk <kyle.c.klenk@gmail.com> Date: Wed, 29 Jun 2022 16:40:57 -0600 Subject: [PATCH] Can connect multiple clients to solve HRUs --- build/includes/global/global.hpp | 2 + build/includes/global/message_atoms.hpp | 2 + build/includes/summa_actor/batch_manager.hpp | 4 -- build/includes/summa_actor/summa_server.hpp | 3 +- build/source/actors/hru_actor/hru_actor.cpp | 2 - build/source/actors/main.cpp | 2 +- .../actors/summa_actor/batch_manager.cpp | 4 ++ .../actors/summa_actor/summa_client.cpp | 1 + .../actors/summa_actor/summa_server.cpp | 72 +++++++------------ 9 files changed, 36 insertions(+), 56 deletions(-) diff --git a/build/includes/global/global.hpp b/build/includes/global/global.hpp index 4e09056..eb6835a 100644 --- a/build/includes/global/global.hpp +++ b/build/includes/global/global.hpp @@ -7,10 +7,12 @@ #include <unistd.h> #include "json.hpp" + using json = nlohmann::json; extern bool debug; + /** * Return the time between to time points */ diff --git a/build/includes/global/message_atoms.hpp b/build/includes/global/message_atoms.hpp index b28f3c0..11b425b 100644 --- a/build/includes/global/message_atoms.hpp +++ b/build/includes/global/message_atoms.hpp @@ -1,5 +1,7 @@ #pragma once +#include "../summa_actor/batch_manager.hpp" + CAF_BEGIN_TYPE_ID_BLOCK(summa, first_custom_type_id) // Summa Actor CAF_ADD_ATOM(summa, start_summa) diff --git a/build/includes/summa_actor/batch_manager.hpp b/build/includes/summa_actor/batch_manager.hpp index 83c6056..884f2c6 100644 --- a/build/includes/summa_actor/batch_manager.hpp +++ b/build/includes/summa_actor/batch_manager.hpp @@ -40,13 +40,9 @@ class Batch { void assignedBatch(); void updateRunTime(double run_time); - }; - - - class Batch_Manager { private: std::vector<Batch> batch_list; diff --git a/build/includes/summa_actor/summa_server.hpp b/build/includes/summa_actor/summa_server.hpp index 8653e0c..1bd7b9c 100644 --- a/build/includes/summa_actor/summa_server.hpp +++ b/build/includes/summa_actor/summa_server.hpp @@ -13,6 +13,8 @@ struct summa_server_state { int total_hru_count; int num_clients; int num_hru_per_batch; + int batches_remaining = 0; + int batches_solved = 0; std::string config_path; std::vector<Batch*> batch_list; std::vector<Batch> solved_batches; @@ -21,7 +23,6 @@ struct summa_server_state { }; behavior summa_server(stateful_actor<summa_server_state>* self, std::string config_path); -int parseSettings(stateful_actor<summa_server_state>* self, std::string config_path); int assembleBatches(stateful_actor<summa_server_state>* self); Batch* getUnsolvedBatch(stateful_actor<summa_server_state>* self); } \ No newline at end of file diff --git a/build/source/actors/hru_actor/hru_actor.cpp b/build/source/actors/hru_actor/hru_actor.cpp index fb1e347..641f2b8 100644 --- a/build/source/actors/hru_actor/hru_actor.cpp +++ b/build/source/actors/hru_actor/hru_actor.cpp @@ -3,9 +3,7 @@ #include "global.hpp" #include "message_atoms.hpp" #include "hru_actor_subroutine_wrappers.hpp" -#include "json.hpp" -using json = nlohmann::json; namespace caf { diff --git a/build/source/actors/main.cpp b/build/source/actors/main.cpp index cf370c0..1aa2a47 100644 --- a/build/source/actors/main.cpp +++ b/build/source/actors/main.cpp @@ -10,7 +10,7 @@ #include <unistd.h> #include <iostream> #include "json.hpp" - +#include "batch_manager.hpp" using namespace caf; diff --git a/build/source/actors/summa_actor/batch_manager.cpp b/build/source/actors/summa_actor/batch_manager.cpp index b3d8576..aa777d5 100644 --- a/build/source/actors/summa_actor/batch_manager.cpp +++ b/build/source/actors/summa_actor/batch_manager.cpp @@ -9,6 +9,8 @@ Batch::Batch(int batch_id, int start_hru, int num_hru) { this->status = unassigned; } + + void Batch::printBatchInfo() { std::cout << "batch_id: " << this->batch_id << "\n"; std::cout << "start_hru: " << this->start_hru << "\n"; @@ -42,3 +44,5 @@ void Batch::assignedBatch() { void Batch::updateRunTime(double run_time) { this->run_time = run_time; } + + diff --git a/build/source/actors/summa_actor/summa_client.cpp b/build/source/actors/summa_actor/summa_client.cpp index ab2f7ff..cfea2af 100644 --- a/build/source/actors/summa_actor/summa_client.cpp +++ b/build/source/actors/summa_actor/summa_client.cpp @@ -4,6 +4,7 @@ #include "summa_client.hpp" #include "summa_actor.hpp" #include "message_atoms.hpp" +#include "batch_manager.hpp" #include <unistd.h> #include <limits.h> diff --git a/build/source/actors/summa_actor/summa_server.cpp b/build/source/actors/summa_actor/summa_server.cpp index da7c2b8..d696941 100644 --- a/build/source/actors/summa_actor/summa_server.cpp +++ b/build/source/actors/summa_actor/summa_server.cpp @@ -1,13 +1,10 @@ #include "caf/all.hpp" #include "caf/io/all.hpp" -#include "json.hpp" #include <string> #include "batch_manager.hpp" #include "summa_server.hpp" #include "message_atoms.hpp" - - -using json = nlohmann::json; +#include "global.hpp" namespace caf { @@ -15,19 +12,20 @@ namespace caf { behavior summa_server(stateful_actor<summa_server_state>* self, std::string config_path) { aout(self) << "Summa Server has Started \n"; self->state.config_path = config_path; - if (parseSettings(self, config_path) == -1) { - aout(self) << "ERROR WITH JSON SETTINGS FILE!!\n"; - aout(self) << "Summa_Server_Actor Exiting\n"; - self->quit(); - } else { - aout(self) << "-------------------------------------\n"; - aout(self) << "-----Summa_Server_Actor_Settings-----\n"; - aout(self) << "Total HRUs to compute = " << self->state.total_hru_count << "\n"; - aout(self) << "Number of HRUs per batch = " << self->state.num_hru_per_batch << "\n"; - aout(self) << "-------------------------------------\n"; + + self->state.total_hru_count = getSettings(self->state.config_path, "SimulationSettings", "total_hru_count", + self->state.total_hru_count).value_or(-1); + if (self->state.total_hru_count == -1) { + aout(self) << "ERROR: With total_hru_count - CHECK Summa_Actors_Settings.json\n"; + } + self->state.num_hru_per_batch = getSettings(self->state.config_path, "SimulationSettings", "num_hru_per_batch", + self->state.num_hru_per_batch).value_or(-1); + if (self->state.num_hru_per_batch == -1) { + aout(self) << "ERROR: With num_hru_per_batch - CHECK Summa_Actors_Settings.json\n"; } aout(self) << "Assembling HRUs into Batches\n"; + if (assembleBatches(self) == -1) { aout(self) << "ERROR: assembleBatches\n"; } else { @@ -52,9 +50,17 @@ behavior summa_server(stateful_actor<summa_server_state>* self, std::string conf }, [=](done_batch, actor client, double duration, int batch_id) { - aout(self) << "Client has Solved Batch " << batch_id << "\n"; + aout(self) << "Client finished batch: " << batch_id << "\n"; self->state.batch_list[batch_id]->solvedBatch(); + self->state.batches_solved++; + self->state.batches_remaining = self->state.batch_list.size() - self->state.batches_solved; + + aout(self) << "\n****************************************\n"; + aout(self) << "Batches Solved = " << self->state.batches_solved << "\n"; + aout(self) << "Batches Remaining = " << self->state.batches_remaining << "\n"; + aout(self) << "****************************************\n"; + // Find a new batch Batch *batch_to_send = getUnsolvedBatch(self); if (batch_to_send == NULL) { @@ -63,6 +69,9 @@ behavior summa_server(stateful_actor<summa_server_state>* self, std::string conf self->send(self->state.client_list[i]->getActor(), time_to_exit_v); } + self->quit(); + return; + } else { self->send(client, batch_v, batch_to_send->getBatchID(), batch_to_send->getStartHRU(), batch_to_send->getNumHRU(), self->state.config_path); @@ -72,39 +81,6 @@ behavior summa_server(stateful_actor<summa_server_state>* self, std::string conf }; } -int parseSettings(stateful_actor<summa_server_state>* self, std::string config_path) { - json settings; - std::string SummaActorsSettings = "/Summa_Actors_Settings.json"; - std::ifstream settings_file(config_path + SummaActorsSettings); - settings_file >> settings; - settings_file.close(); - - if (settings.find("SimulationSettings") != settings.end()) { - json simulation_settings = settings["SimulationSettings"]; - - if (simulation_settings.find("total_hru_count") != simulation_settings.end()) { - self->state.total_hru_count = simulation_settings["total_hru_count"]; - } else { - aout(self) << "ERROR Finding Total HRU Count - Exiting because the number " << - "of HRUs to compute is unknown\n"; - return -1; - } - - if (simulation_settings.find("num_hru_per_batch") != simulation_settings.end()) { - self->state.num_hru_per_batch = simulation_settings["num_hru_per_batch"]; - } else { - aout(self) << "ERROR Finding initial value for the number of HRUs in a batch " << - "setting num_hru_per_batch to default value of 500\n"; - self->state.num_hru_per_batch = 500; - } - - return 0; - - } else { - aout(self) << "Error Finding SimulationSettings in JSON File - Exiting as Num"; - return -1; - } -} int assembleBatches(stateful_actor<summa_server_state>* self) { int remaining_hru_to_batch = self->state.total_hru_count; -- GitLab