X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/2f2db04b850386899392bc06568f17f071f8620f..8052f28d5b5a9d88b6724dff2e5e81dee10065d7:/src/dag/loaders.cpp diff --git a/src/dag/loaders.cpp b/src/dag/loaders.cpp index e78e7169a0..09591b1e83 100644 --- a/src/dag/loaders.cpp +++ b/src/dag/loaders.cpp @@ -1,5 +1,4 @@ -/* Copyright (c) 2009-2023. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2009-2023. 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. */ @@ -21,7 +20,15 @@ #include "dax_dtd.h" #include "dax_dtd.c" +#if SIMGRID_HAVE_JSON +// Disable implicit conversions. See https://github.com/nlohmann/json#implicit-conversions +#ifdef JSON_USE_IMPLICIT_CONVERSIONS +#undef JSON_USE_IMPLICIT_CONVERSIONS +#endif +#define JSON_USE_IMPLICIT_CONVERSIONS 0 #include +#include +#endif #if HAVE_GRAPHVIZ #include @@ -85,27 +92,33 @@ static ExecPtr current_job; /** @brief loads a JSON file describing a DAG * - * See https://github.com/wfcommons/wfformat for more details. + * See https://github.com/wfcommons/wfformat for more details. We support wfformat 1.4. */ std::vector create_DAG_from_json(const std::string& filename) { +#if SIMGRID_HAVE_JSON std::ifstream f(filename); auto data = nlohmann::json::parse(f); std::vector dag = {}; - std::map> successors = {}; + std::map, std::less<>> successors = {}; std::map comms_destinations = {}; ActivityPtr current; for (auto const& task: data["workflow"]["tasks"]) { if (task["type"] == "compute") { - current = Exec::init()->set_name(task["name"])->set_flops_amount(task["runtime"]); + current = + Exec::init()->set_name(task["name"].get())->set_flops_amount(task["runtimeInSeconds"].get()); if (task.contains("machine")) - dynamic_cast(current.get())->set_host(simgrid::s4u::Engine::get_instance()->host_by_name(task["machine"])); + dynamic_cast(current.get()) + ->set_host(simgrid::s4u::Engine::get_instance()->host_by_name(task["machine"].get())); } else if (task["type"] == "transfer"){ - current = Comm::sendto_init()->set_name(task["name"])->set_payload_size(task["bytesWritten"]); + current = Comm::sendto_init() + ->set_name(task["name"].get()) + ->set_payload_size(task["writtenBytes"].get()); if (task.contains("machine")) - comms_destinations[current] = simgrid::s4u::Engine::get_instance()->host_by_name(task["machine"]); + comms_destinations[current] = + simgrid::s4u::Engine::get_instance()->host_by_name(task["machine"].get()); if (task["parents"].size() == 1) { ActivityPtr parent_activity; for (auto const& activity: dag) { @@ -119,17 +132,15 @@ std::vector create_DAG_from_json(const std::string& filename) else if (dynamic_cast(parent_activity.get()) != nullptr) dynamic_cast(current.get())->set_source(dynamic_cast(parent_activity.get())->get_destination()); } + } else if (XBT_LOG_ISENABLED(dag_parsing, xbt_log_priority_debug)) { + std::stringstream ss; + ss << task["type"]; + XBT_DEBUG("Task type \"%s\" not supported.", ss.str().c_str()); } - else - XBT_DEBUG("Task type \"%s\" not supported.", task["type"]); dag.push_back(current); - for (auto const& parent: task["parents"]) { - auto it = successors.find(parent); - if (it == successors.end()) - successors[parent] = {}; - successors[parent].push_back(current); - } + for (auto const& parent : task["parents"]) + successors[parent.get()].push_back(current); } // Assign successors for (auto const& [parent, successors_list] : successors) @@ -145,12 +156,15 @@ std::vector create_DAG_from_json(const std::string& filename) // Start only Activities with dependencies solved for (auto const& activity: dag) { - if (dynamic_cast(activity.get()) != nullptr and activity->dependencies_solved()) + if (dynamic_cast(activity.get()) != nullptr && activity->dependencies_solved()) activity->start(); } return dag; +#else + xbt_die("JSON support was not compiled in, probably because nlohmann/json was not found. Please install " + "nlohmann-json3-dev and recompile SimGrid to use this feature."); +#endif } - /** @brief loads a DAX file describing a DAG * * See https://confluence.pegasus.isi.edu/display/pegasus/WorkflowGenerator for more details.