Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / examples / cpp / io-file-remote / s4u-io-file-remote.cpp
1 /* Copyright (c) 2014-2022. 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(std::vector<std::string> args)
15 {
16   simgrid::s4u::File* file = simgrid::s4u::File::open(args[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 (args.size() > 4) {
25     if (std::stoi(args[4]) != 0) {
26       XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, file->size(),
27                simgrid::s4u::Host::current()->get_cname(), args[2].c_str());
28       file->remote_move(simgrid::s4u::Host::by_name(args[2]), args[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(), args[2].c_str());
32       file->remote_copy(simgrid::s4u::Host::by_name(args[2]), args[3]);
33     }
34   }
35   file->close();
36 }
37
38 int main(int argc, char** argv)
39 {
40   simgrid::s4u::Engine e(&argc, argv);
41   sg_storage_file_system_init();
42   e.load_platform(argv[1]);
43   e.register_function("host", host);
44   e.load_deployment(argv[2]);
45   std::vector<simgrid::s4u::Host*> all_hosts = e.get_all_hosts();
46
47   for (auto const& h : all_hosts) {
48     for (auto const& d : h->get_disks())
49       XBT_INFO("Init: %s: %llu/%llu MiB used/free on '%s@%s'", h->get_cname(), sg_disk_get_size_used(d) / INMEGA,
50                sg_disk_get_size_free(d) / INMEGA, d->get_cname(), d->get_host()->get_cname());
51   }
52
53   e.run();
54
55   for (auto const& h : all_hosts) {
56     for (auto const& d : h->get_disks())
57       XBT_INFO("End: %llu/%llu MiB used/free on '%s@%s'", sg_disk_get_size_used(d) / INMEGA,
58                sg_disk_get_size_free(d) / INMEGA, d->get_cname(), h->get_cname());
59   }
60
61   XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
62   return 0;
63 }