Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Clearly state that we don't care about the return code of actors
[simgrid.git] / examples / s4u / io-file-remote / s4u-io-file-remote.cpp
1 /* Copyright (c) 2014-2020. 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/plugins/file_system.h>
7 #include <simgrid/s4u.hpp>
8 #include <string>
9
10 #define INMEGA (1024 * 1024)
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io, "Messages specific for this io example");
13
14 static void host(int argc, char* argv[])
15 {
16   simgrid::s4u::File file(argv[1], nullptr);
17   const char* filename = file.get_path();
18   XBT_INFO("Opened file '%s'", filename);
19   file.dump();
20   XBT_INFO("Try to write %llu MiB to '%s'", file.size() / 1024, filename);
21   sg_size_t write = file.write(file.size() * 1024);
22   XBT_INFO("Have written %llu MiB to '%s'.", write / (1024 * 1024), filename);
23
24   if (argc > 4) {
25     if (std::stoi(argv[4]) != 0) {
26       XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, file.size(),
27                simgrid::s4u::Host::current()->get_cname(), argv[2]);
28       file.remote_move(simgrid::s4u::Host::by_name(argv[2]), argv[3]);
29     } else {
30       XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, file.size(),
31                simgrid::s4u::Host::current()->get_cname(), argv[2]);
32       file.remote_copy(simgrid::s4u::Host::by_name(argv[2]), argv[3]);
33     }
34   }
35 }
36
37 int main(int argc, char** argv)
38 {
39   simgrid::s4u::Engine e(&argc, argv);
40   sg_storage_file_system_init();
41   e.load_platform(argv[1]);
42   e.register_function("host", host);
43   e.load_deployment(argv[2]);
44   std::vector<simgrid::s4u::Host*> all_hosts = e.get_all_hosts();
45
46   for (auto const& h : all_hosts) {
47     for (auto const& d : h->get_disks())
48       XBT_INFO("Init: %s: %llu/%llu MiB used/free on '%s@%s'", h->get_cname(), sg_disk_get_size_used(d) / INMEGA,
49                sg_disk_get_size_free(d) / INMEGA, d->get_cname(), d->get_host()->get_cname());
50   }
51
52   e.run();
53
54   for (auto const& h : all_hosts) {
55     for (auto const& d : h->get_disks())
56       XBT_INFO("End: %llu/%llu MiB used/free on '%s@%s'", sg_disk_get_size_used(d) / INMEGA,
57                sg_disk_get_size_free(d) / INMEGA, d->get_cname(), h->get_cname());
58   }
59
60   XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
61   return 0;
62 }