File: s4u-plugin-link-load.cpp

package info (click to toggle)
simgrid 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 38,980 kB
  • sloc: cpp: 123,583; ansic: 66,779; python: 8,358; java: 6,406; fortran: 6,079; f90: 5,123; xml: 4,587; sh: 2,337; perl: 1,436; makefile: 105; lisp: 49; javascript: 7; sed: 6
file content (108 lines) | stat: -rw-r--r-- 3,450 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* Copyright (c) 2007-2025. 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/plugins/load.h"
#include "simgrid/s4u.hpp"
#include "simgrid/s4u/Engine.hpp"

XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
namespace sg4 = simgrid::s4u;

static void sender(const std::string& mailbox, uint64_t msg_size)
{
  auto* mbox         = sg4::Mailbox::by_name(mailbox);
  static int payload = 42;
  mbox->put(&payload, msg_size);
}

static void receiver(const std::string& mailbox)
{
  auto* mbox = sg4::Mailbox::by_name(mailbox);
  mbox->get<int>();
}

static void run_transfer(sg4::Engine& e, sg4::Host* src_host, sg4::Host* dst_host, const std::string& mailbox,
                         unsigned long msg_size)
{
  XBT_INFO("Launching the transfer of %lu bytes", msg_size);
  e.add_actor("sender", src_host, sender, mailbox, msg_size);
  e.add_actor("receiver", dst_host, receiver, mailbox);
}

static void execute_load_test()
{
  sg4::Engine& e = *sg4::this_actor::get_engine();
  auto* host0 = sg4::Host::by_name("node-0.simgrid.org");
  auto* host1 = sg4::Host::by_name("node-1.simgrid.org");

  sg4::this_actor::sleep_for(1);
  run_transfer(e, host0, host1, "1", 1000 * 1000 * 1000);

  sg4::this_actor::sleep_for(10);
  run_transfer(e, host0, host1, "2", 1000 * 1000 * 1000);
  sg4::this_actor::sleep_for(3);
  run_transfer(e, host0, host1, "3", 1000 * 1000 * 1000);
}

static void show_link_load(const std::string& link_name, const sg4::Link* link)
{
  XBT_INFO("%s link load (cum, avg, min, max): (%g, %g, %g, %g)", link_name.c_str(), sg_link_get_cum_load(link),
           sg_link_get_avg_load(link), sg_link_get_min_instantaneous_load(link),
           sg_link_get_max_instantaneous_load(link));
}

static void monitor()
{
  const auto* link_backbone = sg4::Link::by_name("cluster0_backbone");
  const auto* link_host0    = sg4::Link::by_name("cluster0_link_0_UP");
  const auto* link_host1    = sg4::Link::by_name("cluster0_link_1_DOWN");

  XBT_INFO("Tracking desired links");
  sg_link_load_track(link_backbone);
  sg_link_load_track(link_host0);
  sg_link_load_track(link_host1);

  show_link_load("Backbone", link_backbone);
  while (sg4::Engine::get_clock() < 5) {
    sg4::this_actor::sleep_for(1);
    show_link_load("Backbone", link_backbone);
  }

  XBT_INFO("Untracking the backbone link");
  sg_link_load_untrack(link_backbone);

  show_link_load("Host0_UP", link_host0);
  show_link_load("Host1_UP", link_host1);

  XBT_INFO("Now resetting and probing host links each second.");

  while (sg4::Engine::get_clock() < 29) {
    sg_link_load_reset(link_host0);
    sg_link_load_reset(link_host1);

    sg4::this_actor::sleep_for(1);

    show_link_load("Host0_UP", link_host0);
    show_link_load("Host1_UP", link_host1);
  }
}

int main(int argc, char* argv[])
{
  sg4::Engine e(&argc, argv);
  sg_link_load_plugin_init();

  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../platforms/energy_platform.xml\n", argv[0], argv[0]);
  e.load_platform(argv[1]);

  e.add_actor("load_test", e.host_by_name("node-42.simgrid.org"), execute_load_test);
  e.add_actor("monitor", e.host_by_name("node-51.simgrid.org"), monitor);

  e.run();

  XBT_INFO("Total simulation time: %.2f", sg4::Engine::get_clock());

  return 0;
}