diff --git a/build/includes/global/global.hpp b/build/includes/global/global.hpp index 3d2914c44c958258e69f185ba5bf395063540f1c..376ef7e0397f9b122b836ba59b106678f399cd7a 100644 --- a/build/includes/global/global.hpp +++ b/build/includes/global/global.hpp @@ -7,20 +7,14 @@ #include <bits/stdc++.h> #include <unistd.h> #include "json.hpp" - +#include "caf/all.hpp" using json = nlohmann::json; -extern bool debug; -template<typename T> -int getSettingsTest(std::vector<std::string> keys, T return_value) { - for (std::vector<int>::size_type i = 0; i < keys.size(); i++) { - std::cout<< keys[i] << std::endl; - } - return 0; -} +extern bool debug; +// get_settings /** * Return the time between to time points @@ -28,12 +22,13 @@ int getSettingsTest(std::vector<std::string> keys, T return_value) { double calculateTime(std::chrono::time_point<std::chrono::system_clock> start, std::chrono::time_point<std::chrono::system_clock> end); + + template <typename T> -std::optional<T> getSettings(std::string settings_file_path, std::string key_1, std::string key_2, +std::optional<T> getSettings(std::string json_settings_file, std::string key_1, std::string key_2, T return_value) { json settings; - std::string summa_actors_settings = "/Summa_Actors_Settings.json"; - std::ifstream settings_file(settings_file_path + summa_actors_settings); + std::ifstream settings_file(json_settings_file); settings_file >> settings; settings_file.close(); @@ -53,6 +48,8 @@ std::optional<T> getSettings(std::string settings_file_path, std::string key_1, } } catch (json::exception& e) { std::cout << e.what() << "\n"; + std::cout << key_1 << "\n"; + std::cout << key_2 << "\n"; return {}; } diff --git a/build/includes/global/message_atoms.hpp b/build/includes/global/message_atoms.hpp index 93f1b8f2e40b472a40095155c3e568ed805e3c86..99478e2e1ebfa424b97e74d38deddbb7f8fb3ba2 100644 --- a/build/includes/global/message_atoms.hpp +++ b/build/includes/global/message_atoms.hpp @@ -1,6 +1,7 @@ #pragma once #include "../summa_actor/batch_manager.hpp" +#include "settings_functions.hpp" CAF_BEGIN_TYPE_ID_BLOCK(summa, first_custom_type_id) // Summa Actor @@ -48,5 +49,11 @@ CAF_BEGIN_TYPE_ID_BLOCK(summa, first_custom_type_id) // Server Actor CAF_ADD_ATOM(summa, done_batch) CAF_ADD_ATOM(summa, time_to_exit) - + + // Struct Types + CAF_ADD_TYPE_ID(summa, (Distributed_Settings)) + CAF_ADD_TYPE_ID(summa, (Summa_Actor_Settings)) + 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)) CAF_END_TYPE_ID_BLOCK(summa) \ No newline at end of file diff --git a/build/includes/global/settings_functions.hpp b/build/includes/global/settings_functions.hpp new file mode 100644 index 0000000000000000000000000000000000000000..848abc3656402d827d61a41b7418d24a19a2761f --- /dev/null +++ b/build/includes/global/settings_functions.hpp @@ -0,0 +1,87 @@ +#pragma once + +#include "caf/all.hpp" + +struct Distributed_Settings; +struct Summa_Actor_Settings; +struct File_Access_Actor_Settings; +struct Job_Actor_Settings; +struct HRU_Actor_Settings; + + +struct Distributed_Settings { + bool distributed_mode; // flag for starting summa in distributed mode + std::string hostname; // the hostname of the server actor + int port; // the port number of the server actor + int total_hru_count; + int num_hru_per_batch; +}; + +template<class Inspector> +bool inspect(Inspector& inspector, Distributed_Settings& distributed_settings) { + return inspector.object(distributed_settings).fields( + inspector.field("distributed_mode", distributed_settings.distributed_mode), + inspector.field("hostname", distributed_settings.hostname), + inspector.field("port", distributed_settings.port), + inspector.field("total_hru_count", distributed_settings.total_hru_count), + inspector.field("num_hru_per_batch",distributed_settings.num_hru_per_batch)); +} + + +struct Summa_Actor_Settings { + int output_structure_size; + int max_gru_per_job; +}; + +template<class Inspector> +bool inspect(Inspector& inspector, Summa_Actor_Settings& summa_actor_settings) { + return inspector.object(summa_actor_settings).fields( + inspector.field("output_structure_size", summa_actor_settings.output_structure_size), + inspector.field("max_gru_per_job", summa_actor_settings.max_gru_per_job)); +} + + +struct File_Access_Actor_Settings { + int num_vectors_in_output_manager; +}; +template<class Inspector> +bool inspect(Inspector& inspector, File_Access_Actor_Settings& file_access_actor_settings) { + return inspector.object(file_access_actor_settings).fields( + inspector.field("num_vectors_in_output_manager", + file_access_actor_settings.num_vectors_in_output_manager)); +} + +struct Job_Actor_Settings { + std::string file_manager_path; + bool output_csv; + std::string csv_path; +}; + +template<class Inspector> +bool inspect(Inspector& inspector, Job_Actor_Settings& job_actor_settings) { + return inspector.object(job_actor_settings).fields( + inspector.field("file_manager_path", job_actor_settings.file_manager_path), + inspector.field("output_csv", job_actor_settings.output_csv), + inspector.field("csv_path", job_actor_settings.csv_path)); +} + + +struct HRU_Actor_Settings { + bool print_output; + int output_frequency; +}; + +template<class Inspector> +bool inspect(Inspector& inspector, HRU_Actor_Settings& hru_actor_settings) { + return inspector.object(hru_actor_settings).fields( + inspector.field("print_output", hru_actor_settings.print_output), + inspector.field("output_frequency", hru_actor_settings.output_frequency)); +} + + +int read_settings_from_json(std::string json_settings_file_path, + 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); \ No newline at end of file diff --git a/build/makefile b/build/makefile index 9b984db055949643e91dc36e78d8fe33c0932a2b..c471e04878348b07cefdb0e86c65b76c9a0588e1 100644 --- a/build/makefile +++ b/build/makefile @@ -260,6 +260,7 @@ SOURCE_DIR = /Summa-Actors/build/source/actors GLOBAL_INCLUDES = -I$(INCLUDE_DIR)/global GLOBAL = $(SOURCE_DIR)/global/global.cpp TIMEINFO = $(SOURCE_DIR)/global/timing_info.cpp +SETTINGS_FILES = $(SOURCE_DIR)/global/settings_functions.cpp SUMMA_ACTOR_INCLUDES = -I$(INCLUDE_DIR)/summa_actor SUMMA_ACTOR = $(SOURCE_DIR)/summa_actor/summa_actor.cpp @@ -335,7 +336,7 @@ clean_fortran: ################################################ COMPILE SUMMA-C++ ################################################ ################################################################################################################### compile_globals: - $(CC) $(FLAGS_ACTORS) -c $(GLOBAL) $(TIMEINFO) $(GLOBAL_INCLUDES) + $(CC) $(FLAGS_ACTORS) -c $(GLOBAL) $(TIMEINFO) $(SETTINGS_FILES) $(GLOBAL_INCLUDES) compile_gru_actor: $(CC) $(FLAGS_ACTORS) -c $(GRU_ACTOR) $(HRU_ACTOR_INCLUDES) $(GRU_ACTOR_INCLUDES) $(GLOBAL_INCLUDES) $(ACTORS_INCLUDES) diff --git a/build/source/actors/global/global.cpp b/build/source/actors/global/global.cpp index 0ef698918431e2ebc9d0b716a04030e5e5ca4b6c..c6e01f6a11a3575184033f06ee1a15f51e42f0fc 100644 --- a/build/source/actors/global/global.cpp +++ b/build/source/actors/global/global.cpp @@ -1,5 +1,6 @@ #include "global.hpp" #include <chrono> +#include "json.hpp" diff --git a/build/source/actors/global/settings_functions.cpp b/build/source/actors/global/settings_functions.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2b2c282d25230c12424a09053841e4bea67bbab6 --- /dev/null +++ b/build/source/actors/global/settings_functions.cpp @@ -0,0 +1,67 @@ +#include "settings_functions.hpp" +#include "global.hpp" + +int read_settings_from_json(std::string json_settings_file, + 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) { + + + // read distributed settings + std::string parent_key = "Distributed_Settings"; + distributed_settings.distributed_mode = getSettings(json_settings_file, parent_key, + "distributed_mode", distributed_settings.distributed_mode).value_or(false); + + distributed_settings.hostname = getSettings(json_settings_file, parent_key, + "hostname", distributed_settings.hostname).value_or(""); + + distributed_settings.port = getSettings(json_settings_file, parent_key, + "port", distributed_settings.port).value_or(-1); + + distributed_settings.total_hru_count = getSettings(json_settings_file, parent_key, + "total_hru_count", distributed_settings.total_hru_count).value_or(-1); + + distributed_settings.num_hru_per_batch = getSettings(json_settings_file, parent_key, + "num_hru_per_batch", distributed_settings.num_hru_per_batch).value_or(-1); + + + // read settings for summa actor + parent_key = "Summa_Actor"; + summa_actor_settings.output_structure_size = getSettings(json_settings_file, parent_key, + "output_structure_size", summa_actor_settings.output_structure_size).value_or(250); + + summa_actor_settings.max_gru_per_job = getSettings(json_settings_file, parent_key, + "max_gru_per_job", summa_actor_settings.max_gru_per_job).value_or(250); + + parent_key = "File_Access_Actor"; + file_access_actor_settings.num_vectors_in_output_manager = getSettings(json_settings_file, parent_key, + "num_vectors_in_output_manager", file_access_actor_settings.num_vectors_in_output_manager).value_or(1); + + + // read settings for job actor + parent_key = "Job_Actor"; + job_actor_settings.file_manager_path = getSettings(json_settings_file, parent_key, + "file_manager_path", job_actor_settings.file_manager_path).value_or(""); + + job_actor_settings.output_csv = getSettings(json_settings_file, parent_key, + "output_csv", job_actor_settings.output_csv).value_or(false); + + job_actor_settings.csv_path = getSettings(json_settings_file, parent_key, + "csv_path", job_actor_settings.csv_path).value_or(""); + + + // read settings for hru_actor + parent_key = "HRU_Actor"; + hru_actor_settings.print_output = getSettings(json_settings_file, parent_key, + "print_output", hru_actor_settings.print_output).value_or(true); + + hru_actor_settings.output_frequency = getSettings(json_settings_file, parent_key, + "output_frequency", hru_actor_settings.output_frequency).value_or(250); + + + + + return 0; +} \ No newline at end of file diff --git a/build/source/actors/main.cpp b/build/source/actors/main.cpp index ab6583ad3e9c2a70d28aad0db507c7b643b1b177..c00ecac88aebc441db2cb35b3e3836a9061c8245 100644 --- a/build/source/actors/main.cpp +++ b/build/source/actors/main.cpp @@ -4,6 +4,7 @@ #include "summa_client.hpp" #include "summa_server.hpp" #include "global.hpp" +#include "settings_functions.hpp" #include "message_atoms.hpp" #include <string> #include <bits/stdc++.h> @@ -22,7 +23,7 @@ class config : public actor_system_config { public: int startGRU = -1; int countGRU = -1; - std::string config_path = ""; + std::string config_file = ""; bool debugMode = false; bool server_mode = false; @@ -30,7 +31,7 @@ class config : public actor_system_config { opt_group{custom_options_, "global"} .add(startGRU, "gru,g", "Starting GRU Index") .add(countGRU, "numGRU,n", "Total Number of GRUs") - .add(config_path, "config,c", "Path name of the config directory") + .add(config_file, "config,c", "Path name of the config directory") .add(debugMode, "debug-mode,b", "enable debug mode") .add(server_mode, "server-mode,s", "enable server mode"); } @@ -42,14 +43,14 @@ void run_client(actor_system& system, const config& cfg) { uint16_t port; aout(self) << "Starting SUMMA-Client in Distributed Mode\n"; - host = getSettings(cfg.config_path, "DistributedSettings", "host", host).value_or(""); - port = getSettings(cfg.config_path, "DistributedSettings", "port", port).value_or(-1); + host = getSettings(cfg.config_file, "DistributedSettings", "host", host).value_or(""); + port = getSettings(cfg.config_file, "DistributedSettings", "port", port).value_or(-1); if (host == "" || port == -1) { aout(self) << "ERROR: run_client() host and port - CHECK SETTINGS FILE\n"; return; } - std::optional<std::string> path = cfg.config_path; + std::optional<std::string> path = cfg.config_file; auto c = system.spawn(summa_client, path); if (!host.empty() && port > 0) { anon_send(c, connect_atom_v, host, port); @@ -63,12 +64,12 @@ void run_server(actor_system& system, const config& cfg) { scoped_actor self{system}; uint16_t port; - port = getSettings(cfg.config_path, "DistributedSettings", "port", port).value_or(-1); + port = getSettings(cfg.config_file, "DistributedSettings", "port", port).value_or(-1); if (port == -1) { aout(self) << "ERROR: run_server() port - CHECK SETTINGS FILE\n"; return; } - auto server = system.spawn(summa_server, cfg.config_path); + auto server = system.spawn(summa_server, cfg.config_file); aout(self) << "Attempting to publish summa_server_actor on port " << port << std::endl; auto is_port = io::publish(server, port); if (!is_port) { @@ -83,39 +84,54 @@ void run_server(actor_system& system, const config& cfg) { void caf_main(actor_system& sys, const config& cfg) { scoped_actor self{sys}; - std::string key_1 = "DistributedSettings"; - std::string key_2 = "distributed-mode"; - bool distributed_mode = false; + int err; + 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; + err = read_settings_from_json(cfg.config_file, + distributed_settings, + summa_actor_settings, + file_access_actor_settings, + job_actor_settings, + hru_actor_settings); - distributed_mode = getSettings(cfg.config_path, key_1, key_2, distributed_mode).value_or(false); - if (distributed_mode) { - // only command line arguments needed are config_path and server-mode - auto system = cfg.server_mode ? run_server : run_client; - system(sys, cfg); - } else { - // Configure command line arguments - if (cfg.startGRU == -1) { - aout(self) << "Starting GRU was not defined!! " << - "startGRU is set with the \"-g\" option\n"; - aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n"; - return; - } - if (cfg.countGRU == -1) { - aout(self) << "Number of GRUs was not defined!! " << - "countGRU is set with the \"-n\" option\n"; - aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n"; - return; - } - if (cfg.config_path == "") { - aout(self) << "File Manager was not defined!! " << - "fileManger is set with the \"-c\" option\n"; - aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n"; - return; - } - - auto summa = sys.spawn(summa_actor, cfg.startGRU, cfg.countGRU, cfg.config_path, self); - } + + // std::string key_1 = "DistributedSettings"; + // std::string key_2 = "distributed-mode"; + // bool distributed_mode = false; + + // distributed_mode = getSettings(cfg.config_file, key_1, key_2, distributed_mode).value_or(false); + // if (distributed_mode) { + // // only command line arguments needed are config_file and server-mode + // auto system = cfg.server_mode ? run_server : run_client; + // system(sys, cfg); + + // } else { + // // Configure command line arguments + // if (cfg.startGRU == -1) { + // aout(self) << "Starting GRU was not defined!! " << + // "startGRU is set with the \"-g\" option\n"; + // aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n"; + // return; + // } + // if (cfg.countGRU == -1) { + // aout(self) << "Number of GRUs was not defined!! " << + // "countGRU is set with the \"-n\" option\n"; + // aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n"; + // return; + // } + // if (cfg.config_file == "") { + // aout(self) << "File Manager was not defined!! " << + // "fileManger is set with the \"-c\" option\n"; + // aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n"; + // return; + // } + + // auto summa = sys.spawn(summa_actor, cfg.startGRU, cfg.countGRU, cfg.config_file, self); + // } } diff --git a/build/source/actors/summa_actor/summa_server.cpp b/build/source/actors/summa_actor/summa_server.cpp index 51c6d1c1e4cc41a84d0c6587fd1f73da55194c50..d6f8039e9876a656059602dcfc06669e531a2cf8 100644 --- a/build/source/actors/summa_actor/summa_server.cpp +++ b/build/source/actors/summa_actor/summa_server.cpp @@ -13,9 +13,6 @@ 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; - // std::string returnType; - // getSettingsTest(std::vector<std::string> {"test", "test2"} ,returnType); - // --------------------------Initalize Settings -------------------------- self->state.total_hru_count = getSettings(self->state.config_path, "SimulationSettings", "total_hru_count", self->state.total_hru_count).value_or(-1); @@ -45,7 +42,6 @@ behavior summa_server(stateful_actor<summa_server_state>* self, std::string conf csv_output.close(); // -------------------------- Initalize CSV ------------------------------ - // -------------------------- Assemble Batches --------------------------- aout(self) << "Assembling HRUs into Batches\n"; if (assembleBatches(self) == -1) { aout(self) << "ERROR: assembleBatches\n"; @@ -56,7 +52,6 @@ behavior summa_server(stateful_actor<summa_server_state>* self, std::string conf self->state.batch_list[i].printBatchInfo(); } } - // -------------------------- Assemble Batches --------------------------- return { [=](connect_to_server, actor client, std::string hostname) { diff --git a/build/source/testing/inspector/inspector_test b/build/source/testing/inspector/inspector_test new file mode 100755 index 0000000000000000000000000000000000000000..7d35d4e064ee958e44d2ebe3d4a3eb007c55b4f6 Binary files /dev/null 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 new file mode 100644 index 0000000000000000000000000000000000000000..c3576128d7910b823cd5243474a571a080a92137 --- /dev/null +++ b/build/source/testing/inspector/main.cpp @@ -0,0 +1,65 @@ +#include "caf/all.hpp" +#include "caf/io/all.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)); +} +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)); +} + +// 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"; + +} + +CAF_MAIN(id_block::custom_type) \ No newline at end of file diff --git a/build/source/testing/inspector/main.o b/build/source/testing/inspector/main.o new file mode 100644 index 0000000000000000000000000000000000000000..8519db1e40675ffc742f195155694cae4a8893f9 Binary files /dev/null and b/build/source/testing/inspector/main.o differ diff --git a/build/source/testing/inspector/makefile b/build/source/testing/inspector/makefile new file mode 100644 index 0000000000000000000000000000000000000000..7debce63ccaa10c4097cd3d2bb7f0e6338866935 --- /dev/null +++ b/build/source/testing/inspector/makefile @@ -0,0 +1,20 @@ + + +CC = g++ + +INCLUDES = -I/usr/include -I/usr/local/include +ACTORS_LIBRARIES = -L/usr/lib -L/usr/local/lib -L/Summa-Actors/bin -lcaf_core -lcaf_io +FLAGS = -g -O0 -Wall -std=c++17 + + +all: compile link + +compile: + $(CC) $(FLAGS) -c main.cpp $(INCLUDES) + +link: + $(CC) $(FLAGS) -o inspector_test *.o $(ACTORS_LIBRARIES) + +clean: + rm *.o + rm inspector_test