Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
aa9089e724d5192f6fccbec8ab9e8736f517c376
[simgrid.git] / examples / platforms / supernode.cpp
1 /* Copyright (c) 2006-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <simgrid/s4u.hpp>
7 namespace sg4 = simgrid::s4u;
8
9 constexpr double BW_CPU  = 1e12;
10 constexpr double LAT_CPU = 0;
11
12 constexpr double BW_NODE  = 1e11;
13 constexpr double LAT_NODE = 1e-8;
14
15 constexpr double BW_NETWORK  = 1.25e10;
16 constexpr double LAT_NETWORK = 1e-7;
17
18 static std::string int_string(int n)
19 {
20   return simgrid::xbt::string_printf("%02d", n);
21 }
22
23 /**
24  *
25  * This function creates one node made of nb_cpu CPUs.
26  */
27 static sg4::NetZone* create_node(const sg4::NetZone* root, const std::string& node_name, const int nb_cpu)
28 {
29   auto* node = sg4::create_star_zone(node_name);
30   node->set_parent(root);
31
32   /* create all hosts and connect them to outside world */
33   for (int i = 0; i < nb_cpu; i++) {
34     const auto& cpuname  = node_name + "_cpu-" + int_string(i);
35     const auto& linkname = "link_" + cpuname;
36
37     const sg4::Host* host = node->create_host(cpuname, 1e9);
38     const sg4::Link* l    = node->create_split_duplex_link(linkname, BW_CPU)->set_latency(LAT_CPU)->seal();
39
40     node->add_route(host->get_netpoint(), nullptr, nullptr, nullptr, {{l, sg4::LinkInRoute::Direction::UP}}, true);
41   }
42
43   return node;
44 }
45
46 /**
47  *
48  * This function creates one super-node made of nb_nodes nodes with nb_cpu CPUs.
49  */
50 static sg4::NetZone* create_supernode(const sg4::NetZone* root, const std::string& supernode_name, const int nb_nodes,
51                                       const int nb_cpu)
52 {
53   auto* supernode = sg4::create_star_zone(supernode_name);
54   supernode->set_parent(root);
55
56   /* create all nodes and connect them to outside world */
57   for (int i = 0; i < nb_nodes; i++) {
58     const auto& node_name = supernode_name + "_node-" + int_string(i);
59     const auto& linkname  = "link_" + node_name;
60
61     sg4::NetZone* node = create_node(supernode, node_name, nb_cpu);
62     const auto router  = node->create_router("router_" + node_name);
63     node->seal();
64
65     const sg4::Link* l = supernode->create_split_duplex_link(linkname, BW_NODE)->set_latency(LAT_NODE)->seal();
66     supernode->add_route(node->get_netpoint(), nullptr, router, nullptr, {{l, sg4::LinkInRoute::Direction::UP}}, true);
67   }
68   return supernode;
69 }
70
71 /**
72  *
73  * This function creates one cluster of nb_supernodes super-nodes made of nb_nodes nodes with nb_cpu CPUs.
74  */
75 static sg4::NetZone* create_cluster(const std::string& cluster_name, const int nb_supernodes, const int nb_nodes,
76                                     const int nb_cpu)
77 {
78   auto* cluster = sg4::create_star_zone(cluster_name);
79
80   /* create all supernodes and connect them to outside world */
81   for (int i = 0; i < nb_supernodes; i++) {
82     const auto& supernode_name = cluster_name + "_supernode-" + int_string(i);
83     const auto& linkname       = "link_" + supernode_name;
84
85     sg4::NetZone* supernode = create_supernode(cluster, supernode_name, nb_nodes, nb_cpu);
86     const auto router       = supernode->create_router("router_" + supernode_name);
87     supernode->seal();
88
89     const sg4::Link* l = cluster->create_split_duplex_link(linkname, BW_NETWORK)->set_latency(LAT_NETWORK)->seal();
90     cluster->add_route(supernode->get_netpoint(), nullptr, router, nullptr, {{l, sg4::LinkInRoute::Direction::UP}},
91                        true);
92   }
93   return cluster;
94 }
95
96 extern "C" void load_platform(const sg4::Engine& e);
97 void load_platform(const sg4::Engine&)
98 {
99   create_cluster("cluster", 4, 6, 2)->seal();
100 }