File: issue105.cpp

package info (click to toggle)
simgrid 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 39,192 kB
  • sloc: cpp: 124,913; ansic: 66,744; python: 8,560; java: 6,773; fortran: 6,079; f90: 5,123; xml: 4,587; sh: 2,194; perl: 1,436; makefile: 111; lisp: 49; javascript: 7; sed: 6
file content (89 lines) | stat: -rw-r--r-- 3,339 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
/* Copyright (c) 2013-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. */

/**
 * Test for issue105: https://framagit.org/simgrid/simgrid/-/issues/105
 */

#include <simgrid/kernel/ProfileBuilder.hpp>
#include <simgrid/s4u.hpp>
#include <xbt/log.h>
namespace sg4 = simgrid::s4u;

XBT_LOG_NEW_DEFAULT_CATEGORY(issue105, "Issue105");
static void load_generator(sg4::Mailbox* mailbox)
{
  sg4::ActivitySet comms;

  // Send the task messages
  for (int i = 0; i < 100; i++) {
    auto* payload     = new int(i);
    sg4::CommPtr comm = mailbox->put_async(payload, 1024);
    comms.push(comm);
    sg4::this_actor::sleep_for(1.0);
  }

  // send shutdown messages
  auto* payload     = new int(-1);
  sg4::CommPtr comm = mailbox->put_async(payload, 1024);
  XBT_INFO("Sent shutdown");
  comms.push(comm);

  // Wait for all messages to be consumed before ending the simulation
  comms.wait_all();
  XBT_INFO("Load generator finished");
}

static void receiver(sg4::Mailbox* mailbox)
{
  bool shutdown = false;
  while (not shutdown) {
    auto msg = mailbox->get_unique<int>();
    if (*msg >= 0) {
      XBT_INFO("Started Task: %d", *msg);
      sg4::this_actor::execute(1e9);
    } else {
      shutdown = true;
    }
  }
  XBT_INFO("Receiver finished");
}

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

  sg4::NetZone* world = e.get_netzone_root();
  sg4::Host* hostGl01 = world->add_host("host-gl01", "98Mf")->seal();
  sg4::Host* hostSa01 = world->add_host("host-sa01", "98Mf")->seal();

  // create latency and bandwidth profiles
  auto* linkSaLatencyProfile   = simgrid::kernel::profile::ProfileBuilder::from_string("link-sa-latency-profile",
                                                                                     "0 0.100\n"
                                                                                     "0.102 0.00002\n",
                                                                                     60);
  auto* linkSaBandwidthProfile = simgrid::kernel::profile::ProfileBuilder::from_string("link-sa-bandwidth-profile",
                                                                                       "0 42000000\n"
                                                                                       "1 200\n"
                                                                                       "100 42000000\n",
                                                                                       150);
  const sg4::Link* linkSa      = world->add_link("link-front-sa", "42MBps")
                                ->set_latency("20ms")
                                ->set_latency_profile(linkSaLatencyProfile)
                                ->set_bandwidth_profile(linkSaBandwidthProfile)
                                ->seal();

  world->add_route(hostGl01, hostSa01, {{linkSa, sg4::LinkInRoute::Direction::NONE}}, true);
  world->seal();

  sg4::Mailbox* mb1 = e.mailbox_by_name_or_create("Mailbox 1");
  hostGl01->add_actor("load-generator", load_generator, mb1);
  hostSa01->add_actor("cluster-node-sa01", receiver, mb1);

  e.run();

  XBT_INFO("Total simulation time: %.3f", e.get_clock());
  return 0;
}