From: Christian Heinrich Date: Fri, 6 Jan 2017 13:31:08 +0000 (+0100) Subject: [SMPI] Added SmpiHost.cpp and .hpp X-Git-Tag: v3.16~360^2~2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e8e45482e5bc7f26685b40e12884e8bab8f0fab8?hp=6e25b005a8667e37e9010b4462dd3480ee4e577c [SMPI] Added SmpiHost.cpp and .hpp The SmpiHost is not yet fully implemented but is the first step towards a more configurable SMPI. --- diff --git a/src/smpi/SmpiHost.cpp b/src/smpi/SmpiHost.cpp new file mode 100644 index 0000000000..962ea77cb6 --- /dev/null +++ b/src/smpi/SmpiHost.cpp @@ -0,0 +1,82 @@ +#include "smpi/smpi_utils.hpp" +#include "src/smpi/SmpiHost.hpp" +#include "src/surf/virtual_machine.hpp" + +#include +#include + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_host, smpi, "Logging specific to SMPI (host)"); + +namespace simgrid { +namespace smpi { + +simgrid::xbt::Extension SmpiHost::EXTENSION_ID; + +double SmpiHost::orecv(size_t size) +{ + if (orecv_parsed_values.empty()) { + if (orecv_.empty()) { + std::string test = xbt_cfg_get_string("smpi/or"); + orecv_parsed_values = parse_factor(xbt_cfg_get_string("smpi/or")); + } + else + orecv_parsed_values = parse_factor(orecv_.c_str()); + } + + double current=orecv_parsed_values.empty()?0.0:orecv_parsed_values.front().values[0]+orecv_parsed_values.front().values[1]*size; + + // Iterate over all the sections that were specified and find the right value. (fact.factor represents the interval + // sizes; we want to find the section that has fact.factor <= size and no other such fact.factor <= size) + // Note: parse_factor() (used before) already sorts the vector we iterate over! + for (auto fact : orecv_parsed_values) { + if (size <= fact.factor) { // Values already too large, use the previously computed value of current! + XBT_DEBUG("or : %zu <= %zu return %.10f", size, fact.factor, current); + return current; + } else { + // If the next section is too large, the current section must be used. + // Hence, save the cost, as we might have to use it. + current=fact.values[0]+fact.values[1]*size; + } + } + XBT_DEBUG("smpi_or: %zu is larger than largest boundary, return %.10f", size, current); + + return current; +} + +SmpiHost::SmpiHost(simgrid::s4u::Host *ptr) : host(ptr) +{ + if (!SmpiHost::EXTENSION_ID.valid()) + SmpiHost::EXTENSION_ID = simgrid::s4u::Host::extension_create(); + + // if (host->properties() != nullptr) { + // char* off_power_str = (char*)xbt_dict_get_or_null(host->properties(), "watt_off"); + // if (off_power_str != nullptr) { + // char *msg = bprintf("Invalid value for property watt_off of host %s: %%s",host->name().c_str()); + // watts_off = xbt_str_parse_double(off_power_str, msg); + // xbt_free(msg); + // } + // else + // watts_off = 0; + // } +} + +SmpiHost::~SmpiHost()=default; + +static void onCreation(simgrid::s4u::Host& host) { +} + +static void onHostDestruction(simgrid::s4u::Host& host) { + // Ignore virtual machines + simgrid::surf::HostImpl* surf_host = host.extension(); + if (dynamic_cast(surf_host)) + return; +} + +void sg_smpi_host_init() +{ + simgrid::s4u::Host::onCreation.connect(&onCreation); + simgrid::s4u::Host::onDestruction.connect(&onHostDestruction); +} + +} +} diff --git a/src/smpi/SmpiHost.hpp b/src/smpi/SmpiHost.hpp new file mode 100644 index 0000000000..1d6daa5cad --- /dev/null +++ b/src/smpi/SmpiHost.hpp @@ -0,0 +1,42 @@ +#ifndef SMPI_HOST_HPP_ +#define SMPI_HOST_HPP_ + +#include "src/include/smpi/smpi_utils.hpp" + +#include +#include +#include +#include + + + +namespace simgrid { +namespace smpi { + +void sg_smpi_host_init(); +static void onHostDestruction(simgrid::s4u::Host& host); +static void onCreation(simgrid::s4u::Host& host); + +class SmpiHost { + + private: + std::vector orecv_parsed_values; + simgrid::s4u::Host *host = nullptr; + + public: + static simgrid::xbt::Extension EXTENSION_ID; + + explicit SmpiHost(simgrid::s4u::Host *ptr); + ~SmpiHost(); + + double wtime; + double osend; + double oisend; + std::string orecv_; + double orecv(size_t size); + +}; + +} +} +#endif diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 7da60c6188..e2e680acf5 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -220,6 +220,8 @@ set(SMPI_SRC src/smpi/smpi_f2c.hpp src/smpi/smpi_group.cpp src/smpi/smpi_group.hpp + src/smpi/SmpiHost.cpp + src/smpi/SmpiHost.hpp src/smpi/smpi_mpi.cpp src/smpi/smpi_datatype.cpp src/smpi/smpi_datatype.hpp