From: Christian Heinrich Date: Fri, 1 Jun 2018 08:15:10 +0000 (+0200) Subject: [S4U] Add some tests for upcoming filtering feature X-Git-Tag: v3.20~169 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/255679960704cbcb615939d55e26b8c20c02a050?ds=sidebyside [S4U] Add some tests for upcoming filtering feature These tests are currently neither active nor compilable, because we haven't implemented this feature yet. See next commit. --- diff --git a/examples/s4u/engine-filtering/s4u-engine-filtering.cpp b/examples/s4u/engine-filtering/s4u-engine-filtering.cpp new file mode 100644 index 0000000000..935f1103e7 --- /dev/null +++ b/examples/s4u/engine-filtering/s4u-engine-filtering.cpp @@ -0,0 +1,84 @@ +/* Copyright (c) 2017-2018. 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. */ + +#include "xbt/log.h" +#include + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_engine_filtering, "Messages specific for this s4u example"); + +namespace filter { +class FrequencyChanged { + std::map host_list; + +public: + FrequencyChanged(simgrid::s4u::Engine& e) { + std::vector list = e.get_all_hosts(); + for (auto& host : list) { + host_list.insert({host, host->get_pstate()}); + } + } + + bool operator()(simgrid::s4u::Host* host) { return host->get_pstate() != host_list.at(host); } + + double get_old_speed(simgrid::s4u::Host* host) { return host_list.at(host); } +}; +class SingleCore { +public: + bool operator()(simgrid::s4u::Host* host) { return host->get_core_count() == 1; } +}; + +bool filter_speed_more_than_50Mf(simgrid::s4u::Host* host); +bool filter_speed_more_than_50Mf(simgrid::s4u::Host* host) +{ + return host->getSpeed() > 50E6; +} +} +int main(int argc, char* argv[]) +{ + simgrid::s4u::Engine e(&argc, argv); + e.load_platform(argv[1]); + + /** + * Use a lambda function to filter hosts: We only want multicore hosts + */ + XBT_INFO("Hosts currently registered with this engine: %lu", e.get_host_count()); + std::vector list = + e.get_filtered_hosts([](simgrid::s4u::Host* host) { return host->get_core_count() > 1; }); + + for (auto& host : list) + XBT_INFO("The following hosts have more than one core: %s", host->get_cname()); + + xbt_assert(list.size() == 1); + + /* + * Use a function object (functor) without memory + */ + list = e.get_filtered_hosts(filter::SingleCore()); + + for (auto& host : list) + XBT_INFO("The following hosts are SingleCore: %s", host->get_cname()); + + /** + * This just shows how to use a function object that uses + * memory to filter. + */ + XBT_INFO("A simple example: Let's retrieve all hosts that changed their frequency"); + filter::FrequencyChanged filter(e); + e.host_by_name("MyHost2")->set_pstate(2); + list = e.get_filtered_hosts(filter); + + for (auto& host : list) + XBT_INFO("The following hosts changed their frequency: %s (from %.1ff to %.1ff)", host->get_cname(), host->getPstateSpeed(filter.get_old_speed(host)), host->getSpeed()); + + /* + * You can also just use any normal function (namespaced as well, if you want) to filter + */ + list = e.get_filtered_hosts(filter::filter_speed_more_than_50Mf); + + for (auto& host : list) + XBT_INFO("The following hosts have a frequency > 50Mf: %s", host->get_cname()); + + return 0; +} diff --git a/examples/s4u/engine-filtering/s4u-engine-filtering.tesh b/examples/s4u/engine-filtering/s4u-engine-filtering.tesh new file mode 100644 index 0000000000..07f0d99d85 --- /dev/null +++ b/examples/s4u/engine-filtering/s4u-engine-filtering.tesh @@ -0,0 +1,14 @@ +#!/usr/bin/env tesh + +p Let's filter some hosts... +$ ${bindir:=.}/s4u-engine-filtering$EXEEXT ${platfdir}/energy_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=network/model:CM02 --cfg=network/crosstraffic:no +> [ 0.000000] (0:maestro@) Configuration change: Set 'network/model' to 'CM02' +> [ 0.000000] (0:maestro@) Configuration change: Set 'network/crosstraffic' to 'no' +> [ 0.000000] (0:maestro@) Hosts currently registered with this engine: 3 +> [ 0.000000] (0:maestro@) The following hosts have more than one core: MyHost1 +> [ 0.000000] (0:maestro@) The following hosts are SingleCore: MyHost2 +> [ 0.000000] (0:maestro@) The following hosts are SingleCore: MyHost3 +> [ 0.000000] (0:maestro@) A simple example: Let's retrieve all hosts that changed their frequency +> [ 0.000000] (0:maestro@) The following hosts changed their frequency: MyHost2 (from 100000000.0f to 20000000.0f) +> [ 0.000000] (0:maestro@) The following hosts have a frequency > 50Mf: MyHost1 +> [ 0.000000] (0:maestro@) The following hosts have a frequency > 50Mf: MyHost3