From 00a95a666da253bfdbb797d8bf26d2dbf35eb11b Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Mon, 8 Mar 2021 18:24:05 +0100 Subject: [PATCH] new example with ptasks on multi-core hosts --- .gitignore | 1 + MANIFEST.in | 2 + examples/cpp/CMakeLists.txt | 5 +- .../s4u-exec-ptask-multicore.cpp | 56 +++++++++++++++++++ .../s4u-exec-ptask-multicore.tesh | 10 ++++ 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 examples/cpp/exec-ptask-multicore/s4u-exec-ptask-multicore.cpp create mode 100644 examples/cpp/exec-ptask-multicore/s4u-exec-ptask-multicore.tesh diff --git a/.gitignore b/.gitignore index b46ee9cd99..ac8438af3b 100644 --- a/.gitignore +++ b/.gitignore @@ -195,6 +195,7 @@ examples/cpp/exec-basic/s4u-exec-basic examples/cpp/exec-dependent/s4u-exec-dependent examples/cpp/exec-dvfs/s4u-exec-dvfs examples/cpp/exec-ptask/s4u-exec-ptask +examples/cpp/exec-ptask-multicore/s4u-exec-ptask-multicore examples/cpp/exec-remote/s4u-exec-remote examples/cpp/exec-unassigned/s4u-exec-unassigned examples/cpp/exec-waitany/s4u-exec-waitany diff --git a/MANIFEST.in b/MANIFEST.in index b8f9628bf7..c4d738fdaa 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -237,6 +237,8 @@ include examples/cpp/exec-dependent/s4u-exec-dependent.cpp include examples/cpp/exec-dependent/s4u-exec-dependent.tesh include examples/cpp/exec-dvfs/s4u-exec-dvfs.cpp include examples/cpp/exec-dvfs/s4u-exec-dvfs.tesh +include examples/cpp/exec-ptask-multicore/s4u-exec-ptask-multicore.cpp +include examples/cpp/exec-ptask-multicore/s4u-exec-ptask-multicore.tesh include examples/cpp/exec-ptask/s4u-exec-ptask.cpp include examples/cpp/exec-ptask/s4u-exec-ptask.tesh include examples/cpp/exec-remote/s4u-exec-remote.cpp diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index 393f3f89db..15af769ee7 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -68,10 +68,11 @@ foreach (example actor-create actor-daemon actor-exiting actor-join actor-kill dht-chord dht-kademlia energy-exec energy-boot energy-link energy-vm energy-exec-ptask energy-wifi engine-filtering - exec-async exec-basic exec-dvfs exec-ptask exec-remote exec-waitany exec-waitfor exec-dependent exec-unassigned + exec-async exec-basic exec-dvfs exec-remote exec-waitany exec-waitfor exec-dependent exec-unassigned + exec-ptask exec-ptask-multicore maestro-set mc-bugged1 mc-bugged2 mc-electric-fence mc-failing-assert - network-wifi + network-wifi io-async io-file-system io-file-remote io-disk-raw io-dependent platform-failures platform-profile platform-properties plugin-host-load plugin-link-load diff --git a/examples/cpp/exec-ptask-multicore/s4u-exec-ptask-multicore.cpp b/examples/cpp/exec-ptask-multicore/s4u-exec-ptask-multicore.cpp new file mode 100644 index 0000000000..10627091ac --- /dev/null +++ b/examples/cpp/exec-ptask-multicore/s4u-exec-ptask-multicore.cpp @@ -0,0 +1,56 @@ +/* Copyright (c) 2017-2021. 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_NEW_DEFAULT_CATEGORY(s4u_ptask_multicore, "Messages specific for this s4u example"); + +namespace sg4 = simgrid::s4u; + +static void runner() +{ + auto e = sg4::Engine::get_instance(); + std::vector comp(2, 1e9); + std::vector comm(4, 0.0); + // Different hosts. + std::vector hosts_diff = {e->host_by_name("MyHost2"), e->host_by_name("MyHost3")}; + double start_time = e->get_clock(); + sg4::this_actor::parallel_execute(hosts_diff, comp, comm); + XBT_INFO("Computed 2-core activity on two different hosts. Took %g s", e->get_clock() - start_time); + + // Same host, monocore. + std::vector monocore_hosts = {e->host_by_name("MyHost2"), e->host_by_name("MyHost2")}; + start_time = e->get_clock(); + sg4::this_actor::parallel_execute(monocore_hosts, comp, comm); + XBT_INFO("Computed 2-core activity one 1-core host. Took %g s", e->get_clock() - start_time); + + // Same host, multicore. + std::vector multicore_host = {e->host_by_name("MyHost1"), e->host_by_name("MyHost1")}; + start_time = e->get_clock(); + sg4::this_actor::parallel_execute(multicore_host, comp, comm); + XBT_INFO("Computed 2-core activity on one 2-core host. Took %g s", e->get_clock() - start_time); + + // Same host, using too many cores + std::vector comp6(6, 1e9); + std::vector comm6(36, 0.0); + std::vector multicore_overload(6, e->host_by_name("MyHost1")); + start_time = e->get_clock(); + sg4::this_actor::parallel_execute(multicore_overload, comp6, comm6); + XBT_INFO("Computed 6-core activity of a 4-core host. Took %g s", e->get_clock() - start_time); +} + +int main(int argc, char* argv[]) +{ + sg4::Engine e(&argc, argv); + + xbt_assert(argc == 2, "Usage: %s ", argv[0]); + + e.load_platform(argv[1]); + sg4::Actor::create("test", sg4::Host::by_name("MyHost1"), runner); + + e.run(); + XBT_INFO("Simulation done."); + return 0; +} diff --git a/examples/cpp/exec-ptask-multicore/s4u-exec-ptask-multicore.tesh b/examples/cpp/exec-ptask-multicore/s4u-exec-ptask-multicore.tesh new file mode 100644 index 0000000000..2dadba223a --- /dev/null +++ b/examples/cpp/exec-ptask-multicore/s4u-exec-ptask-multicore.tesh @@ -0,0 +1,10 @@ +#!/usr/bin/env tesh + +$ ${bindir:=.}/s4u-exec-ptask-multicore ${platfdir}/energy_platform.xml --cfg=host/model:ptask_L07 --log=no_loc "--log=root.fmt:[%10.6r]%e%m%n" +> [ 0.000000] Configuration change: Set 'host/model' to 'ptask_L07' +> [ 0.000000] Switching to the L07 model to handle parallel tasks. +> [ 10.000000] Computed 2-core activity on two different hosts. Took 10 s +> [ 30.000000] Computed 2-core activity one 1-core host. Took 20 s +> [ 40.000000] Computed 2-core activity on one 2-core host. Took 10 s +> [ 55.000000] Computed 6-core activity of a 4-core host. Took 15 s +> [ 55.000000] Simulation done. \ No newline at end of file -- 2.20.1