From 4e4ee823e63a90fd91cbec6f2312c896ca4cabe0 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 6 Sep 2016 19:02:55 +0200 Subject: [PATCH] objectify jedule still some cleanings to do but this commit might not go red --- examples/simdag/CMakeLists.txt | 3 +- examples/simdag/scheduling/sd_scheduling.tesh | 4 +- include/simgrid/jedule/jedule_events.h | 40 --- include/simgrid/jedule/jedule_events.hpp | 54 ++++ .../{jedule_output.h => jedule_output.hpp} | 8 +- ...{jedule_platform.h => jedule_platform.hpp} | 57 ++-- src/instr/jedule/jedule_events.cpp | 94 +++--- src/instr/jedule/jedule_output.cpp | 200 ++----------- src/instr/jedule/jedule_platform.cpp | 280 ++++++++++++------ src/instr/jedule/jedule_sd_binding.cpp | 82 ++--- tools/cmake/DefinePackages.cmake | 6 +- 11 files changed, 384 insertions(+), 444 deletions(-) delete mode 100644 include/simgrid/jedule/jedule_events.h create mode 100644 include/simgrid/jedule/jedule_events.hpp rename include/simgrid/jedule/{jedule_output.h => jedule_output.hpp} (83%) rename include/simgrid/jedule/{jedule_platform.h => jedule_platform.hpp} (61%) diff --git a/examples/simdag/CMakeLists.txt b/examples/simdag/CMakeLists.txt index a8f627919f..26a8a1b5ed 100644 --- a/examples/simdag/CMakeLists.txt +++ b/examples/simdag/CMakeLists.txt @@ -37,7 +37,8 @@ set(txt_files ${txt_files} ${CMAKE_CURRENT_SOURCE_DIR}/dag-dotload/dag_wi ${CMAKE_CURRENT_SOURCE_DIR}/dag-dotload/dag.dot ${CMAKE_CURRENT_SOURCE_DIR}/ptg-dotload/ptg.dot ${CMAKE_CURRENT_SOURCE_DIR}/schedule-dotload/dag_with_bad_schedule.dot - ${CMAKE_CURRENT_SOURCE_DIR}/schedule-dotload/dag_with_good_schedule.dot PARENT_SCOPE) + ${CMAKE_CURRENT_SOURCE_DIR}/schedule-dotload/dag_with_good_schedule.dot + ${CMAKE_CURRENT_SOURCE_DIR}/scheduling/expected_output.jed PARENT_SCOPE) foreach(x availability daxload fail typed_tasks properties throttling scheduling test) ADD_TESH(simdag-${x} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/simdag --cd ${CMAKE_BINARY_DIR}/examples/simdag ${CMAKE_HOME_DIRECTORY}/examples/simdag/${x}/sd_${x}.tesh) diff --git a/examples/simdag/scheduling/sd_scheduling.tesh b/examples/simdag/scheduling/sd_scheduling.tesh index db4902ffce..7a06826f39 100644 --- a/examples/simdag/scheduling/sd_scheduling.tesh +++ b/examples/simdag/scheduling/sd_scheduling.tesh @@ -34,6 +34,6 @@ $ $SG_TEST_EXENV ${bindir:=.}/scheduling/sd_scheduling --log=sd_daxparse.thresh: > [98.184618] [test/INFO] ------------------- Produce the trace file--------------------------- > [98.184618] [test/INFO] Producing a jedule output (if active) of the run into minmin_test.jed -$ diff ./scheduling/sd_scheduling.jed ./scheduling/expected_output.jed +$ diff ${srcdir:=.}/scheduling/sd_scheduling.jed ${srcdir:=.}/scheduling/expected_output.jed -$ cmake -E remove -f ${srcdir:=.}/sd_scheduling.jed \ No newline at end of file +$ cmake -E remove -f ${srcdir:=.}/scheduling/sd_scheduling.jed \ No newline at end of file diff --git a/include/simgrid/jedule/jedule_events.h b/include/simgrid/jedule/jedule_events.h deleted file mode 100644 index d2a5bdf0f7..0000000000 --- a/include/simgrid/jedule/jedule_events.h +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (c) 2010-2012, 2014-2015. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#ifndef JEDULE_EVENTS_H_ -#define JEDULE_EVENTS_H_ - -#include "simgrid_config.h" -#include "xbt/dynar.h" -#include "xbt/dict.h" -#include "simgrid/jedule/jedule_platform.h" - -#if HAVE_JEDULE -SG_BEGIN_DECL() - -struct jed_event { - int event_id; - char *name; - double start_time; - double end_time; - char *type; - xbt_dynar_t resource_subsets; - xbt_dynar_t characteristics_list; /* just a list of names (strings) */ - xbt_dict_t info_hash; /* key/value pairs */ -}; - -typedef struct jed_event s_jed_event_t, *jed_event_t; - -void create_jed_event(jed_event_t *event, char *name, double start_time, double end_time, const char *type); -void jed_event_free(jed_event_t event); -void jed_event_add_resources(jed_event_t event, xbt_dynar_t host_selection); -void jed_event_add_characteristic(jed_event_t event, char *characteristic); -void jed_event_add_info(jed_event_t event, char *key, char *value); - -SG_END_DECL() -#endif - -#endif /* JEDULE_EVENTS_H_ */ diff --git a/include/simgrid/jedule/jedule_events.hpp b/include/simgrid/jedule/jedule_events.hpp new file mode 100644 index 0000000000..1ccee5c803 --- /dev/null +++ b/include/simgrid/jedule/jedule_events.hpp @@ -0,0 +1,54 @@ +/* Copyright (c) 2010-2012, 2014-2015. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef JEDULE_EVENTS_H_ +#define JEDULE_EVENTS_H_ + +#include "simgrid_config.h" +#include "simgrid/forward.h" +#include +#include +#include + +#include "jedule_platform.hpp" + +#if HAVE_JEDULE +namespace simgrid { +namespace jedule{ + +XBT_PUBLIC_CLASS Event{ + private: + ~Event()=default; + public: + Event(std::string name, double start_time, double end_time, std::string type) + : name(name), start_time(start_time), end_time(end_time), type(type){} + void deleteEvent(); + void addCharacteristic(char *characteristic); + void addResources(std::vector *host_selection); + void addInfo(char *key, char *value); + void print(FILE *file); + + private: + std::string name; + double start_time; + double end_time; + std::string type; + std::vector resource_subsets; + std::vector characteristics_list; /* just a list of names (strings) */ + std::unordered_map info_map; /* key/value pairs */ +}; +} +} + +SG_BEGIN_DECL() + +typedef simgrid::jedule::Event * jed_event_t; + +SG_END_DECL() + +#endif + +#endif /* JEDULE_EVENTS_H_ */ diff --git a/include/simgrid/jedule/jedule_output.h b/include/simgrid/jedule/jedule_output.hpp similarity index 83% rename from include/simgrid/jedule/jedule_output.h rename to include/simgrid/jedule/jedule_output.hpp index 6b50c7672e..3492b91dcb 100644 --- a/include/simgrid/jedule/jedule_output.h +++ b/include/simgrid/jedule/jedule_output.hpp @@ -9,17 +9,19 @@ #include #include "simgrid_config.h" -#include "jedule_events.h" -#include "jedule_platform.h" + +#include "jedule_events.hpp" +#include "jedule_platform.hpp" #if HAVE_JEDULE SG_BEGIN_DECL() - extern xbt_dynar_t jedule_event_list; + void jedule_init_output(void); void jedule_cleanup_output(void); void jedule_store_event(jed_event_t event); void write_jedule_output(FILE *file, jedule_t jedule, xbt_dynar_t event_list, xbt_dict_t meta_info_dict); +void print_key_value_dict(FILE *file, std::unordered_map key_value_dict); SG_END_DECL() #endif diff --git a/include/simgrid/jedule/jedule_platform.h b/include/simgrid/jedule/jedule_platform.hpp similarity index 61% rename from include/simgrid/jedule/jedule_platform.h rename to include/simgrid/jedule/jedule_platform.hpp index 38df596628..618f9e0c39 100644 --- a/include/simgrid/jedule/jedule_platform.h +++ b/include/simgrid/jedule/jedule_platform.hpp @@ -8,47 +8,63 @@ #define JED_SIMGRID_PLATFORM_H_ #include "simgrid_config.h" +#include "simgrid/forward.h" #include "xbt/dynar.h" #include "xbt/dict.h" +#include +#include +#include #if HAVE_JEDULE -SG_BEGIN_DECL() - -typedef struct jed_simgrid_container s_jed_simgrid_container_t, *jed_simgrid_container_t; - -struct jed_simgrid_container { - char *name; - xbt_dynar_t container_children; - jed_simgrid_container_t parent; - xbt_dynar_t resource_list; - xbt_dict_t name2id; +namespace simgrid { +namespace jedule{ +XBT_PUBLIC_CLASS Container { +public: + Container(std::string name); + ~Container()=default; +private: int last_id; int is_lowest; +public: + std::string name; + std::unordered_map name2id; + Container *parent; + std::vector children; + std::vector resource_list; + void addChild(Container* child); + void addResources(std::vector hosts); + void createHierarchy(AS_t from_as); + std::vector getHierarchy(); + std::string getHierarchyAsString(); + void print(FILE *file); + void printResources(FILE *file); }; +} +} +SG_BEGIN_DECL() +typedef simgrid::jedule::Container * jed_container_t; + /** selection of a subset of resources from the original set */ struct jed_res_subset { - jed_simgrid_container_t parent; + jed_container_t parent; int start_idx; // start idx in resource_list of container int nres; // number of resources spanning starting at start_idx }; typedef struct jed_res_subset s_jed_res_subset_t, *jed_res_subset_t; -struct jedule_struct { - jed_simgrid_container_t root_container; - xbt_dict_t jedule_meta_info; -}; +typedef struct jedule_struct { + jed_container_t root_container; + std::unordered_map jedule_meta_info; +} s_jedule_t; -typedef struct jedule_struct s_jedule_t, *jedule_t; +typedef s_jedule_t *jedule_t; void jed_create_jedule(jedule_t *jedule); void jed_free_jedule(jedule_t jedule); void jedule_add_meta_info(jedule_t jedule, char *key, char *value); -void jed_simgrid_create_container(jed_simgrid_container_t *container, const char *name); -void jed_simgrid_add_container(jed_simgrid_container_t parent, jed_simgrid_container_t child); -void jed_simgrid_add_resources(jed_simgrid_container_t parent, xbt_dynar_t host_names); /** * it is assumed that the host_names in the entire system are unique that means that we don't need parent references @@ -56,7 +72,7 @@ void jed_simgrid_add_resources(jed_simgrid_container_t parent, xbt_dynar_t host_ * subset_list must be allocated * host_names is the list of host_names associated with an event */ -void jed_simgrid_get_resource_selection_by_hosts(xbt_dynar_t subset_list, xbt_dynar_t host_names); +void jed_simgrid_get_resource_selection_by_hosts(xbt_dynar_t subset_list, std::vector* host_list); /* global: @@ -72,5 +88,4 @@ SG_END_DECL() #endif - #endif /* JED_SIMGRID_PLATFORM_H_ */ diff --git a/src/instr/jedule/jedule_events.cpp b/src/instr/jedule/jedule_events.cpp index 2c63914e95..8efdbd3e67 100644 --- a/src/instr/jedule/jedule_events.cpp +++ b/src/instr/jedule/jedule_events.cpp @@ -4,20 +4,27 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include "simgrid/jedule/jedule_events.hpp" +#include "simgrid/jedule/jedule_output.hpp" #include #include -#include +#include -#include "xbt/dict.h" -#include "xbt/dynar.h" #include "xbt/asserts.h" -#include "simgrid/jedule/jedule_events.h" -#include "simgrid/jedule/jedule_platform.h" - #if HAVE_JEDULE +namespace simgrid{ +namespace jedule{ + +void Event::deleteEvent(){ + while (!this->resource_subsets.empty()){ + xbt_free(this->resource_subsets.back()); + this->resource_subsets.pop_back(); + } + delete this; +} -void jed_event_add_resources(jed_event_t event, xbt_dynar_t host_selection) { +void Event::addResources(std::vector *host_selection) { xbt_dynar_t resource_subset_list; jed_res_subset_t res_set; unsigned int i; @@ -26,52 +33,59 @@ void jed_event_add_resources(jed_event_t event, xbt_dynar_t host_selection) { jed_simgrid_get_resource_selection_by_hosts(resource_subset_list, host_selection); xbt_dynar_foreach(resource_subset_list, i, res_set) { - xbt_dynar_push(event->resource_subsets, &res_set); + this->resource_subsets.push_back(res_set); } - xbt_dynar_free(&resource_subset_list); + xbt_dynar_free_container(&resource_subset_list); } -void jed_event_add_characteristic(jed_event_t event, char *characteristic) { +void Event::addCharacteristic(char *characteristic) { xbt_assert( characteristic != nullptr ); - xbt_dynar_push(event->characteristics_list, &characteristic); + this->characteristics_list.push_back(characteristic); } -void jed_event_add_info(jed_event_t event, char *key, char *value) { - char *val_cp; - - xbt_assert(key != nullptr); - xbt_assert(value != nullptr); - - val_cp = strdup(value); - xbt_dict_set(event->info_hash, key, val_cp, nullptr); +void Event::addInfo(char* key, char *value) { + xbt_assert((key != nullptr) && value != nullptr); + this->info_map.insert({key, value}); } -void create_jed_event(jed_event_t *event, char *name, double start_time, - double end_time, const char *type) { - - *event = xbt_new0(s_jed_event_t,1); - (*event)->name = xbt_strdup(name); +void Event::print(FILE *jed_file){ + fprintf(jed_file, " \n"); + fprintf(jed_file, " \n", this->name.c_str()); + fprintf(jed_file, " \n", this->start_time); + fprintf(jed_file, " \n", this->end_time); + fprintf(jed_file, " \n", this->type.c_str()); + fprintf(jed_file, " \n"); + + xbt_assert(!this->resource_subsets.empty()); + for (auto subset: this->resource_subsets) { + int start = subset->start_idx; + int end = subset->start_idx + subset->nres - 1; + + std::string resid = subset->parent->getHierarchyAsString(); + fprintf(jed_file, " \n"); - } - - fprintf(jed_file, " \n"); - if (!xbt_dynar_is_empty(event->characteristics_list)){ - fprintf(jed_file, " \n"); - char *ch; - unsigned int iter; - xbt_dynar_foreach(event->characteristics_list, iter, ch) { - fprintf(jed_file, " \n", ch); - } - fprintf(jed_file, " \n"); - } - - if (!xbt_dict_is_empty(event->info_hash)){ - fprintf(jed_file, " \n"); - print_key_value_dict(event->info_hash); - fprintf(jed_file, " \n"); - } - - fprintf(jed_file, " \n"); -} - -static void print_events(xbt_dynar_t event_list) { +static void print_events(FILE *jed_file, xbt_dynar_t event_list) { unsigned int i; jed_event_t event; fprintf(jed_file, " \n"); xbt_dynar_foreach(event_list, i, event) { - print_event(event); + event->print(jed_file); } fprintf(jed_file, " \n"); } void write_jedule_output(FILE *file, jedule_t jedule, xbt_dynar_t event_list, xbt_dict_t meta_info_dict) { - - jed_file = file; if (!xbt_dynar_is_empty(jedule_event_list)){ - fprintf(jed_file, "\n"); + fprintf(file, "\n"); - if (!xbt_dict_is_empty(jedule->jedule_meta_info)){ - fprintf(jed_file, " \n"); - print_key_value_dict(jedule->jedule_meta_info); - fprintf(jed_file, " \n"); + if (!jedule->jedule_meta_info.empty()){ + fprintf(file, " \n"); + print_key_value_dict(file, jedule->jedule_meta_info); + fprintf(file, " \n"); } - print_platform(jedule->root_container); + print_platform(file, jedule->root_container); - print_events(event_list); + print_events(file, event_list); - fprintf(jed_file, "\n"); + fprintf(file, "\n"); } } -static void jed_event_free_ref(void *evp) -{ - jed_event_t ev = *(jed_event_t *)evp; - jed_event_free(ev); -} - void jedule_init_output() { - jedule_event_list = xbt_dynar_new(sizeof(jed_event_t), jed_event_free_ref); + jedule_event_list = xbt_dynar_new(sizeof(jed_event_t), nullptr); } void jedule_cleanup_output() { - xbt_dynar_free(&jedule_event_list); + while (!xbt_dynar_is_empty(jedule_event_list)) { + jed_event_t evt = xbt_dynar_pop_as(jedule_event_list, jed_event_t) ; + evt->deleteEvent(); + } + + xbt_dynar_free_container(&jedule_event_list); } void jedule_store_event(jed_event_t event) { diff --git a/src/instr/jedule/jedule_platform.cpp b/src/instr/jedule/jedule_platform.cpp index dfa912973a..7c33b3e529 100644 --- a/src/instr/jedule/jedule_platform.cpp +++ b/src/instr/jedule/jedule_platform.cpp @@ -4,84 +4,189 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "simgrid/jedule/jedule_platform.h" +#include "simgrid/jedule/jedule_platform.hpp" +#include "simgrid/jedule/jedule_output.hpp" +#include "simgrid/s4u/As.hpp" +#include "simgrid/host.h" #include "xbt/asserts.h" #include "xbt/dynar.h" #include "xbt/str.h" +#include #include -#include +#include #if HAVE_JEDULE static xbt_dict_t host2_simgrid_parent_container; static xbt_dict_t container_name2container; -static int compare_ids(const void *num1, const void *num2) { - return *((int*) num1) - *((int*) num2); +namespace simgrid { +namespace jedule { + +Container::Container(std::string name) +: name(name) { + + this->is_lowest = 0; + this->parent = nullptr; + + xbt_dict_set(container_name2container, this->name.c_str(), this, nullptr); +} + +void Container::addChild(jed_container_t child){ + xbt_assert(this != nullptr); + xbt_assert(child != nullptr); + this->children.push_back(child); + child->parent = this; } -static void jed_free_container(jed_simgrid_container_t container) { - xbt_dict_free(&container->name2id); - xbt_dynar_free(&container->resource_list); +void Container::addResources(std::vector hosts){ + this->is_lowest = 1; + this->children.clear(); + this->last_id = 0; + + //FIXME do we need to sort?: xbt_dynar_sort_strings(host_names); + + for (auto host : hosts) { + const char *host_name = sg_host_get_name(host); + this->name2id.insert({host_name, this->last_id}); + (this->last_id)++; + xbt_dict_set(host2_simgrid_parent_container, host_name, this, nullptr); + this->resource_list.push_back(host); + } +} + +void Container::createHierarchy(AS_t from_as){ + xbt_dict_cursor_t cursor = nullptr; + char *key; + AS_t elem; + xbt_dict_t routing_sons = from_as->children(); + + if (xbt_dict_is_empty(routing_sons)) { + // I am no AS + // add hosts to jedule platform + xbt_dynar_t table = from_as->hosts(); + unsigned int dynar_cursor; + sg_host_t host; + + std::vector hosts; - if( container->container_children != nullptr ) { - unsigned int iter; - jed_simgrid_container_t child_container; - xbt_dynar_foreach(container->container_children, iter, child_container) { - jed_free_container(child_container); + xbt_dynar_foreach(table, dynar_cursor, host) { + hosts.push_back(host); + } + this->addResources(hosts); + xbt_dynar_free(&table); + } else { + xbt_dict_foreach(routing_sons, cursor, key, elem) { + jed_container_t child_container = new simgrid::jedule::Container(std::string(elem->name())); + this->addChild(child_container); + child_container->createHierarchy(elem); } - xbt_dynar_free(&container->container_children); } - xbt_free(container->name); - xbt_free(container); } -void jed_simgrid_create_container(jed_simgrid_container_t *container, const char *name) -{ - xbt_assert( name != nullptr ); +std::vector Container::getHierarchy() { + xbt_assert( this!= nullptr ); + + if(this->parent != nullptr ) { - *container = xbt_new0(s_jed_simgrid_container_t,1); - (*container)->name = xbt_strdup(name); - (*container)->is_lowest = 0; - (*container)->container_children = xbt_dynar_new(sizeof(jed_simgrid_container_t), nullptr); - (*container)->parent = nullptr; + if(!this->parent->children.empty()) { + // we are in the last level + return this->parent->getHierarchy(); + } else { + unsigned int i =0; + int child_nb = -1; + + for (auto child : this->parent->children) { + if( child == this) { + child_nb = i; + break; + } + i++; + } - xbt_dict_set(container_name2container, (*container)->name, *container, nullptr); + xbt_assert( child_nb > - 1); + std::vector heir_list = this->parent->getHierarchy(); + heir_list.insert(heir_list.begin(), child_nb); + return heir_list; + } + } else { + int top_level = 0; + std::vector heir_list = {top_level}; + return heir_list; + } } -void jed_simgrid_add_container(jed_simgrid_container_t parent, jed_simgrid_container_t child) { - xbt_assert(parent != nullptr); - xbt_assert(child != nullptr); - xbt_dynar_push(parent->container_children, &child); - child->parent = parent; +std::string Container::getHierarchyAsString(){ + std::string output(""); + + std::vector heir_list = this->getHierarchy(); + + unsigned int length = heir_list.size(); + unsigned int i = 0; + for (auto id : heir_list) { + output += std::to_string(id); + if( i != length-1 ) { + output += "."; + } + } + + return output; } -void jed_simgrid_add_resources(jed_simgrid_container_t parent, xbt_dynar_t host_names) { - unsigned int iter; - char *host_name; - char *buf; - - parent->is_lowest = 1; - xbt_dynar_free(&parent->container_children); - parent->container_children = nullptr; - parent->name2id = xbt_dict_new_homogeneous(xbt_free_f); - parent->last_id = 0; - parent->resource_list = xbt_dynar_new(sizeof(char *), nullptr); - - xbt_dynar_sort_strings(host_names); - - xbt_dynar_foreach(host_names, iter, host_name) { - buf = bprintf("%d", parent->last_id); - (parent->last_id)++; - xbt_dict_set(parent->name2id, host_name, buf, nullptr); - xbt_dict_set(host2_simgrid_parent_container, host_name, parent, nullptr); - xbt_dynar_push(parent->resource_list, &host_name); +void Container::printResources(FILE * jed_file){ + unsigned int res_nb; + unsigned int i=0; + xbt_assert(!this->resource_list.empty()); + + res_nb = this->resource_list.size(); + + std::string resid = this->getHierarchyAsString(); + + fprintf(jed_file, " resource_list) { + const char * res_name = sg_host_get_name(res); + fprintf(jed_file, "%s", res_name); + if( i != res_nb-1 ) { + fprintf(jed_file, "|"); + } + i++; + } + fprintf(jed_file, "\" />\n"); +} + +void Container::print(FILE* jed_file) { + xbt_assert( this != nullptr ); + fprintf(jed_file, " \n", this->name.c_str()); + if( !this->children.empty()){ + for (auto child: this->children) { + child->print(jed_file); + } + } else { + this->printResources(jed_file); } + fprintf(jed_file, " \n"); } -static void add_subset_to(xbt_dynar_t subset_list, int start, int end, jed_simgrid_container_t parent) { + +} +} + +static int compare_ids(const void *num1, const void *num2) { + return *((int*) num1) - *((int*) num2); +} + +static void jed_free_container(jed_container_t container) { + if(!container->children.empty()) { + for (auto child: container->children){ + jed_free_container(child); + } + } + delete container; +} + +static void add_subset_to(xbt_dynar_t subset_list, int start, int end, jed_container_t parent) { jed_res_subset_t subset; xbt_assert( subset_list != nullptr ); @@ -95,13 +200,13 @@ static void add_subset_to(xbt_dynar_t subset_list, int start, int end, jed_simgr xbt_dynar_push(subset_list, &subset); } -static void add_subsets_to(xbt_dynar_t subset_list, xbt_dynar_t hostgroup, jed_simgrid_container_t parent) { +static void add_subsets_to(xbt_dynar_t subset_list, xbt_dynar_t hostgroup, jed_container_t parent) { unsigned int iter; char *host_name; xbt_dynar_t id_list; int *id_ar; int nb_ids; - char *id_str; + int id; // get ids for each host // sort ids @@ -113,23 +218,19 @@ static void add_subsets_to(xbt_dynar_t subset_list, xbt_dynar_t hostgroup, jed_s xbt_assert( hostgroup != nullptr ); xbt_assert( parent != nullptr ); - id_list = xbt_dynar_new(sizeof(char *), nullptr); + id_list = xbt_dynar_new(sizeof(int), nullptr); xbt_dynar_foreach(hostgroup, iter, host_name) { - jed_simgrid_container_t parent; + jed_container_t parent; xbt_assert( host_name != nullptr ); - parent = (jed_simgrid_container_t)xbt_dict_get(host2_simgrid_parent_container, host_name); - id_str = (char*)xbt_dict_get(parent->name2id, host_name); - xbt_dynar_push(id_list, &id_str); + parent = (jed_container_t)xbt_dict_get(host2_simgrid_parent_container, host_name); + id = parent->name2id.at(host_name); + xbt_dynar_push(id_list, &id); } - nb_ids = xbt_dynar_length(id_list); - id_ar = xbt_new0(int,nb_ids); - xbt_dynar_foreach(id_list, iter, id_str) { - id_ar[iter] = xbt_str_parse_int(id_str, "Parse error: not a number: %s"); - } + xbt_dynar_sort(id_list, &compare_ids); - qsort (id_ar, nb_ids, sizeof(int), &compare_ids); + id_ar = static_cast(xbt_dynar_to_array(id_list)); if( nb_ids > 0 ) { int start = 0; @@ -155,71 +256,58 @@ static void add_subsets_to(xbt_dynar_t subset_list, xbt_dynar_t hostgroup, jed_s } } - free(id_ar); - xbt_dynar_free(&id_list); + xbt_free(id_ar); } -void jed_simgrid_get_resource_selection_by_hosts(xbt_dynar_t subset_list, xbt_dynar_t host_names) { - char *host_name; - unsigned int iter; - xbt_dict_t parent2hostgroup; // group hosts by parent +void jed_simgrid_get_resource_selection_by_hosts(xbt_dynar_t subset_list, std::vector *host_list) { + std::unordered_map parent2hostgroup; // group hosts by parent - parent2hostgroup = xbt_dict_new_homogeneous(nullptr); - - xbt_assert( host_names != nullptr ); + xbt_assert( host_list != nullptr ); // for each host name // find parent container // group by parent container - xbt_dynar_foreach(host_names, iter, host_name) { - jed_simgrid_container_t parent = (jed_simgrid_container_t)xbt_dict_get(host2_simgrid_parent_container, host_name); + for (auto host: *host_list) { + const char *host_name = sg_host_get_name(host); + jed_container_t parent = (jed_container_t)xbt_dict_get(host2_simgrid_parent_container, host_name); xbt_assert( parent != nullptr ); - xbt_dynar_t hostgroup = (xbt_dynar_t)xbt_dict_get_or_null (parent2hostgroup, parent->name); - if( hostgroup == nullptr ) { - hostgroup = xbt_dynar_new(sizeof(char*), nullptr); - xbt_dict_set(parent2hostgroup, parent->name, hostgroup, nullptr); + auto host_group = parent2hostgroup.find(parent->name.c_str()); + if (host_group == parent2hostgroup.end()){ + xbt_dynar_t group = xbt_dynar_new(sizeof(char*), nullptr); + xbt_dynar_push(group, &host_name); + parent2hostgroup.insert({parent->name.c_str(), group}); + } else { + xbt_dynar_push(host_group->second, &host_name); } - - xbt_dynar_push(hostgroup, &host_name); } - xbt_dict_cursor_t cursor=nullptr; - char *parent_name; - xbt_dynar_t hostgroup; - jed_simgrid_container_t parent; - - xbt_dict_foreach(parent2hostgroup,cursor,parent_name,hostgroup) { - parent = (jed_simgrid_container_t)xbt_dict_get(container_name2container, parent_name); - add_subsets_to(subset_list, hostgroup, parent); + for (auto elm: parent2hostgroup) { + jed_container_t parent = (jed_container_t)xbt_dict_get(container_name2container, elm.first); + add_subsets_to(subset_list, elm.second, parent); + xbt_dynar_free_container(&elm.second); } - xbt_dynar_free(&hostgroup); - xbt_dict_free(&parent2hostgroup); + } void jedule_add_meta_info(jedule_t jedule, char *key, char *value) { - char *val_cp; - xbt_assert(key != nullptr); xbt_assert(value != nullptr); - val_cp = xbt_strdup(value); - xbt_dict_set(jedule->jedule_meta_info, key, val_cp, nullptr); + jedule->jedule_meta_info.insert({key, value}); } void jed_create_jedule(jedule_t *jedule) { *jedule = xbt_new0(s_jedule_t,1); host2_simgrid_parent_container = xbt_dict_new_homogeneous(nullptr); container_name2container = xbt_dict_new_homogeneous(nullptr); - (*jedule)->jedule_meta_info = xbt_dict_new_homogeneous(nullptr); } void jed_free_jedule(jedule_t jedule) { jed_free_container(jedule->root_container); - xbt_dict_free(&jedule->jedule_meta_info); xbt_free(jedule); xbt_dict_free(&host2_simgrid_parent_container); diff --git a/src/instr/jedule/jedule_sd_binding.cpp b/src/instr/jedule/jedule_sd_binding.cpp index 31ba7891eb..c321a598b6 100644 --- a/src/instr/jedule/jedule_sd_binding.cpp +++ b/src/instr/jedule/jedule_sd_binding.cpp @@ -11,15 +11,16 @@ #include "surf/surf.h" #include "simgrid/jedule/jedule_sd_binding.h" -#include "simgrid/jedule/jedule_events.h" -#include "simgrid/jedule/jedule_platform.h" -#include "simgrid/jedule/jedule_output.h" - #include "simgrid/simdag.h" #include "simgrid/s4u/As.hpp" #include "simgrid/s4u/engine.hpp" #include +#include "simgrid/forward.h" + +#include "simgrid/jedule/jedule_events.hpp" +#include "simgrid/jedule/jedule_output.hpp" +#include "simgrid/jedule/jedule_platform.hpp" #include "../../simdag/simdag_private.hpp" #if HAVE_JEDULE @@ -27,76 +28,29 @@ XBT_LOG_NEW_CATEGORY(jedule, "Logging specific to Jedule"); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jed_sd, jedule, "Logging specific to Jedule SD binding"); -jedule_t jedule; +jedule_t my_jedule; void jedule_log_sd_event(SD_task_t task) { - jed_event_t event; - xbt_assert(task != nullptr); - xbt_dynar_t host_list = xbt_dynar_new(sizeof(char*), nullptr); - - for(auto host: *task->allocation){ - const char *hostname = sg_host_get_name(host); - xbt_dynar_push(host_list, &hostname); - } - - create_jed_event(&event, (char*)SD_task_get_name(task), task->start_time, task->finish_time,"SD"); - - jed_event_add_resources(event, host_list); + jed_event_t event = + new simgrid::jedule::Event(std::string(SD_task_get_name(task)), task->start_time, task->finish_time,"SD"); + event->addResources(task->allocation); jedule_store_event(event); - - xbt_dynar_free(&host_list); -} - -static void create_hierarchy(AS_t current_comp, jed_simgrid_container_t current_container) -{ - xbt_dict_cursor_t cursor = nullptr; - char *key; - AS_t elem; - xbt_dict_t routing_sons = current_comp->children(); - - if (xbt_dict_is_empty(routing_sons)) { - // I am no AS - // add hosts to jedule platform - xbt_dynar_t table = current_comp->hosts(); - xbt_dynar_t hosts; - unsigned int dynar_cursor; - sg_host_t host_elem; - - hosts = xbt_dynar_new(sizeof(char*), nullptr); - - xbt_dynar_foreach(table, dynar_cursor, host_elem) { - xbt_dynar_push_as(hosts, const char*, sg_host_get_name(host_elem)); - } - - jed_simgrid_add_resources(current_container, hosts); - xbt_dynar_free(&hosts); - xbt_dynar_free(&table); - } else { - xbt_dict_foreach(routing_sons, cursor, key, elem) { - jed_simgrid_container_t child_container; - jed_simgrid_create_container(&child_container, elem->name()); - jed_simgrid_add_container(current_container, child_container); - XBT_DEBUG("name : %s\n", elem->name()); - create_hierarchy(elem, child_container); - } - } } void jedule_setup_platform() { - jed_create_jedule(&jedule); + jed_create_jedule(&my_jedule); AS_t root_comp = simgrid::s4u::Engine::instance()->rootAs(); XBT_DEBUG("root name %s\n", root_comp->name()); - jed_simgrid_container_t root_container; - jed_simgrid_create_container(&root_container, root_comp->name()); - jedule->root_container = root_container; + jed_container_t root_container = new simgrid::jedule::Container(std::string(root_comp->name())); + my_jedule->root_container = root_container; - create_hierarchy(root_comp, root_container); + root_container->createHierarchy(root_comp); } void jedule_sd_cleanup() @@ -111,15 +65,15 @@ void jedule_sd_init() void jedule_sd_exit(void) { - if (jedule) { - jed_free_jedule(jedule); - jedule = nullptr; + if (my_jedule) { + jed_free_jedule(my_jedule); + my_jedule = nullptr; } } void jedule_sd_dump(const char * filename) { - if (jedule) { + if (my_jedule) { char *fname; FILE *fh; if (!filename) { @@ -130,7 +84,7 @@ void jedule_sd_dump(const char * filename) fh = fopen(fname, "w"); - write_jedule_output(fh, jedule, jedule_event_list, nullptr); + write_jedule_output(fh, my_jedule, jedule_event_list, nullptr); fclose(fh); free(fname); diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index ff7d97a5f0..a6c6363c4f 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -524,9 +524,9 @@ set(TRACING_SRC ) set(JEDULE_SRC - include/simgrid/jedule/jedule_events.h - include/simgrid/jedule/jedule_output.h - include/simgrid/jedule/jedule_platform.h + include/simgrid/jedule/jedule_events.hpp + include/simgrid/jedule/jedule_output.hpp + include/simgrid/jedule/jedule_platform.hpp include/simgrid/jedule/jedule_sd_binding.h src/instr/jedule/jedule_events.cpp src/instr/jedule/jedule_output.cpp -- 2.20.1