1 /* Copyright (c) 2017-2022. 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 "smpi_host.hpp"
8 #include "simgrid/s4u/VirtualMachine.hpp"
10 #include "smpi_utils.hpp"
11 #include "xbt/config.hpp"
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_host, smpi, "Logging specific to SMPI (host)");
19 /* save user's cost callbacks for SMPI operations */
20 static std::unordered_map<SmpiOperation, SmpiOpCostCb> cost_cbs;
22 void smpi_register_op_cost_callback(SmpiOperation op, const SmpiOpCostCb& cb)
27 void smpi_cleanup_op_cost_callback()
32 namespace simgrid::smpi {
34 xbt::Extension<s4u::Host, smpi::Host> Host::EXTENSION_ID;
36 double Host::orecv(size_t size, s4u::Host* src, s4u::Host* dst)
38 /* return user's callback if available */
39 if (auto it = cost_cbs.find(SmpiOperation::RECV); it != cost_cbs.end())
40 return it->second(size, src, dst);
45 double Host::osend(size_t size, s4u::Host* src, s4u::Host* dst)
47 /* return user's callback if available */
48 if (auto it = cost_cbs.find(SmpiOperation::SEND); it != cost_cbs.end())
49 return it->second(size, src, dst);
54 double Host::oisend(size_t size, s4u::Host* src, s4u::Host* dst)
56 /* return user's callback if available */
57 if (auto it = cost_cbs.find(SmpiOperation::ISEND); it != cost_cbs.end())
58 return it->second(size, src, dst);
63 void Host::check_factor_configs(const std::string& op) const
65 static const std::unordered_map<std::string, SmpiOperation> name_to_op_enum{
66 {"smpi/or", SmpiOperation::RECV}, {"smpi/os", SmpiOperation::SEND}, {"smpi/ois", SmpiOperation::ISEND}};
67 if (cost_cbs.find(name_to_op_enum.at(op)) != cost_cbs.end() &&
68 (host->get_property(op) || not config::is_default(op.c_str()))) {
69 XBT_WARN("SMPI (host: %s): mismatch cost functions for %s. Only user's callback will be used.", host->get_cname(),
74 Host::Host(s4u::Host* ptr) : host(ptr)
76 if (not smpi::Host::EXTENSION_ID.valid())
77 smpi::Host::EXTENSION_ID = s4u::Host::extension_create<Host>();
79 check_factor_configs("smpi/or");
80 if (const char* orecv_string = host->get_property("smpi/or"))
81 orecv_.parse(orecv_string);
83 orecv_.parse(config::get_value<std::string>("smpi/or"));
85 check_factor_configs("smpi/os");
86 if (const char* osend_string = host->get_property("smpi/os"))
87 osend_.parse(osend_string);
89 osend_.parse(config::get_value<std::string>("smpi/os"));
91 check_factor_configs("smpi/ois");
92 if (const char* oisend_string = host->get_property("smpi/ois"))
93 oisend_.parse(oisend_string);
95 oisend_.parse(config::get_value<std::string>("smpi/ois"));
98 } // namespace simgrid::smpi