Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
save some hidden calls to Engine::get_instance
[simgrid.git] / teshsuite / models / ptask_L07_usage / ptask_L07_usage.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_usage, "[usage] ptask_L07_usage <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 = e->get_clock();
27   sg4::Exec::init()->set_flops_amount(1)->set_host(hosts[0])->wait();
28   end_time = e->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      = e->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 = e->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 = e->get_clock();
54   sg4::Exec::init()
55       ->set_flops_amounts(std::vector<double>({1.0, 1.0}))
56       ->set_hosts(std::vector<sg4::Host*>({hosts[0], hosts[1]}))
57       ->wait();
58   end_time = e->get_clock();
59   XBT_INFO("Actual result: computing 2 flops on 2 hosts at 1 flop/s takes %.2f seconds.", end_time - start_time);
60   XBT_INFO("\n");
61
62   sg4::this_actor::sleep_for(5);
63
64   XBT_INFO("TEST: Create and run a parallel execution on 2 heterogeneous hosts.");
65   XBT_INFO("------------------------------------------------------------");
66   XBT_INFO("Have to compute 2 flops across two hosts, one running at 1 flop/s and one at 2 flop/s.");
67   XBT_INFO("Should be done in exactly one second.");
68   start_time = e->get_clock();
69   sg4::Exec::init()
70       ->set_flops_amounts(std::vector<double>({1.0, 1.0}))
71       ->set_hosts(std::vector<sg4::Host*>({hosts[0], hosts[5]}))
72       ->wait();
73   end_time = e->get_clock();
74   XBT_INFO("Actual result: computing 2 flops on 2 heterogeneous hosts takes %.2f seconds.", end_time - start_time);
75   XBT_INFO("\n");
76
77   sg4::this_actor::sleep_for(5);
78
79   XBT_INFO("TEST: Latency test between hosts connected by a shared link.");
80   XBT_INFO("------------------------------------------------------------");
81   XBT_INFO("Have to send 1B from one host to another at 1Bps with a latency of 500ms.");
82   XBT_INFO("Should be done in 1.5 seconds (500ms latency + 1s transfert).");
83   start_time = e->get_clock();
84   sg4::Comm::sendto_async(hosts[0], hosts[4], 1.0)->wait();
85   end_time = e->get_clock();
86   XBT_INFO("Actual result: sending 1 byte on a shared link at 1Bps + 500ms takes %.2f seconds.", end_time - start_time);
87   XBT_INFO("\n");
88
89   sg4::this_actor::sleep_for(5);
90
91   XBT_INFO("TEST: Latency test between hosts connected by a fatpipe link.");
92   XBT_INFO("------------------------------------------------------------");
93   XBT_INFO("Have to send 1B from one host to another at 1Bps with a latency of 500ms.");
94   XBT_INFO("Should be done in 1.5 seconds (500ms latency + 1s transfert).");
95   start_time = e->get_clock();
96   sg4::Comm::sendto_async(hosts[0], hosts[5], 1.0)->wait();
97   end_time = e->get_clock();
98   XBT_INFO("Actual result: sending 1 byte on a fatpipe link at 1Bps + 500ms takes %.2f seconds.",
99            end_time - start_time);
100   XBT_INFO("\n");
101
102   sg4::this_actor::sleep_for(5);
103
104   XBT_INFO("TEST: Latency test between hosts connected by a 3-link route.");
105   XBT_INFO("------------------------------------------------------------");
106   XBT_INFO("Have to send 1B from one host to another at 1Bps with a latency of 2 x 500ms + 1s.");
107   XBT_INFO("Should be done in 3 seconds (2 x 500ms + 1s latency + 1s transfert).");
108   start_time = e->get_clock();
109   sg4::Comm::sendto_async(hosts[0], hosts[1], 1.0)->wait();
110   end_time = e->get_clock();
111   XBT_INFO("Actual result: sending 1 byte on a 3-link route at 1Bps + 2,500ms takes %.2f seconds.",
112            end_time - start_time);
113   XBT_INFO("\n");
114
115   sg4::this_actor::sleep_for(5);
116
117   XBT_INFO("TEST: Latency test between hosts connected by a link with large latency.");
118   XBT_INFO("------------------------------------------------------------");
119   XBT_INFO("Have to send 1B from one host to another on a link at 2Bps with a latency of 2 x 1024^2s.");
120   XBT_INFO("This latency is half the default TCP window size (4MiB). This limits the bandwidth to 1B");
121   XBT_INFO("Should be done in 2 x 1024^2s + 1 seconds (large latency + 1s transfert).");
122   start_time = e->get_clock();
123   sg4::Comm::sendto_async(hosts[0], hosts[6], 1.0)->wait();
124   end_time = e->get_clock();
125   XBT_INFO("Actual result: sending 1 byte on a large latency link takes %.2f seconds.", end_time - start_time);
126   XBT_INFO("\n");
127
128   sg4::this_actor::sleep_for(5);
129
130   XBT_INFO("TEST: Latency test between hosts connected by a shared link with 2 comms in same direction.");
131   XBT_INFO("------------------------------------------------------------");
132   XBT_INFO("Have to send 2 x 1B from one host to another at 1Bps with a latency of 500ms.");
133   XBT_INFO("Should be done in 2.5 seconds (500ms latency + 2s transfert).");
134   start_time      = e->get_clock();
135   sg4::CommPtr c1 = sg4::Comm::sendto_async(hosts[0], hosts[4], 1.0);
136   sg4::CommPtr c2 = sg4::Comm::sendto_async(hosts[0], hosts[4], 1.0);
137   c1->wait();
138   c2->wait();
139   end_time = e->get_clock();
140   XBT_INFO("Actual result: sending 2x1 bytes on a shared link at 1Bps + 500ms takes %.2f seconds.",
141            end_time - start_time);
142   XBT_INFO("\n");
143
144   sg4::this_actor::sleep_for(5);
145
146   XBT_INFO("TEST: Latency test between hosts connected by a fatpipe link with 2 comms in same direction.");
147   XBT_INFO("------------------------------------------------------------");
148   XBT_INFO("Have to send 2 x 1B from one host to another at 1Bps with a latency of 500ms.");
149   XBT_INFO("Should be done in 1.5 seconds (500ms latency + 1s transfert).");
150   start_time = e->get_clock();
151   c1         = sg4::Comm::sendto_async(hosts[0], hosts[5], 1.0);
152   c2         = sg4::Comm::sendto_async(hosts[0], hosts[5], 1.0);
153   c1->wait();
154   c2->wait();
155   end_time = e->get_clock();
156   XBT_INFO("Actual result: sending 2x1 bytes on a fatpipe link at 1Bps + 500ms takes %.2f seconds.",
157            end_time - start_time);
158   XBT_INFO("\n");
159
160   sg4::this_actor::sleep_for(5);
161
162   XBT_INFO("TEST: Latency test between hosts connected by a 3-link route with 2 comms in same direction.");
163   XBT_INFO("------------------------------------------------------------");
164   XBT_INFO("Have to send 2 x 1B from one host to another at 1Bps with a latency of 2 x 500ms + 1s.");
165   XBT_INFO("Should be done in 4 seconds (2 x 500ms + 1s latency + 2s transfert).");
166   start_time = e->get_clock();
167   c1         = sg4::Comm::sendto_async(hosts[0], hosts[1], 1.0);
168   c2         = sg4::Comm::sendto_async(hosts[0], hosts[1], 1.0);
169   c1->wait();
170   c2->wait();
171   end_time = e->get_clock();
172   XBT_INFO("Actual result: sending 2x1 bytes on a 3-link route at 1Bps + 2,500ms takes %.2f seconds.",
173            end_time - start_time);
174   XBT_INFO("\n");
175
176   sg4::this_actor::sleep_for(5);
177
178   XBT_INFO("TEST: Latency test between hosts connected by a shared link with 2 comms in opposite direction.");
179   XBT_INFO("------------------------------------------------------------");
180   XBT_INFO("Have to send 1B between two hosts in each direction at 1Bps with a latency of 500ms.");
181   XBT_INFO("Should be done in 2.5 seconds (500ms latency + 2s transfert).");
182   start_time = e->get_clock();
183   c1         = sg4::Comm::sendto_async(hosts[0], hosts[4], 1.0);
184   c2         = sg4::Comm::sendto_async(hosts[4], hosts[0], 1.0);
185   c1->wait();
186   c2->wait();
187   end_time = e->get_clock();
188   XBT_INFO("Actual result: sending 1 byte in both directions on a shared link at 1Bps + 500ms takes %.2f seconds.",
189            end_time - start_time);
190   XBT_INFO("\n");
191
192   sg4::this_actor::sleep_for(5);
193
194   XBT_INFO("TEST: Latency test between hosts connected by a fatpipe link with 2 comms in opposite direction.");
195   XBT_INFO("------------------------------------------------------------");
196   XBT_INFO("Have to send 1B between two hosts in each direction at 1Bps with a latency of 500ms.");
197   XBT_INFO("Should be done in 1.5 seconds (500ms latency + 1s transfert).");
198   start_time = e->get_clock();
199   c1         = sg4::Comm::sendto_async(hosts[0], hosts[5], 1.0);
200   c2         = sg4::Comm::sendto_async(hosts[5], hosts[0], 1.0);
201   c1->wait();
202   c2->wait();
203   end_time = e->get_clock();
204   XBT_INFO("Actual result: sending 1 byte in both directions on a fatpipe link at 1Bps + 500ms takes %.2f seconds.",
205            end_time - start_time);
206   XBT_INFO("\n");
207
208   sg4::this_actor::sleep_for(5);
209
210   XBT_INFO("TEST: Latency test between hosts connected by a 3-link route with 2 comms in opposite direction.");
211   XBT_INFO("------------------------------------------------------------");
212   XBT_INFO("Have to send 1B between two hosts in each direction at 1Bps with a latency of 2 x 500ms + 1s.");
213   XBT_INFO("Should be done in 4 seconds (2 x 500ms + 1s latency + 2s transfert).");
214   start_time = e->get_clock();
215   c1         = sg4::Comm::sendto_async(hosts[0], hosts[1], 1.0);
216   c2         = sg4::Comm::sendto_async(hosts[1], hosts[0], 1.0);
217   c1->wait();
218   c2->wait();
219   end_time = e->get_clock();
220   XBT_INFO("Actual result: sending 1 byte in both directions on a 3-link route at 1Bps + 2,500ms takes %.2f seconds.",
221            end_time - start_time);
222   XBT_INFO("\n");
223
224   sg4::this_actor::sleep_for(5);
225
226   XBT_INFO("TEST: 4-host parallel communication with independent transfers.");
227   XBT_INFO("------------------------------------------------------------");
228   XBT_INFO("'cpu0' sends 1B to 'cpu1' and 'cpu2' sends 1B to 'cpu3'. The only shared link is the fatpipe switch.");
229   XBT_INFO("Should be done in 3 seconds (2 x 500ms + 1s latency + 1s transfert).");
230   start_time = e->get_clock();
231   sg4::Exec::init()
232       ->set_bytes_amounts(std::vector<double>({0.0, 1.0, 0.0, 0.0,
233                                                0.0, 0.0, 0.0, 0.0,
234                                                0.0, 0.0, 0.0, 1.0,
235                                                0.0, 0.0, 0.0, 0.0 }))
236       ->set_hosts(std::vector<sg4::Host*>({hosts[0], hosts[1], hosts[2], hosts[3]}))
237       ->wait();
238   end_time = e->get_clock();
239   XBT_INFO("Actual result: sending 2 x 1 byte in a parallel communication without interference takes %.2f seconds.",
240            end_time - start_time);
241   XBT_INFO("\n");
242
243   sg4::this_actor::sleep_for(5);
244
245   XBT_INFO("TEST: 4-host parallel communication with scatter pattern.");
246   XBT_INFO("------------------------------------------------------------");
247   XBT_INFO("'cpu0' sends 1B to 'cpu1', 2B to 'cpu2' and 3B to 'cpu3'.");
248   XBT_INFO("Should be done in 8 seconds: 2 x 500ms + 1s of initial latency and :");
249   XBT_INFO(" - For 3 seconds, three flows share a link to transfer 3 x 1B. 'cpu1' received its payload");
250   XBT_INFO(" - For 2 seconds, two lows share a link to transfer 1 x 1B. 'cpu2' received is payload");
251   XBT_INFO(" - For 1 second, one flow has the full bandwidth to transfer 1B. 'cpu3' received is payload");
252
253   start_time = e->get_clock();
254   sg4::Exec::init()
255       ->set_bytes_amounts(std::vector<double>({0.0, 1.0, 2.0, 3.0,
256                                                0.0, 0.0, 0.0, 0.0,
257                                                0.0, 0.0, 0.0, 0.0,
258                                                0.0, 0.0, 0.0, 0.0 }))
259       ->set_hosts(std::vector<sg4::Host*>({hosts[0], hosts[1], hosts[2], hosts[3]}))
260       ->wait();
261   end_time = e->get_clock();
262   XBT_INFO("Actual result: scattering an increasing number of bytes to 3 hosts takes %.2f seconds.",
263            end_time - start_time);
264   XBT_INFO("\n");
265
266   sg4::this_actor::sleep_for(5);
267
268   XBT_INFO("TEST: 4-host parallel communication with all-to-all pattern.");
269   XBT_INFO("------------------------------------------------------------");
270   XBT_INFO("Each host sends 1B to every other hosts.");
271   XBT_INFO("Should be done in 8 seconds: 2 x 500ms + 1s of initial latency and 6 seconds for transfer");
272   XBT_INFO("Each SHARED link is traversed by 6 flows (3 in and 3 out). ");
273   XBT_INFO("Each 1B transfer thus takes 6 seconds on a 1Bps link");
274
275   start_time = e->get_clock();
276   sg4::Exec::init()
277       ->set_bytes_amounts(std::vector<double>({0.0, 1.0, 1.0, 1.0,
278                                                1.0, 0.0, 1.0, 1.0,
279                                                1.0, 1.0, 0.0, 1.0,
280                                                1.0, 1.0, 1.0, 0.0 }))
281       ->set_hosts(std::vector<sg4::Host*>({hosts[0], hosts[1], hosts[2], hosts[3]}))
282       ->wait();
283   end_time = e->get_clock();
284   XBT_INFO("Actual result: 1-byte all-too-all in a parallel communication takes %.2f seconds.", end_time - start_time);
285   XBT_INFO("\n");
286
287   sg4::this_actor::sleep_for(5);
288
289   XBT_INFO("TEST: Two concurrent communications, 1 large and 1 small.");
290   XBT_INFO("------------------------------------------------------------");
291   XBT_INFO("A host sends two messages of 100MB and 1B to the other host.");
292   XBT_INFO("Should be done in 0.8001 seconds: 1e8/1.25e8 for transfer + 1e-4 of latency");
293   XBT_INFO("The small communication has a negligible impact on the large one.");
294   XBT_INFO("This corresponds to paying latency once and having the full bandwidth for the large communication.");
295
296   start_time = e->get_clock();
297   c1         = sg4::Comm::sendto_async(hosts[0], hosts[7], 1e8);
298   c2         = sg4::Comm::sendto_async(hosts[0], hosts[7], 1.0);
299   c1->wait();
300   c2->wait();
301   end_time = e->get_clock();
302   XBT_INFO("Actual result: 1 small and 1 large concurrent communications take %.4f seconds.", end_time - start_time);
303   XBT_INFO("\n");
304
305   sg4::this_actor::sleep_for(5);
306
307   XBT_INFO("TEST: Concurrent communication and computation.");
308   XBT_INFO("------------------------------------------------------------");
309   XBT_INFO("A host sends 1B to another while the latter compute 2 flop.");
310   XBT_INFO("Should be done in 2 seconds: 1.5s to transfer and 2 seconds to compute.");
311   XBT_INFO("The two activities should overlap smoothly as they use different resources.");
312   XBT_INFO("The completion time is thus the maximum of the time to complete the two activities.");
313
314   start_time = e->get_clock();
315   c1         = sg4::Comm::sendto_async(hosts[0], hosts[4], 1.0);
316   e1         = sg4::Exec::init()->set_flops_amount(2.0)->set_host(hosts[4])->start();
317   e1->wait();
318   c1->wait();
319   end_time = e->get_clock();
320   XBT_INFO("Actual result: Sending 1B while computing 2 flops takes %.4f seconds.", end_time - start_time);
321   XBT_INFO("\n");
322 }
323
324 int main(int argc, char** argv)
325 {
326   sg4::Engine engine(&argc, argv);
327   engine.load_platform(argv[1]);
328   sg4::Actor::create("dispatcher", engine.host_by_name("cpu0"), main_dispatcher);
329   engine.run();
330
331   return 0;
332 }