Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7d5acb7df78b444e9054d8fae1f19523b57a05ef
[simgrid.git] / teshsuite / models / ptask_L07 / ptask_L07.cpp
1 /* Copyright g(c) 2019-2021. 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 #include "xbt/asserts.h"
8 #include "xbt/log.h"
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(ptask_L07_tes, "[usage] ptask_LO7 <platform-file>");
11
12 namespace sg4 = simgrid::s4u;
13
14 /* We need a separate actor so that it can sleep after each test */
15 static void main_dispatcher()
16 {
17   const sg4::Engine* e = sg4::Engine::get_instance();
18   double start_time;
19   double end_time;
20   std::vector<sg4::Host*> hosts = e->get_all_hosts();
21
22   XBT_INFO("TEST: Create and run a sequential execution.");
23   XBT_INFO("------------------------------------------------------------");
24   XBT_INFO("Have to compute 1 flop on a 1 flop/s host.");
25   XBT_INFO("Should be done in exactly one second.");
26   start_time = sg4::Engine::get_clock();
27   sg4::Exec::init()->set_flops_amount(1)->set_host(hosts[0])->wait();
28   end_time = sg4::Engine::get_clock();
29   XBT_INFO("Actual result: computing 1 flop at 1 flop/s takes %.2f seconds.", end_time - start_time);
30   XBT_INFO("\n");
31
32   sg4::this_actor::sleep_for(5);
33
34   XBT_INFO("TEST: Create and run two concurrent sequential executions.");
35   XBT_INFO("------------------------------------------------------------");
36   XBT_INFO("Have to compute 2 x 1 flop on a 1 flop/s host.");
37   XBT_INFO("Should be done in exactly 2 seconds because of sharing.");
38   start_time      = sg4::Engine::get_clock();
39   sg4::ExecPtr e1 = sg4::Exec::init()->set_flops_amount(1)->set_host(hosts[0])->start();
40   sg4::ExecPtr e2 = sg4::Exec::init()->set_flops_amount(1)->set_host(hosts[0])->start();
41   e1->wait();
42   e2->wait();
43   end_time = sg4::Engine::get_clock();
44   XBT_INFO("Actual result: computing 2x1 flop at 1 flop/s takes %.2f seconds.", end_time - start_time);
45   XBT_INFO("\n");
46
47   sg4::this_actor::sleep_for(5);
48
49   XBT_INFO("TEST: Create and run a parallel execution on 2 homogeneous hosts.");
50   XBT_INFO("------------------------------------------------------------");
51   XBT_INFO("Have to compute 2 flops across two hosts running at 1 flop/s.");
52   XBT_INFO("Should be done in exactly one second.");
53   start_time = sg4::Engine::get_clock();
54   sg4::Exec::init()->set_flops_amounts(std::vector<double>({1.0, 1.0}))
55                    ->set_hosts(std::vector<sg4::Host*>({hosts[0], hosts[1]}))
56                    ->wait();
57   end_time = sg4::Engine::get_clock();
58   XBT_INFO("Actual result: computing 2 flops on 2 hosts at 1 flop/s takes %.2f seconds.", end_time - start_time);
59   XBT_INFO("\n");
60
61   sg4::this_actor::sleep_for(5);
62
63   XBT_INFO("TEST: Create and run a parallel execution on 2 heterogeneous hosts.");
64   XBT_INFO("------------------------------------------------------------");
65   XBT_INFO("Have to compute 2 flops across two hosts, one running at 1 flop/s and one at 2 flop/s.");
66   XBT_INFO("Should be done in exactly one second.");
67   start_time = sg4::Engine::get_clock();
68   sg4::Exec::init()->set_flops_amounts(std::vector<double>({1.0, 1.0}))
69                    ->set_hosts(std::vector<sg4::Host*>({hosts[0], hosts[5]}))
70                    ->wait();
71   end_time = sg4::Engine::get_clock();
72   XBT_INFO("Actual result: computing 2 flops on 2 heterogeneous hosts takes %.2f seconds.", end_time - start_time);
73   XBT_INFO("\n");
74
75   sg4::this_actor::sleep_for(5);
76
77   XBT_INFO("TEST: Latency test between hosts connected by a shared link.");
78   XBT_INFO("------------------------------------------------------------");
79   XBT_INFO("Have to send 1B from one host to another at 1Bps with a latency of 500ms.");
80   XBT_INFO("Should be done in 1.5 seconds (500ms latency + 1s transfert).");
81   start_time = sg4::Engine::get_clock();
82   sg4::Comm::sendto_async(hosts[0], hosts[4], 1.0)->wait();
83   end_time = sg4::Engine::get_clock();
84   XBT_INFO("Actual result: sending 1 byte on a shared link at 1Bps + 500ms takes %.2f seconds.", end_time - start_time);
85   XBT_INFO("\n");
86
87   sg4::this_actor::sleep_for(5);
88
89   XBT_INFO("TEST: Latency test between hosts connected by a fatpipe link.");
90   XBT_INFO("------------------------------------------------------------");
91   XBT_INFO("Have to send 1B from one host to another at 1Bps with a latency of 500ms.");
92   XBT_INFO("Should be done in 1.5 seconds (500ms latency + 1s transfert).");
93   start_time = sg4::Engine::get_clock();
94   sg4::Comm::sendto_async(hosts[0], hosts[5], 1.0)->wait();
95   end_time = sg4::Engine::get_clock();
96   XBT_INFO("Actual result: sending 1 byte on a fatpipe link at 1Bps + 500ms takes %.2f seconds.", end_time - start_time);
97   XBT_INFO("\n");
98
99   sg4::this_actor::sleep_for(5);
100
101   XBT_INFO("TEST: Latency test between hosts connected by a 3-link route.");
102   XBT_INFO("------------------------------------------------------------");
103   XBT_INFO("Have to send 1B from one host to another at 1Bps with a latency of 2 x 500ms + 1s.");
104   XBT_INFO("Should be done in 3 seconds (2 x 500ms + 1s latency + 1s transfert).");
105   start_time = sg4::Engine::get_clock();
106   sg4::Comm::sendto_async(hosts[0], hosts[1], 1.0)->wait();
107   end_time = sg4::Engine::get_clock();
108   XBT_INFO("Actual result: sending 1 byte on a 3-link route at 1Bps + 2,500ms takes %.2f seconds.", end_time - start_time);
109   XBT_INFO("\n");
110
111   sg4::this_actor::sleep_for(5);
112
113   XBT_INFO("TEST: Latency test between hosts connected by a link with large latency.");
114   XBT_INFO("------------------------------------------------------------");
115   XBT_INFO("Have to send 1B from one host to another on a link at 2Bps with a latency of 2 x 1024^2s.");
116   XBT_INFO("This latency is half the default TCP window size (4MiB). This limits the bandwidth to 1B");
117   XBT_INFO("Should be done in 2 x 1024^2s + 1 seconds (large latency + 1s transfert).");
118   start_time = sg4::Engine::get_clock();
119   sg4::Comm::sendto_async(hosts[0], hosts[6], 1.0)->wait();
120   end_time = sg4::Engine::get_clock();
121   XBT_INFO("Actual result: sending 1 byte on a large latency link takes %.2f seconds.", end_time - start_time);
122   XBT_INFO("\n");
123
124   sg4::this_actor::sleep_for(5);
125
126    XBT_INFO("TEST: Latency test between hosts connected by a shared link with 2 comms in same direction.");
127    XBT_INFO("------------------------------------------------------------");
128    XBT_INFO("Have to send 2 x 1B from one host to another at 1Bps with a latency of 500ms.");
129    XBT_INFO("Should be done in 2.5 seconds (500ms latency + 2s transfert).");
130    start_time      = sg4::Engine::get_clock();
131    sg4::CommPtr c1 = sg4::Comm::sendto_async(hosts[0], hosts[4], 1.0);
132    sg4::CommPtr c2 = sg4::Comm::sendto_async(hosts[0], hosts[4], 1.0);
133    c1->wait();
134    c2->wait();
135    end_time = sg4::Engine::get_clock();
136    XBT_INFO("Actual result: sending 2x1 bytes on a shared link at 1Bps + 500ms takes %.2f seconds.", end_time - start_time);
137    XBT_INFO("\n");
138
139    sg4::this_actor::sleep_for(5);
140
141    XBT_INFO("TEST: Latency test between hosts connected by a fatpipe link with 2 comms in same direction.");
142    XBT_INFO("------------------------------------------------------------");
143    XBT_INFO("Have to send 2 x 1B from one host to another at 1Bps with a latency of 500ms.");
144    XBT_INFO("Should be done in 1.5 seconds (500ms latency + 1s transfert).");
145    start_time = sg4::Engine::get_clock();
146    c1 = sg4::Comm::sendto_async(hosts[0], hosts[5], 1.0);
147    c2 = sg4::Comm::sendto_async(hosts[0], hosts[5], 1.0);
148    c1->wait();
149    c2->wait();
150    end_time = sg4::Engine::get_clock();
151    XBT_INFO("Actual result: sending 2x1 bytes on a fatpipe link at 1Bps + 500ms takes %.2f seconds.", end_time - start_time);
152    XBT_INFO("\n");
153
154    sg4::this_actor::sleep_for(5);
155
156    XBT_INFO("TEST: Latency test between hosts connected by a 3-link route with 2 comms in same direction.");
157    XBT_INFO("------------------------------------------------------------");
158    XBT_INFO("Have to send 2 x 1B from one host to another at 1Bps with a latency of 2 x 500ms + 1s.");
159    XBT_INFO("Should be done in 4 seconds (2 x 500ms + 1s latency + 2s transfert).");
160    start_time = sg4::Engine::get_clock();
161    c1 = sg4::Comm::sendto_async(hosts[0], hosts[1], 1.0);
162    c2 = sg4::Comm::sendto_async(hosts[0], hosts[1], 1.0);
163    c1->wait();
164    c2->wait();
165    end_time = sg4::Engine::get_clock();
166    XBT_INFO("Actual result: sending 2x1 bytes on a 3-link route at 1Bps + 2,500ms takes %.2f seconds.",
167             end_time - start_time);
168    XBT_INFO("\n");
169
170    sg4::this_actor::sleep_for(5);
171
172    XBT_INFO("TEST: Latency test between hosts connected by a shared link with 2 comms in opposite direction.");
173    XBT_INFO("------------------------------------------------------------");
174    XBT_INFO("Have to send 1B between two hosts in each direction at 1Bps with a latency of 500ms.");
175    XBT_INFO("Should be done in 2.5 seconds (500ms latency + 2s transfert).");
176    start_time = sg4::Engine::get_clock();
177    c1 = sg4::Comm::sendto_async(hosts[0], hosts[4], 1.0);
178    c2 = sg4::Comm::sendto_async(hosts[4], hosts[0], 1.0);
179    c1->wait();
180    c2->wait();
181    end_time = sg4::Engine::get_clock();
182    XBT_INFO("Actual result: sending 1 byte in both directions on a shared link at 1Bps + 500ms takes %.2f seconds.",
183             end_time - start_time);
184    XBT_INFO("\n");
185
186    sg4::this_actor::sleep_for(5);
187
188    XBT_INFO("TEST: Latency test between hosts connected by a fatpipe link with 2 comms in opposite direction.");
189    XBT_INFO("------------------------------------------------------------");
190    XBT_INFO("Have to send 1B between two hosts in each direction at 1Bps with a latency of 500ms.");
191    XBT_INFO("Should be done in 1.5 seconds (500ms latency + 1s transfert).");
192    start_time = sg4::Engine::get_clock();
193    c1 = sg4::Comm::sendto_async(hosts[0], hosts[5], 1.0);
194    c2 = sg4::Comm::sendto_async(hosts[5], hosts[0], 1.0);
195    c1->wait();
196    c2->wait();
197    end_time = sg4::Engine::get_clock();
198    XBT_INFO("Actual result: sending 1 byte in both directions on a fatpipe link at 1Bps + 500ms takes %.2f seconds.",
199             end_time - start_time);
200    XBT_INFO("\n");
201
202    sg4::this_actor::sleep_for(5);
203
204    XBT_INFO("TEST: Latency test between hosts connected by a 3-link route with 2 comms in opposite direction.");
205    XBT_INFO("------------------------------------------------------------");
206    XBT_INFO("Have to send 1B between two hosts in each direction at 1Bps with a latency of 2 x 500ms + 1s.");
207    XBT_INFO("Should be done in 4 seconds (2 x 500ms + 1s latency + 2s transfert).");
208    start_time = sg4::Engine::get_clock();
209    c1 = sg4::Comm::sendto_async(hosts[0], hosts[1], 1.0);
210    c2 = sg4::Comm::sendto_async(hosts[1], hosts[0], 1.0);
211    c1->wait();
212    c2->wait();
213    end_time = sg4::Engine::get_clock();
214    XBT_INFO("Actual result: sending 1 byte in both directions on a 3-link route at 1Bps + 2,500ms takes %.2f seconds.",
215              end_time - start_time);
216    XBT_INFO("\n");
217
218    sg4::this_actor::sleep_for(5);
219
220    XBT_INFO("TEST: 4-host parallel communication with independent transfers.");
221    XBT_INFO("------------------------------------------------------------");
222    XBT_INFO("'cpu0' sends 1B to 'cpu1' and 'cpu2' sends 1B to 'cpu3'. The only shared link is the fatpipe switch.");
223    XBT_INFO("Should be done in 3 seconds (2 x 500ms + 1s latency + 1s transfert).");
224    start_time = sg4::Engine::get_clock();
225    sg4::Exec::init()->set_bytes_amounts(std::vector<double>({0.0, 1.0, 0.0, 0.0,
226                                                              0.0, 0.0, 0.0, 0.0,
227                                                              0.0, 0.0, 0.0, 1.0,
228                                                              0.0, 0.0, 0.0, 0.0 }))
229                     ->set_hosts(std::vector<sg4::Host*>({hosts[0], hosts[1], hosts[2], hosts[3]}))
230                     ->wait();
231    end_time = sg4::Engine::get_clock();
232    XBT_INFO("Actual result: sending 2 x 1 byte in a parallel communication without interference takes %.2f seconds.",
233              end_time - start_time);
234    XBT_INFO("\n");
235
236    sg4::this_actor::sleep_for(5);
237
238    XBT_INFO("TEST: 4-host parallel communication with scatter pattern.");
239    XBT_INFO("------------------------------------------------------------");
240    XBT_INFO("'cpu0' sends 1B to 'cpu1', 2B to 'cpu2' and 3B to 'cpu3'.");
241    XBT_INFO("Should be done in 8 seconds: 2 x 500ms + 1s of initial latency and :");
242    XBT_INFO(" - For 3 seconds, three flows share a link to transfer 3 x 1B. 'cpu1' received its payload");
243    XBT_INFO(" - For 2 seconds, two lows share a link to transfer 1 x 1B. 'cpu2' received is payload");
244    XBT_INFO(" - For 1 second, one flow has the full bandwidth to transfer 1B. 'cpu3' received is payload");
245
246    start_time = sg4::Engine::get_clock();
247    sg4::Exec::init()->set_bytes_amounts(std::vector<double>({0.0, 1.0, 2.0, 3.0,
248                                                              0.0, 0.0, 0.0, 0.0,
249                                                              0.0, 0.0, 0.0, 0.0,
250                                                              0.0, 0.0, 0.0, 0.0 }))
251                     ->set_hosts(std::vector<sg4::Host*>({hosts[0], hosts[1], hosts[2], hosts[3]}))
252                     ->wait();
253    end_time = sg4::Engine::get_clock();
254    XBT_INFO("Actual result: scattering an increasing number of bytes to 3 hosts takes %.2f seconds.",
255              end_time - start_time);
256    XBT_INFO("\n");
257
258    sg4::this_actor::sleep_for(5);
259
260    XBT_INFO("TEST: 4-host parallel communication with all-to-all pattern.");
261    XBT_INFO("------------------------------------------------------------");
262    XBT_INFO("Each host sends 1B to every other hosts.");
263    XBT_INFO("Should be done in 8 seconds: 2 x 500ms + 1s of initial latency and 6 seconds for transfer");
264    XBT_INFO("Each SHARED link is traversed by 6 flows (3 in and 3 out). ");
265    XBT_INFO("Each 1B transfer thus takes 6 seconds on a 1Bps link");
266
267    start_time = sg4::Engine::get_clock();
268    sg4::Exec::init()->set_bytes_amounts(std::vector<double>({0.0, 1.0, 1.0, 1.0,
269                                                              1.0, 0.0, 1.0, 1.0,
270                                                              1.0, 1.0, 0.0, 1.0,
271                                                              1.0, 1.0, 1.0, 0.0 }))
272                     ->set_hosts(std::vector<sg4::Host*>({hosts[0], hosts[1], hosts[2], hosts[3]}))
273                     ->wait();
274    end_time = sg4::Engine::get_clock();
275    XBT_INFO("Actual result: 1-byte all-too-all in a parallel communication takes %.2f seconds.",
276              end_time - start_time);
277    XBT_INFO("\n");
278
279    sg4::this_actor::sleep_for(5);
280
281    XBT_INFO("TEST: Two concurrent communications, 1 large and 1 small.");
282    XBT_INFO("------------------------------------------------------------");
283    XBT_INFO("A host sends two messages of 100MB and 1B to the other host.");
284    XBT_INFO("Should be done in 0.8001 seconds: 1e8/1.25e8 for transfer + 1e-4 of latency");
285    XBT_INFO("The small communication has a negligible impact on the large one.");
286    XBT_INFO("This corresponds to paying latency once and having the full bandwidth for the large communication.");
287
288    start_time = sg4::Engine::get_clock();
289    c1 = sg4::Comm::sendto_async(hosts[0], hosts[7], 1e8);
290    c2 = sg4::Comm::sendto_async(hosts[0], hosts[7], 1.0);
291    c1->wait();
292    c2->wait();
293    end_time = sg4::Engine::get_clock();
294    XBT_INFO("Actual result: 1 small and 1 large concurrent communications take %.4f seconds.",
295              end_time - start_time);
296    XBT_INFO("\n");
297 }
298
299 int main(int argc, char** argv)
300 {
301   sg4::Engine engine(&argc, argv);
302   engine.load_platform(argv[1]);
303   sg4::Actor::create("dispatcher", sg4::Host::by_name("cpu0"), main_dispatcher);
304   engine.run();
305
306   return 0;
307 }
308