From 5ba9dd101068054af5f53a5d19d3cbeedb73f8e1 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Thu, 5 Mar 2020 10:03:22 +0100 Subject: [PATCH] add C version of exec-remote --- .gitignore | 2 + MANIFEST.in | 2 + examples/README.rst | 4 ++ examples/c/CMakeLists.txt | 4 +- examples/c/exec-remote/exec-remote.c | 62 +++++++++++++++++++++++++ examples/c/exec-remote/exec-remote.tesh | 12 +++++ 6 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 examples/c/exec-remote/exec-remote.c create mode 100644 examples/c/exec-remote/exec-remote.tesh diff --git a/.gitignore b/.gitignore index fe6000b9cb..eba7785c68 100644 --- a/.gitignore +++ b/.gitignore @@ -138,7 +138,9 @@ examples/c/cloud-simple/cloud-simple-c examples/c/energy-exec/energy-exec-c examples/c/energy-exec-ptask/energy-exec-ptask-c examples/c/energy-vm/energy-vm-c +examples/c/exec-basic/exec-basic-c examples/c/exec-dvfs/exec-dvfs-c +examples/c/exec-remote/exec-remote-c examples/c/io-disk-raw/io-disk-raw-c examples/c/io-file-remote/io-file-remote-c examples/c/plugin-hostload/plugin-hostload-c diff --git a/MANIFEST.in b/MANIFEST.in index a7b2fdc6bd..3afdbb3076 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -76,6 +76,8 @@ include examples/c/exec-basic/exec-basic.c include examples/c/exec-basic/exec-basic.tesh include examples/c/exec-dvfs/exec-dvfs.c include examples/c/exec-dvfs/exec-dvfs.tesh +include examples/c/exec-remote/exec-remote.c +include examples/c/exec-remote/exec-remote.tesh include examples/c/io-disk-raw/io-disk-raw.c include examples/c/io-disk-raw/io-disk-raw.tesh include examples/c/io-file-remote/io-file-remote.c diff --git a/examples/README.rst b/examples/README.rst index 3e6f6cefc5..538cc71051 100644 --- a/examples/README.rst +++ b/examples/README.rst @@ -391,6 +391,10 @@ Executions on the CPU See also :py:func:`simgrid.Exec.set_host()`. + .. example-tab:: examples/c/exec-remote/exec-remote.c + + See also :cpp:func:`sg_exec_set_host()`. + - **Parallel executions:** These objects are convenient abstractions of parallel computational kernels that span over several machines, such as a diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index 1bd07556bf..48e8a61764 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -7,7 +7,7 @@ foreach(x app-pingpong app-token-ring async-wait async-waitall async-waitany cloud-capping cloud-migration cloud-simple - exec-basic exec-dvfs + exec-basic exec-dvfs exec-remote energy-exec energy-exec-ptask energy-vm io-disk-raw io-file-remote plugin-hostload) @@ -62,7 +62,7 @@ foreach(x app-chainsend app-pingpong app-token-ring async-wait async-waitall async-waitany cloud-capping cloud-migration cloud-simple - exec-basic exec-dvfs + exec-basic exec-dvfs exec-remote energy-exec energy-exec-ptask energy-vm io-disk-raw io-file-remote plugin-hostload) diff --git a/examples/c/exec-remote/exec-remote.c b/examples/c/exec-remote/exec-remote.c new file mode 100644 index 0000000000..79cd017fb1 --- /dev/null +++ b/examples/c/exec-remote/exec-remote.c @@ -0,0 +1,62 @@ +/* Copyright (c) 2007-2020. 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 "simgrid/actor.h" +#include "simgrid/engine.h" +#include "simgrid/exec.h" +#include "simgrid/host.h" + +#include "xbt/log.h" + +XBT_LOG_NEW_DEFAULT_CATEGORY(exec_remote, "Messages specific for this example"); + +static void wizard(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[]) +{ + const_sg_host_t fafard = sg_host_by_name("Fafard"); + sg_host_t ginette = sg_host_by_name("Ginette"); + sg_host_t boivin = sg_host_by_name("Boivin"); + + XBT_INFO("I'm a wizard! I can run a task on the Ginette host from the Fafard one! Look!"); + sg_exec_t exec = sg_actor_exec_init(48.492e6); + sg_exec_set_host(exec, ginette); + sg_exec_start(exec); + XBT_INFO("It started. Running 48.492Mf takes exactly one second on Ginette (but not on Fafard)."); + + sg_actor_sleep_for(0.1); + XBT_INFO("Loads in flops/s: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", sg_host_load(boivin), sg_host_load(fafard), + sg_host_load(ginette)); + + sg_exec_wait(exec); + + XBT_INFO("Done!"); + XBT_INFO("And now, harder. Start a remote task on Ginette and move it to Boivin after 0.5 sec"); + exec = sg_actor_exec_init(73293500); + sg_exec_set_host(exec, ginette); + sg_exec_start(exec); + + sg_actor_sleep_for(0.5); + XBT_INFO("Loads before the move: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", sg_host_load(boivin), sg_host_load(fafard), + sg_host_load(ginette)); + + sg_exec_set_host(exec, boivin); + + sg_actor_sleep_for(0.1); + XBT_INFO("Loads after the move: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", sg_host_load(boivin), sg_host_load(fafard), + sg_host_load(ginette)); + + sg_exec_wait(exec); + XBT_INFO("Done!"); +} + +int main(int argc, char* argv[]) +{ + simgrid_init(&argc, argv); + simgrid_load_platform(argv[1]); + sg_actor_create("test", sg_host_by_name("Fafard"), wizard, 0, NULL); + + simgrid_run(); + + return 0; +} diff --git a/examples/c/exec-remote/exec-remote.tesh b/examples/c/exec-remote/exec-remote.tesh new file mode 100644 index 0000000000..784c6c1ff9 --- /dev/null +++ b/examples/c/exec-remote/exec-remote.tesh @@ -0,0 +1,12 @@ +#!/usr/bin/env tesh + +! output sort 19 +$ ${bindir:=.}/exec-remote-c ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:test@Fafard) I'm a wizard! I can run a task on the Ginette host from the Fafard one! Look! +> [ 0.000000] (1:test@Fafard) It started. Running 48.492Mf takes exactly one second on Ginette (but not on Fafard). +> [ 0.100000] (1:test@Fafard) Loads in flops/s: Boivin=0; Fafard=0; Ginette=48492000 +> [ 1.000000] (1:test@Fafard) Done! +> [ 1.000000] (1:test@Fafard) And now, harder. Start a remote task on Ginette and move it to Boivin after 0.5 sec +> [ 1.500000] (1:test@Fafard) Loads before the move: Boivin=0; Fafard=0; Ginette=48492000 +> [ 1.600000] (1:test@Fafard) Loads after the move: Boivin=98095000; Fafard=0; Ginette=0 +> [ 2.000000] (1:test@Fafard) Done! -- 2.20.1