diff --git a/build/includes/global/message_atoms.hpp b/build/includes/global/message_atoms.hpp index 99478e2e1ebfa424b97e74d38deddbb7f8fb3ba2..ad70432e2ba8a13dd3ca25ed03c4e35c51536334 100644 --- a/build/includes/global/message_atoms.hpp +++ b/build/includes/global/message_atoms.hpp @@ -45,7 +45,7 @@ CAF_BEGIN_TYPE_ID_BLOCK(summa, first_custom_type_id) CAF_ADD_ATOM(summa, dt_init_factor) // Client Actor CAF_ADD_ATOM(summa, connect_to_server) - CAF_ADD_ATOM(summa, batch) + CAF_ADD_ATOM(summa, compute_batch) // Server Actor CAF_ADD_ATOM(summa, done_batch) CAF_ADD_ATOM(summa, time_to_exit) @@ -56,4 +56,7 @@ CAF_BEGIN_TYPE_ID_BLOCK(summa, first_custom_type_id) CAF_ADD_TYPE_ID(summa, (File_Access_Actor_Settings)) CAF_ADD_TYPE_ID(summa, (Job_Actor_Settings)) CAF_ADD_TYPE_ID(summa, (HRU_Actor_Settings)) + + // Class Types + CAF_ADD_TYPE_ID(summa, (Batch)) CAF_END_TYPE_ID_BLOCK(summa) \ No newline at end of file diff --git a/build/includes/summa_actor/batch_manager.hpp b/build/includes/summa_actor/batch_manager.hpp index cca0837a11c2cd815b3ebb9e679300932b68cefc..182dbba74b1c3d75ed0209fac8744eef37b279e0 100644 --- a/build/includes/summa_actor/batch_manager.hpp +++ b/build/includes/summa_actor/batch_manager.hpp @@ -3,6 +3,7 @@ #include <vector> #include <string> +class Batch; enum batch_status { unassigned, @@ -11,73 +12,93 @@ enum batch_status { failed }; -struct Batch_Struct { - int batch_id; - int start_hru; - int num_hru; - - double run_time; - double read_time; - double write_time; - - std::string assigned_host; - caf::actor assigned_actor; - bool assigned; -}; - -template<class Inspector> -bool inspect(Inspector& inspector, Batch_Struct& batch) { - return inspector.object(batch).fields( - inspector.field("batch_id", batch.batch_id), - inspector.field("start_hru",batch.start_hru), - inspector.field("num_hru", batch.num_hru), - inspector.field("run_time", batch.run_time), - inspector.field("write_time",batch.write_time), - inspector.field("assigned_host", batch.assigned_host), - inspector.field("assigned_actor", batch.assigned_actor), - inspector.field("assigned", batch.assigned)); -} - -class Batch { +class Batch{ private: int batch_id; int start_hru; int num_hru; - double run_time; - double read_time; - double write_time; + bool assigned_to_actor; + + public: + Batch(int batch_id = -1, int start_hru = -1, int num_hru = -1); + + int getBatchID(); + + bool getBatchStatus(); + + + template <class Inspector> + friend bool inspect(Inspector& inspector, Batch& batch) { + return inspector.object(batch).fields( + inspector.field("batch_id", batch.batch_id), + inspector.field("start_hru", batch.start_hru), + inspector.field("num_hru", batch.num_hru), + inspector.field("status", batch.assigned_to_actor)); + } +}; + + + + +// class Batch { +// private: +// int batch_id; +// int start_hru; +// int num_hru; + + // double run_time = -1; + // double read_time = -1; + // double write_time = -1; - std::string assigned_host; - caf::actor assigned_actor; - batch_status status; +// std::string assigned_host; +// caf::actor assigned_actor; +// // batch_status status; - public: - Batch(int batch_id, int start_hru, int num_hru); +// public: +// Batch(int batch_id = -1, int start_hru = -1, int num_hru = -1); - void printBatchInfo(); +// // void printBatchInfo(); - batch_status getBatchStatus(); +// // batch_status getBatchStatus(); - int getBatchID(); +// // int getBatchID(); - int getStartHRU(); +// // int getStartHRU(); - int getNumHRU(); +// // int getNumHRU(); - void solvedBatch(double run_time, double read_time, double write_time); +// // void solvedBatch(double run_time, double read_time, double write_time); - void assignedBatch(std::string hostname, caf::actor actor_ref); +// // void assignedBatch(std::string hostname, caf::actor actor_ref); - void updateRunTime(double run_time); +// // void updateRunTime(double run_time); - void writeBatchToFile(std::string file_name); -}; +// // void writeBatchToFile(std::string file_name); + +// template <class Inspector> +// friend bool inspect(Inspector& inspector, Batch& batch) { +// return inspector.object(batch).fields( +// inspector.field("batch_id", batch.batch_id), +// inspector.field("start_hru", batch.start_hru), +// inspector.field("num_hru", batch.num_hru), +// inspector.field("run_time", batch.run_time), +// inspector.field("read_time", batch.read_time), +// inspector.field("write_time", batch.write_time), +// inspector.field("assigned_host", batch.assigned_host), +// inspector.field("assigned_actor", batch.assigned_actor), +// inspector.field("status", batch.status)); +// } +// }; -class Batch_Manager { +class Batch_Container { private: + int total_hru_count; + int num_hru_per_batch; + + std::vector<Batch> batch_list; std::vector<Batch> solved_batches; std::vector<Batch> failed_batches; @@ -85,13 +106,12 @@ class Batch_Manager { public: /** - * Assemble the total number of HRUs given by the user into batches. - * The total number of hrus and the sizes of the batches are parameters - * provided by the user. + * @brief Construct a new Batch_Container object + * Creating the batch_manager will also create the batches + * with the two parameters that are passed in. */ - void assembleBatches(int total_hru_count, int num_hru_per_batch); - - + Batch_Container(int total_hru_count, int num_hru_per_batch); + /** * Assign a batch to be solved by a client. * The hostname and the actor_ref of the client solving this batch @@ -100,29 +120,39 @@ class Batch_Manager { */ Batch assignBatch(std::string hostname, caf::actor actor_ref); - /** * On a successful batch we take the batch given to us by the client * and add it to our solved_batches list. * * We can then remove the batch from the global batch list. */ - void batchSuccess(Batch successful_batch, std::string output_csv); - + void updateBatch_success(Batch successful_batch, std::string output_csv); /** * A batch failure is returned to us by the client * This is for when a client failed to solve the batch. */ - void batchFailure(Batch failed_batch); - + void updateBatch_failure(Batch failed_batch); /** * A client has found to be disconnected. Unassign all batches * that were assigned to the disconnected client. The client id * is passed in as a parameter */ - void disconnected_client(int client_id); + void updatedBatch_disconnectedClient(int client_id); + + /** + * Create the csv file for the completed batches. + */ + void inititalizeCSVOutput(std::string csv_output_name); + + private: + /** + * Assemble the total number of HRUs given by the user into batches. + * The total number of hrus and the sizes of the batches are parameters + * provided by the user. + */ + void assembleBatches(int total_hru_count, int num_hru_per_batch); diff --git a/build/includes/summa_actor/client.hpp b/build/includes/summa_actor/client.hpp index 29e0a7024862337fb6e0e4632a58a3012b7245f2..876e8c701d28edfcdbb249ec7bdb8ffe28aecedb 100644 --- a/build/includes/summa_actor/client.hpp +++ b/build/includes/summa_actor/client.hpp @@ -2,6 +2,7 @@ #include "caf/all.hpp" #include "batch_manager.hpp" +#include <vector> class Client { @@ -23,4 +24,30 @@ class Client { std::string getHostname(); +}; + + +class Client_Container { + private: + int num_clients = 0; + + std::vector<Client> client_list; + + + public: + /** + * @brief Construct a new Client_Container object + */ + Client_Container(); + + /** + * @brief add a client to the client vector + * increment the number of clients + * + * @param client_actor connecting cleint actor_ref + * @param hostname name of the host that client actor is connecting + * from + */ + void addClient(caf::actor client_actor, std::string hostname); + }; \ No newline at end of file diff --git a/build/includes/summa_actor/summa_server.hpp b/build/includes/summa_actor/summa_server.hpp index 69282b1b49ee9d91c2bf92dd4ad32e1a1e92e42a..5844358f0b12247a3845c66c36e0e4f9bb8cd4ff 100644 --- a/build/includes/summa_actor/summa_server.hpp +++ b/build/includes/summa_actor/summa_server.hpp @@ -21,7 +21,9 @@ struct summa_server_state { std::vector<Batch> failed_batches; std::vector<Client> client_list; std::string csv_output_name; - + + Client_Container client_container; + // Batch_Container batch_container; Distributed_Settings distributed_settings; Summa_Actor_Settings summa_actor_settings; @@ -34,6 +36,7 @@ struct summa_server_state { behavior summa_server(stateful_actor<summa_server_state>* self, Distributed_Settings distributed_settings, Summa_Actor_Settings summa_actor_settings, File_Access_Actor_Settings file_access_actor_settings, Job_Actor_Settings job_actor_settings, HRU_Actor_Settings hru_actor_settings); + int assembleBatches(stateful_actor<summa_server_state>* self); std::optional<int> getUnsolvedBatchID(stateful_actor<summa_server_state>* self); void initializeCSVOutput(std::string csv_output_name); diff --git a/build/source/actors/main.cpp b/build/source/actors/main.cpp index 20bfd59e2f63e502e9802308f2d22ca006153b5f..78b02269400d50b6357eeb48f706dc7c499a66e9 100644 --- a/build/source/actors/main.cpp +++ b/build/source/actors/main.cpp @@ -67,7 +67,11 @@ void run_server(actor_system& system, const config& cfg, Distributed_Settings di return; } auto server = system.spawn(summa_server, distributed_settings, - summa_actor_settings, file_access_actor_settings, job_actor_settings, hru_actor_settings); + summa_actor_settings, + file_access_actor_settings, + job_actor_settings, + hru_actor_settings); + aout(self) << "Attempting to publish summa_server_actor on port " << distributed_settings.port << std::endl; auto is_port = io::publish(server, distributed_settings.port); if (!is_port) { diff --git a/build/source/actors/summa_actor/batch_manager.cpp b/build/source/actors/summa_actor/batch_manager.cpp index 85beab394bedbff8e9ce337cb670938afb87baf6..e4d466ffcda3366f27bfc0d8953cae3fdbe1ae6c 100644 --- a/build/source/actors/summa_actor/batch_manager.cpp +++ b/build/source/actors/summa_actor/batch_manager.cpp @@ -2,67 +2,106 @@ #include <vector> #include "batch_manager.hpp" -Batch::Batch(int batch_id, int start_hru, int num_hru) { - this->batch_id = batch_id; - this->start_hru = start_hru; - this->num_hru = num_hru; - this->status = unassigned; -} +Batch_Container::Batch_Container(int total_hru_count, int num_hru_per_batch) { + this->total_hru_count = total_hru_count; + this->num_hru_per_batch = num_hru_per_batch; + + this->assembleBatches(this->total_hru_count, this->num_hru_per_batch); +} +void Batch_Container::assembleBatches(int total_hru_count, int num_hru_per_batch) { + int remaining_hru_to_batch = total_hru_count; + int count_index = 0; + int start_hru = 1; -void Batch::printBatchInfo() { - std::cout << "batch_id: " << this->batch_id << "\n"; - std::cout << "start_hru: " << this->start_hru << "\n"; - std::cout << "num_hru: " << this->num_hru << "\n"; + // while(remaining_hru_to_batch > 0) { + // if (num_hru_per_batch > remaining_hru_to_batch) { + // batch_list.push_back(Batch(count_index, start_hru, remaining_hru_to_batch)); + // remaining_hru_to_batch = 0; + // } else { + // batch_list.push_back(Batch(count_index, start_hru, num_hru_per_batch)); + + // remaining_hru_to_batch -= self->state.distributed_settings.num_hru_per_batch; + // start_hru += self->state.distributed_settings.num_hru_per_batch; + // count_index += 1; + // } + // } + // return 0; } -batch_status Batch::getBatchStatus() { - return this->status; + + +Batch::Batch(int batch_id, int start_hru, int num_hru){ + this->batch_id = batch_id; + this->start_hru = start_hru; + this->num_hru = num_hru; + this->assigned_to_actor = false; } + +// Setters int Batch::getBatchID() { return this->batch_id; } -int Batch::getStartHRU() { - return this->start_hru; +bool Batch::getBatchStatus() { + return this->assigned_to_actor; } -int Batch::getNumHRU() { - return this->num_hru; -} -void Batch::solvedBatch(double run_time, double read_time, double write_time) { - this->status = solved; - this->run_time = run_time; - this->read_time = read_time; - this->write_time = write_time; -} +// void Batch::printBatchInfo() { +// std::cout << "batch_id: " << this->batch_id << "\n"; +// std::cout << "start_hru: " << this->start_hru << "\n"; +// std::cout << "num_hru: " << this->num_hru << "\n"; +// } -void Batch::assignedBatch(std::string hostname, caf::actor actor_ref) { - this->status = assigned; - this->assigned_host = hostname; - this->assigned_actor = actor_ref; -} +// batch_status Batch::getBatchStatus() { +// return this->status; +// } -void Batch::updateRunTime(double run_time) { - this->run_time = run_time; -} +// int Batch::getBatchID() { +// return this->batch_id; +// } -void Batch::writeBatchToFile(std::string file_name) { - std::ofstream output_file; - output_file.open(file_name, std::ios_base::app); - output_file << - this->batch_id << "," << - this->start_hru << "," << - this->num_hru << "," << - this->assigned_host << "," << - this->run_time << "," << - this->read_time << "," << - this->write_time << "," << - this->status << "\n"; - output_file.close(); -} +// int Batch::getStartHRU() { +// return this->start_hru; +// } + +// int Batch::getNumHRU() { +// return this->num_hru; +// } + +// void Batch::solvedBatch(double run_time, double read_time, double write_time) { +// this->status = solved; +// this->run_time = run_time; +// this->read_time = read_time; +// this->write_time = write_time; +// } + +// void Batch::assignedBatch(std::string hostname, caf::actor actor_ref) { +// this->status = assigned; +// this->assigned_host = hostname; +// this->assigned_actor = actor_ref; +// } + +// void Batch::updateRunTime(double run_time) { +// this->run_time = run_time; +// } + +// void Batch::writeBatchToFile(std::string file_name) { +// std::ofstream output_file; +// output_file.open(file_name, std::ios_base::app); +// output_file << +// this->batch_id << "," << +// this->start_hru << "," << +// this->num_hru << "," << +// this->assigned_host << "," << +// this->run_time << "," << +// this->read_time << "," << +// this->write_time << "," << +// this->status << "\n"; +// output_file.close(); +// } diff --git a/build/source/actors/summa_actor/client.cpp b/build/source/actors/summa_actor/client.cpp index b2e868a47a0d1ae6f2c36f3df02a3cfb75886b74..cea1b9b10a2f8c839ce52b83b0daba273a09d542 100644 --- a/build/source/actors/summa_actor/client.cpp +++ b/build/source/actors/summa_actor/client.cpp @@ -22,4 +22,16 @@ int Client::getID() { std::string Client::getHostname() { return this->hostname; -} \ No newline at end of file +} + + +Client_Container::Client_Container() {} + +void Client_Container::addClient(caf::actor client_actor, std::string hostname) { + int client_id = this->num_clients; + + this->client_list.push_back( + Client{client_id, client_actor, hostname}); + + this->num_clients++; +} diff --git a/build/source/actors/summa_actor/summa_client.cpp b/build/source/actors/summa_actor/summa_client.cpp index e8dfa8311133994445cce1b827c856efe756fe20..6e7028df0071a947b0efa10bbe3817a9f2644a26 100644 --- a/build/source/actors/summa_actor/summa_client.cpp +++ b/build/source/actors/summa_actor/summa_client.cpp @@ -87,10 +87,12 @@ behavior running(stateful_actor<summa_client_state>* self, const actor& server_a }, - // [=](compute_batch) {} + [=](Batch& batch) { + aout(self) << batch.getBatchID() << std::endl; + }, - [=](batch, int client_id, int batch_id, int start_hru, int num_hru, std::string config_path) { + [=](compute_batch, int client_id, int batch_id, int start_hru, int num_hru, std::string config_path) { aout(self) << "\nReceived batch to compute" << "\n"; aout(self) << "BatchID = " << batch_id << "\n"; aout(self) << "Start HRU = " << start_hru << "\n"; diff --git a/build/source/actors/summa_actor/summa_server.cpp b/build/source/actors/summa_actor/summa_server.cpp index 68389ead371c4a0979e23153c6e65a24eb02c982..5f5b3ac0ea79f98d8adb05bfb7e05de3a7aebf8d 100644 --- a/build/source/actors/summa_actor/summa_server.cpp +++ b/build/source/actors/summa_actor/summa_server.cpp @@ -21,27 +21,35 @@ behavior summa_server(stateful_actor<summa_server_state>* self, Distributed_Sett self->state.job_actor_settings = job_actor_settings; self->state.hru_actor_settings = hru_actor_settings; + self->state.client_container = Client_Container(); + // self->state.batch_manager = Batch_Manager(); - self->state.csv_output_name = "Batch_Results.csv"; - initializeCSVOutput(self->state.csv_output_name); + // self->state.csv_output_name = "Batch_Results.csv"; + // initializeCSVOutput(self->state.csv_output_name); - aout(self) << "Assembling HRUs into Batches\n"; - if (assembleBatches(self) == -1) { - aout(self) << "ERROR: assembleBatches\n"; - } else { - aout(self) << "HRU Batches Assembled, Ready For Clients to Connect \n"; + // aout(self) << "Assembling HRUs into Batches\n"; + // if (assembleBatches(self) == -1) { + // aout(self) << "ERROR: assembleBatches\n"; + // } else { + // aout(self) << "HRU Batches Assembled, Ready For Clients to Connect \n"; - for (std::vector<int>::size_type i = 0; i < self->state.batch_list.size(); i++) { - self->state.batch_list[i].printBatchInfo(); - } - } + // for (std::vector<int>::size_type i = 0; i < self->state.batch_list.size(); i++) { + // self->state.batch_list[i].printBatchInfo(); + // } + // } return { - [=](connect_to_server, actor client, std::string hostname) { - // Client is connecting - Add it to our client list and assign it a batch + /** + * @brief A message from a client requresting to connect + * + * @param client the actor_ref of the client_actor + * (used to send messages to the client_actor) + * @param hostname human readable hostname of the machine that the actor is running on + */ + [=](connect_to_server, actor client_actor, std::string hostname) { + // self->send(client, Batch{3,4,5}); aout(self) << "Actor trying to connect with hostname " << hostname << "\n"; - int client_id = self->state.client_list.size(); // So we can lookup the client in O(1) time - self->state.client_list.push_back(Client(client_id, client, hostname)); + self->state.client_container.addClient(client_actor, hostname); // Tell client they are connected self->send(client, connect_to_server_v, client_id, self->state.summa_actor_settings, @@ -49,81 +57,81 @@ behavior summa_server(stateful_actor<summa_server_state>* self, Distributed_Sett - std::optional<int> batch_id = getUnsolvedBatchID(self); - if (batch_id.has_value()) { - // update the batch in the batch list with the host and actor_ref - self->state.batch_list[batch_id.value()].assignedBatch(self->state.client_list[client_id].getHostname(), client); + // std::optional<int> batch_id = getUnsolvedBatchID(self); + // if (batch_id.has_value()) { + // // update the batch in the batch list with the host and actor_ref + // self->state.batch_list[batch_id.value()].assignedBatch(self->state.client_list[client_id].getHostname(), client); - int start_hru = self->state.batch_list[batch_id.value()].getStartHRU(); - int num_hru = self->state.batch_list[batch_id.value()].getNumHRU(); - - self->send(client, - batch_v, - client_id, - batch_id.value(), - start_hru, - num_hru, - self->state.config_path); - - } else { - - aout(self) << "We Are Done - Telling Clients to exit \n"; - for (std::vector<int>::size_type i = 0; i < self->state.client_list.size(); i++) { - self->send(self->state.client_list[i].getActor(), time_to_exit_v); - } - self->quit(); - return; - } + // int start_hru = self->state.batch_list[batch_id.value()].getStartHRU(); + // int num_hru = self->state.batch_list[batch_id.value()].getNumHRU(); + + // self->send(client, + // compute_batch_v, + // client_id, + // batch_id.value(), + // start_hru, + // num_hru, + // self->state.config_path); + + // } else { + + // aout(self) << "We Are Done - Telling Clients to exit \n"; + // for (std::vector<int>::size_type i = 0; i < self->state.client_list.size(); i++) { + // self->send(self->state.client_list[i].getActor(), time_to_exit_v); + // } + // self->quit(); + // return; + // } }, [=](done_batch, actor client, int client_id, int batch_id, double total_duration, double total_read_duration, double total_write_duration) { - self->state.batch_list[batch_id].solvedBatch(total_duration, total_read_duration, total_write_duration); - self->state.batch_list[batch_id].writeBatchToFile(self->state.csv_output_name); - self->state.batches_solved++; - self->state.batches_remaining = self->state.batch_list.size() - self->state.batches_solved; - - aout(self) << "\n****************************************\n"; - aout(self) << "Client finished batch: " << batch_id << "\n"; - aout(self) << "Client hostname = " << self->state.client_list[client_id].getHostname() << "\n"; - aout(self) << "Total Batch Duration = " << total_duration << "\n"; - aout(self) << "Total Batch Read Duration = " << total_read_duration << "\n"; - aout(self) << "Total Batch Write Duration = " << total_write_duration << "\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 - std::optional<int> new_batch_id = getUnsolvedBatchID(self); - if (new_batch_id.has_value()) { - // update the batch in the batch list with the host and actor_ref - self->state.batch_list[new_batch_id.value()].assignedBatch(self->state.client_list[client_id].getHostname(), client); + // self->state.batch_list[batch_id].solvedBatch(total_duration, total_read_duration, total_write_duration); + // self->state.batch_list[batch_id].writeBatchToFile(self->state.csv_output_name); + // self->state.batches_solved++; + // self->state.batches_remaining = self->state.batch_list.size() - self->state.batches_solved; + + // aout(self) << "\n****************************************\n"; + // aout(self) << "Client finished batch: " << batch_id << "\n"; + // aout(self) << "Client hostname = " << self->state.client_list[client_id].getHostname() << "\n"; + // aout(self) << "Total Batch Duration = " << total_duration << "\n"; + // aout(self) << "Total Batch Read Duration = " << total_read_duration << "\n"; + // aout(self) << "Total Batch Write Duration = " << total_write_duration << "\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 + // std::optional<int> new_batch_id = getUnsolvedBatchID(self); + // if (new_batch_id.has_value()) { + // // update the batch in the batch list with the host and actor_ref + // self->state.batch_list[new_batch_id.value()].assignedBatch(self->state.client_list[client_id].getHostname(), client); - int start_hru = self->state.batch_list[new_batch_id.value()].getStartHRU(); - int num_hru = self->state.batch_list[new_batch_id.value()].getNumHRU(); - - self->send(client, - batch_v, - client_id, - new_batch_id.value(), - start_hru, - num_hru, - self->state.config_path); - - } else { - // We found no batch this means all batches are assigned - if (self->state.batches_remaining == 0) { - aout(self) << "All Batches Solved -- Telling Clients To Exit\n"; - for (std::vector<int>::size_type i = 0; i < self->state.client_list.size(); i++) { - self->send(self->state.client_list[i].getActor(), time_to_exit_v); - } - aout(self) << "\nSUMMA_SERVER -- EXITING\n"; - self->quit(); - } else { - aout(self) << "No Batches left to compute -- letting client stay connected in case batch fails\n"; - } - } + // int start_hru = self->state.batch_list[new_batch_id.value()].getStartHRU(); + // int num_hru = self->state.batch_list[new_batch_id.value()].getNumHRU(); + + // self->send(client, + // compute_batch_v, + // client_id, + // new_batch_id.value(), + // start_hru, + // num_hru, + // self->state.config_path); + + // } else { + // // We found no batch this means all batches are assigned + // if (self->state.batches_remaining == 0) { + // aout(self) << "All Batches Solved -- Telling Clients To Exit\n"; + // for (std::vector<int>::size_type i = 0; i < self->state.client_list.size(); i++) { + // self->send(self->state.client_list[i].getActor(), time_to_exit_v); + // } + // aout(self) << "\nSUMMA_SERVER -- EXITING\n"; + // self->quit(); + // } else { + // aout(self) << "No Batches left to compute -- letting client stay connected in case batch fails\n"; + // } + // } } }; } @@ -153,11 +161,11 @@ int assembleBatches(stateful_actor<summa_server_state>* self) { std::optional<int> getUnsolvedBatchID(stateful_actor<summa_server_state>* self) { // Find the first unassigned batch - for (std::vector<int>::size_type i = 0; i < self->state.batch_list.size(); i++) { - if (self->state.batch_list[i].getBatchStatus() == unassigned) { - return i; - } - } + // for (std::vector<int>::size_type i = 0; i < self->state.batch_list.size(); i++) { + // if (self->state.batch_list[i].getBatchStatus() == unassigned) { + // return i; + // } + // } return {}; } @@ -176,6 +184,4 @@ void initializeCSVOutput(std::string csv_output_name) { csv_output.close(); } - - } // end namespace diff --git a/build/source/testing/inspector/inspector_test b/build/source/testing/inspector/inspector_test index 7d35d4e064ee958e44d2ebe3d4a3eb007c55b4f6..7fdf0bd3832dfc32072293f86b26a3336567b932 100755 Binary files a/build/source/testing/inspector/inspector_test and b/build/source/testing/inspector/inspector_test differ diff --git a/build/source/testing/inspector/main.cpp b/build/source/testing/inspector/main.cpp index c3576128d7910b823cd5243474a571a080a92137..f29a95e409c707ebd8c3cec21994abbeec6bce7a 100644 --- a/build/source/testing/inspector/main.cpp +++ b/build/source/testing/inspector/main.cpp @@ -1,65 +1,65 @@ #include "caf/all.hpp" #include "caf/io/all.hpp" +#include "main.hpp" + using namespace caf; -struct struct_1; -struct struct_2; -struct struct_3; - -// Add the custom types as messages for actors -CAF_BEGIN_TYPE_ID_BLOCK(custom_type, first_custom_type_id) - // CAF_ADD_TYPE_ID(custom_type, (struct_1)) - CAF_ADD_TYPE_ID(custom_type, (struct_2)) - CAF_ADD_TYPE_ID(custom_type, (struct_3)) -CAF_END_TYPE_ID_BLOCK(custom_type) - - -struct struct_3 { - int num_1; - int num_2; -}; - -struct struct_2 { - int num_3; - int num_4; -}; - -struct struct_1 { - struct_3 test_struct_1; - struct_2 test_struct_2; -}; - -template<class Inspector> -bool inspect(Inspector& inspector, struct_2& struct_2_inspect) { - return inspector.object(struct_2_inspect).fields( - inspector.field("num_3", struct_2_inspect.num_3), - inspector.field("num_4", struct_2_inspect.num_4)); + + + +// class Batch { +// private: +// int batch_id; +// int start_hru; + +// public: +Batch::Batch(int batch_id0, int start_hru0) { this->batch_id=batch_id0; this->start_hru=start_hru0; }//: batch_id(batch_id0), start_hru(start_hru0){} + +int Batch::getBatchID() { + return this->batch_id; +} + +int Batch::getStartHRU() { + return this->start_hru; } -template<class Inspector> -bool inspect(Inspector& inspector, struct_3& struct_3_inspect) { - return inspector.object(struct_3_inspect).fields( - inspector.field("num_1", struct_3_inspect.num_1), - inspector.field("num_2", struct_3_inspect.num_2)); +// this->batch_id = batch_id0; +// this->start_hru = start_hru0; +// } +// int getBatchID() { +// return this->batch_id; +// } + +// int getStartHRU() { +// return this->start_hru; +// } + +// template <class Inspector> +// friend bool inspect(Inspector& inspector, Batch& batch) { +// return inspector.object(batch).fields(inspector.field("a", batch.batch_id), inspector.field("b", batch.start_hru)); +// } + +// }; + +// template<class Inspector> +// bool inspect(Inspector& inpsector, Batch& batch) { +// auto getBatchID = [&batch] {return batch.getBatchID();}; +// auto getStartHRU +// } + +behavior testee(event_based_actor* self) { + return { + [=](Batch& b) { + aout(self) << b.getBatchID() << std::endl; + } + }; } -// Inspector overload is needed to compile -template <class Inspector> -bool insepct(Inspector& inspector, struct_1& struct_1_inspect, - struct_2& struct_2_inspect, struct_3& struct_3_inspect) { - return inspector.object(struct_1_inspect).fields( - inspector.object(struct_2_inspect).fields( - inspector.field("num_3", struct_2_inspect.num_3), - inspector.field("num_4", struct_2_inspect.num_4)), - inspector.object(struct_3_inspect).fields( - inspector.field("num_1", struct_3_inspect.num_1), - inspector.filed("num_2", struct_3_inspect.num_2))); -} void caf_main(actor_system& sys) { scoped_actor self{sys}; aout(self) << "Started Test Actor \n"; - + anon_send(sys.spawn(testee), Batch{2, 4}); } -CAF_MAIN(id_block::custom_type) \ No newline at end of file +CAF_MAIN(id_block::custom_types_3) \ No newline at end of file diff --git a/build/source/testing/inspector/main.hpp b/build/source/testing/inspector/main.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2a7c6646ec47516ce8c4fe3b080ff51b39b81fcb --- /dev/null +++ b/build/source/testing/inspector/main.hpp @@ -0,0 +1,48 @@ +#pragma once +#include "caf/all.hpp" +#include "caf/io/all.hpp" +class Batch; + +using namespace caf; + +enum batch_status { + unassigned, + assigned, + solved, + failed +}; + +CAF_BEGIN_TYPE_ID_BLOCK(custom_types_3, first_custom_type_id) + + CAF_ADD_ATOM(custom_types_3, hello) + + CAF_ADD_TYPE_ID(custom_types_3, (Batch)) + +CAF_END_TYPE_ID_BLOCK(custom_types_3) + + +class Batch { + private: + int batch_id; + int start_hru; + + int test; + caf::actor assigned_actor; + batch_status status; + + public: + Batch(int batch_id0 = 0, int start_hru0 = 0); + int getBatchID(); + + int getStartHRU(); + + template <class Inspector> + friend bool inspect(Inspector& inspector, Batch& batch) { + return inspector.object(batch).fields( + inspector.field("a", batch.batch_id), + inspector.field("b", batch.start_hru), + inspector.field("c", batch.test), + inspector.field("d", batch.assigned_actor)); + } + +}; diff --git a/build/source/testing/inspector/main.o b/build/source/testing/inspector/main.o index 8519db1e40675ffc742f195155694cae4a8893f9..dea34abcb1f8127a67aca276a17b1f419688cd2a 100644 Binary files a/build/source/testing/inspector/main.o and b/build/source/testing/inspector/main.o differ