1 /* Copyright (c) 2006-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include <simgrid/s4u.hpp>
8 namespace sg4 = simgrid::s4u;
11 * @brief User's callback to set dynamic cost for MPI operations
13 * Note that src host can be a nullptr for some collective operations.
14 * This is due the creation of an special requests that aggregates sub-requests
15 * in collective operations. But it doesn't happen in this example
17 * @param op MPI Operation (set by user at cb registering below)
18 * @param size Message size (set by simgrid)
19 * @param src Source host (set by simgrid)
20 * @param dst Source host (set by simgrid)
22 static double smpi_cost_cb(SmpiOperation op, size_t /*size*/, const sg4::Host* src, const sg4::Host* dst)
24 /* some dummy cost that depends on the operation and host */
25 static std::unordered_map<std::string, double> read_cost = {{"Tremblay", 1}, {"Jupiter", 2}};
26 static std::unordered_map<std::string, double> write_cost = {{"Tremblay", 5}, {"Jupiter", 10}};
28 if (op == SmpiOperation::RECV)
29 return read_cost[src->get_name()];
31 return write_cost[dst->get_name()];
35 * Creates a platform for examples/smpi/simple-execute/simple-execute.c MPI program
37 * Sets specific cost for MPI_Send and MPI_Recv operations
39 extern "C" void load_platform(const sg4::Engine& e);
40 void load_platform(const sg4::Engine& /*e*/)
42 /* create a simple 2 host platform inspired from small_platform.xml */
43 auto* root = sg4::create_full_zone("zone0");
45 const sg4::Host* tremblay = root->create_host("Tremblay", "98.095Mf")->seal();
46 const sg4::Host* jupiter = root->create_host("Jupiter", "76.296Mf")->seal();
48 const sg4::Link* link9 = root->create_split_duplex_link("9", "7.20975MBps")->set_latency("1.461517ms")->seal();
50 root->add_route(tremblay->get_netpoint(), jupiter->get_netpoint(), nullptr, nullptr,
51 {{link9, sg4::LinkInRoute::Direction::UP}}, true);
54 /* set cost callback for MPI_Send and MPI_Recv */
55 smpi_register_op_cost_callback(SmpiOperation::SEND,
56 std::bind(&smpi_cost_cb, SmpiOperation::SEND, std::placeholders::_1,
57 std::placeholders::_2, std::placeholders::_3));
59 smpi_register_op_cost_callback(SmpiOperation::RECV,
60 std::bind(&smpi_cost_cb, SmpiOperation::RECV, std::placeholders::_1,
61 std::placeholders::_2, std::placeholders::_3));