X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/cee8b7d98f1c3b6738ad5f0b20de7bed9ba08d5a..8b47d18183827cb13535fd1b3f50df6dfb04b73e:/examples/cpp/dag-scheduling/s4u-dag-scheduling.cpp diff --git a/examples/cpp/dag-scheduling/s4u-dag-scheduling.cpp b/examples/cpp/dag-scheduling/s4u-dag-scheduling.cpp index 155a84b479..97938f20de 100644 --- a/examples/cpp/dag-scheduling/s4u-dag-scheduling.cpp +++ b/examples/cpp/dag-scheduling/s4u-dag-scheduling.cpp @@ -1,10 +1,10 @@ -/* Copyright (c) 2009-2022. 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. */ /* simple test to schedule a DAX file with the Min-Min algorithm. */ -#include +#include #include #include #include @@ -73,47 +73,36 @@ static std::vector get_ready_tasks(const std::vectorget_dependencies(); - - if (not parents.empty()) { - double data_available = 0.; - double last_data_available; - /* compute last_data_available */ - last_data_available = -1.0; - for (const auto& parent : parents) { - /* normal case */ - if (const auto* comm = dynamic_cast(parent.get())) { - auto source = comm->get_source(); - XBT_DEBUG("transfer from %s to %s", source->get_cname(), host->get_cname()); - /* Estimate the redistribution time from this parent */ - double redist_time; - if (comm->get_remaining() <= 1e-6) { - redist_time = 0; - } else { - redist_time = sg_host_get_route_latency(source, host) + - comm->get_remaining() / sg_host_get_route_bandwidth(source, host); - } - // We use the user data field to store the finish time of the predecessor of the comm, i.e., its potential start - // time - data_available = *comm->get_data() + redist_time; - } - - /* no transfer, control dependency */ - if (const auto* exec = dynamic_cast(parent.get())) { - data_available = exec->get_finish_time(); + double data_available = 0.; + double last_data_available = -1.0; + /* compute last_data_available */ + for (const auto& parent : task->get_dependencies()) { + /* normal case */ + if (const auto* comm = dynamic_cast(parent.get())) { + auto source = comm->get_source(); + XBT_DEBUG("transfer from %s to %s", source->get_cname(), host->get_cname()); + /* Estimate the redistribution time from this parent */ + double redist_time; + if (comm->get_remaining() <= 1e-6) { + redist_time = 0; + } else { + redist_time = + sg_host_get_route_latency(source, host) + comm->get_remaining() / sg_host_get_route_bandwidth(source, host); } - - if (last_data_available < data_available) - last_data_available = data_available; + // We use the user data field to store the finish time of the predecessor of the comm, i.e., its potential start + // time + data_available = *comm->get_data() + redist_time; } - result = fmax(sg_host_get_available_at(host), last_data_available) + task->get_remaining() / host->get_speed(); - } else - result = sg_host_get_available_at(host) + task->get_remaining() / host->get_speed(); + /* no transfer, control dependency */ + if (const auto* exec = dynamic_cast(parent.get())) + data_available = exec->get_finish_time(); + + if (last_data_available < data_available) + last_data_available = data_available; + } - return result; + return std::max(sg_host_get_available_at(host), last_data_available) + task->get_remaining() / host->get_speed(); } static sg4::Host* get_best_host(const sg4::ExecPtr exec) @@ -176,10 +165,17 @@ int main(int argc, char** argv) }); e.load_platform(argv[1]); + const auto hosts = e.get_all_hosts(); + + /* Mark all hosts as sequential, as it ought to be in such a scheduling example. + * + * It means that the hosts can only compute one thing at a given time. If an execution already takes place on a given + * host, any subsequently started execution will be queued until after the first execution terminates */ + for (auto const& host : hosts) + host->set_concurrency_limit(1); /* Allocating the host attribute */ unsigned long total_nhosts = e.get_host_count(); - const auto hosts = e.get_all_hosts(); std::vector host_attributes(total_nhosts); for (unsigned long i = 0; i < total_nhosts; i++) hosts[i]->set_data(&host_attributes[i]); @@ -236,8 +232,8 @@ int main(int argc, char** argv) * new dependency */ - auto last_scheduled_task = sg_host_get_last_scheduled_task(selected_host); - if (last_scheduled_task && (last_scheduled_task->get_state() != sg4::Activity::State::FINISHED) && + if (auto last_scheduled_task = sg_host_get_last_scheduled_task(selected_host); + last_scheduled_task && (last_scheduled_task->get_state() != sg4::Activity::State::FINISHED) && (last_scheduled_task->get_state() != sg4::Activity::State::FAILED) && not dependency_exists(sg_host_get_last_scheduled_task(selected_host), selected_task)) last_scheduled_task->add_successor(selected_task);