${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)
> [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
+++ /dev/null
-/* 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_ */
--- /dev/null
+/* 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 <vector>
+#include <string>
+#include <unordered_map>
+
+#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<sg_host_t> *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<jed_res_subset_t> resource_subsets;
+ std::vector<char*> characteristics_list; /* just a list of names (strings) */
+ std::unordered_map<char*, char*> info_map; /* key/value pairs */
+};
+}
+}
+
+SG_BEGIN_DECL()
+
+typedef simgrid::jedule::Event * jed_event_t;
+
+SG_END_DECL()
+
+#endif
+
+#endif /* JEDULE_EVENTS_H_ */
#include <stdio.h>
#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<char*, char*> key_value_dict);
SG_END_DECL()
#endif
#define JED_SIMGRID_PLATFORM_H_
#include "simgrid_config.h"
+#include "simgrid/forward.h"
#include "xbt/dynar.h"
#include "xbt/dict.h"
+#include <unordered_map>
+#include <vector>
+#include <string>
#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<const char*, int> name2id;
+ Container *parent;
+ std::vector<Container*> children;
+ std::vector<sg_host_t> resource_list;
+ void addChild(Container* child);
+ void addResources(std::vector<sg_host_t> hosts);
+ void createHierarchy(AS_t from_as);
+ std::vector<int> 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<char*, char*> 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
* 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<sg_host_t>* host_list);
/*
global:
#endif
-
#endif /* JED_SIMGRID_PLATFORM_H_ */
/* 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 <stdio.h>
#include <stdlib.h>
-#include <string.h>
+#include <string>
-#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<sg_host_t> *host_selection) {
xbt_dynar_t resource_subset_list;
jed_res_subset_t res_set;
unsigned int i;
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, " <event>\n");
+ fprintf(jed_file, " <prop key=\"name\" value=\"%s\" />\n", this->name.c_str());
+ fprintf(jed_file, " <prop key=\"start\" value=\"%g\" />\n", this->start_time);
+ fprintf(jed_file, " <prop key=\"end\" value=\"%g\" />\n", this->end_time);
+ fprintf(jed_file, " <prop key=\"type\" value=\"%s\" />\n", this->type.c_str());
+ fprintf(jed_file, " <res_util>\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, " <select resources=\"");
+ fprintf(jed_file, "%s", resid.c_str());
+ fprintf(jed_file, ".[%d-%d]", start, end);
+ fprintf(jed_file, "\" />\n");
+ }
- (*event)->start_time = start_time;
- (*event)->end_time = end_time;
+ fprintf(jed_file, " </res_util>\n");
+ if (!this->characteristics_list.empty()){
+ fprintf(jed_file, " <characteristics>\n");
+ for (auto ch: this->characteristics_list)
+ fprintf(jed_file, " <characteristic name=\"%s\" />\n", ch);
+ fprintf(jed_file, " </characteristics>\n");
+ }
- (*event)->type = xbt_strdup(type);
+ if (!this->info_map.empty()){
+ fprintf(jed_file, " <info>\n");
+ print_key_value_dict(jed_file, this->info_map);
+ fprintf(jed_file, " </info>\n");
+ }
- (*event)->resource_subsets = xbt_dynar_new(sizeof(jed_res_subset_t), xbt_free_ref);
- (*event)->characteristics_list = xbt_dynar_new(sizeof(char*), nullptr);
- (*event)->info_hash = xbt_dict_new_homogeneous(nullptr);
+ fprintf(jed_file, " </event>\n");
}
-void jed_event_free(jed_event_t event) {
- free(event->name);
- free(event->type);
-
- xbt_dynar_free(&event->resource_subsets);
-
- xbt_dynar_free(&event->characteristics_list);
- xbt_dict_free(&event->info_hash);
-
- free(event);
+}
}
#endif
/* 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_output.hpp"
+#include "simgrid/host.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xbt/dynar.h"
#include "xbt/asserts.h"
-#include "simgrid/jedule/jedule_output.h"
-
#if HAVE_JEDULE
#define STR_BUF_SIZE 1024
xbt_dynar_t jedule_event_list;
-static FILE *jed_file;
-
-static void get_hierarchy_list(xbt_dynar_t hier_list, jed_simgrid_container_t container) {
- xbt_assert( container != nullptr );
-
- if( container->parent != nullptr ) {
-
- if( container->parent->container_children == nullptr ) {
- // we are in the last level
- get_hierarchy_list(hier_list, container->parent);
- } else {
- unsigned int i;
- int child_nb = -1;
- jed_simgrid_container_t child_container;
-
- xbt_dynar_foreach(container->parent->container_children, i, child_container) {
- if( child_container == container ) {
- child_nb = i;
- break;
- }
- }
-
- xbt_assert( child_nb > - 1);
- xbt_dynar_insert_at(hier_list, 0, &child_nb);
-
- get_hierarchy_list(hier_list, container->parent);
- }
- } else {
- int top_level = 0;
- xbt_dynar_insert_at(hier_list, 0, &top_level);
- }
-}
-
-static void get_hierarchy_string(jed_simgrid_container_t container, char *outbuf, int bufsize) {
- char buf[STR_BUF_SIZE];
- xbt_dynar_t hier_list;
- unsigned int iter;
- int number;
- unsigned int length;
-
- outbuf[0] = '\0';
- hier_list = xbt_dynar_new(sizeof(int), nullptr);
- get_hierarchy_list(hier_list, container);
-
- length = xbt_dynar_length(hier_list);
-
- xbt_dynar_foreach(hier_list, iter, number) {
- if( iter != length-1 ) {
- snprintf(buf, STR_BUF_SIZE, "%d.", number);
- } else {
- snprintf(buf, STR_BUF_SIZE, "%d", number);
- }
- strncat(outbuf, buf, bufsize-strlen(outbuf));
- }
-
- xbt_dynar_free(&hier_list);
-}
-
-static void print_key_value_dict(xbt_dict_t key_value_dict) {
- xbt_dict_cursor_t cursor=nullptr;
- char *key,*data;
-
- if( key_value_dict != nullptr ) {
- xbt_dict_foreach(key_value_dict,cursor,key,data) {
- fprintf(jed_file, " <prop key=\"%s\" value=\"%s\" />\n",key,data);
- }
- }
-}
-
-static void print_resources(jed_simgrid_container_t resource_parent) {
- unsigned int res_nb;
- unsigned int i;
- char *res_name;
- char resid[STR_BUF_SIZE];
- xbt_assert( resource_parent->resource_list != nullptr );
-
- res_nb = xbt_dynar_length(resource_parent->resource_list);
-
- get_hierarchy_string(resource_parent, resid, STR_BUF_SIZE);
-
- fprintf(jed_file, " <rset id=\"%s\" nb=\"%d\" names=\"", resid, res_nb);
- xbt_dynar_foreach(resource_parent->resource_list, i, res_name) {
- fprintf(jed_file, "%s", res_name);
- if( i != res_nb-1 ) {
- fprintf(jed_file, "|");
- }
- }
- fprintf(jed_file, "\" />\n");
-}
-
-static void print_container(jed_simgrid_container_t container) {
- unsigned int i;
- jed_simgrid_container_t child_container;
- xbt_assert( container != nullptr );
-
- fprintf(jed_file, " <res name=\"%s\">\n", container->name);
- if( container->container_children != nullptr ) {
- xbt_dynar_foreach(container->container_children, i, child_container) {
- print_container(child_container);
+void print_key_value_dict(FILE *jed_file, std::unordered_map<char*, char*> key_value_dict) {
+ if(!key_value_dict.empty()) {
+ for (auto elm: key_value_dict) {
+ fprintf(jed_file, " <prop key=\"%s\" value=\"%s\" />\n",elm.first,elm.second);
}
- } else {
- print_resources(container);
}
- fprintf(jed_file, " </res>\n");
}
-static void print_platform(jed_simgrid_container_t root_container) {
+static void print_platform(FILE *jed_file, jed_container_t root_container) {
fprintf(jed_file, " <platform>\n");
- print_container(root_container);
+ root_container->print(jed_file);
fprintf(jed_file, " </platform>\n");
}
-static void print_event(jed_event_t event) {
- unsigned int i;
- jed_res_subset_t subset;
-
- xbt_assert( event != nullptr );
- xbt_assert( event->resource_subsets != nullptr );
-
- fprintf(jed_file, " <event>\n");
-
- fprintf(jed_file, " <prop key=\"name\" value=\"%s\" />\n", event->name);
- fprintf(jed_file, " <prop key=\"start\" value=\"%g\" />\n", event->start_time);
- fprintf(jed_file, " <prop key=\"end\" value=\"%g\" />\n", event->end_time);
- fprintf(jed_file, " <prop key=\"type\" value=\"%s\" />\n", event->type);
-
- fprintf(jed_file, " <res_util>\n");
-
- xbt_dynar_foreach(event->resource_subsets, i, subset) {
- int start = subset->start_idx;
- int end = subset->start_idx + subset->nres - 1;
- char resid[STR_BUF_SIZE];
-
- get_hierarchy_string(subset->parent, resid, STR_BUF_SIZE);
- fprintf(jed_file, " <select resources=\"");
- fprintf(jed_file, "%s", resid);
- fprintf(jed_file, ".[%d-%d]", start, end);
- fprintf(jed_file, "\" />\n");
- }
-
- fprintf(jed_file, " </res_util>\n");
- if (!xbt_dynar_is_empty(event->characteristics_list)){
- fprintf(jed_file, " <characteristics>\n");
- char *ch;
- unsigned int iter;
- xbt_dynar_foreach(event->characteristics_list, iter, ch) {
- fprintf(jed_file, " <characteristic name=\"%s\" />\n", ch);
- }
- fprintf(jed_file, " </characteristics>\n");
- }
-
- if (!xbt_dict_is_empty(event->info_hash)){
- fprintf(jed_file, " <info>\n");
- print_key_value_dict(event->info_hash);
- fprintf(jed_file, " </info>\n");
- }
-
- fprintf(jed_file, " </event>\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, " <events>\n");
xbt_dynar_foreach(event_list, i, event) {
- print_event(event);
+ event->print(jed_file);
}
fprintf(jed_file, " </events>\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, "<jedule>\n");
+ fprintf(file, "<jedule>\n");
- if (!xbt_dict_is_empty(jedule->jedule_meta_info)){
- fprintf(jed_file, " <jedule_meta>\n");
- print_key_value_dict(jedule->jedule_meta_info);
- fprintf(jed_file, " </jedule_meta>\n");
+ if (!jedule->jedule_meta_info.empty()){
+ fprintf(file, " <jedule_meta>\n");
+ print_key_value_dict(file, jedule->jedule_meta_info);
+ fprintf(file, " </jedule_meta>\n");
}
- print_platform(jedule->root_container);
+ print_platform(file, jedule->root_container);
- print_events(event_list);
+ print_events(file, event_list);
- fprintf(jed_file, "</jedule>\n");
+ fprintf(file, "</jedule>\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) {
/* 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 <string>
#include <stdlib.h>
-#include <string.h>
+#include <stdio.h>
#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<sg_host_t> 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<sg_host_t> 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<int> 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<int> heir_list = this->parent->getHierarchy();
+ heir_list.insert(heir_list.begin(), child_nb);
+ return heir_list;
+ }
+ } else {
+ int top_level = 0;
+ std::vector<int> 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<int> 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, " <rset id=\"%s\" nb=\"%u\" names=\"", resid.c_str(), res_nb);
+ for (auto res: this->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, " <res name=\"%s\">\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, " </res>\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 );
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
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<int*>(xbt_dynar_to_array(id_list));
if( nb_ids > 0 ) {
int start = 0;
}
}
- 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<sg_host_t> *host_list) {
+ std::unordered_map<const char*, xbt_dynar_t> 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);
#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 <stdio.h>
+#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
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()
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) {
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);
)
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