Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allStorages() -> getStorageList(whereTo)
[simgrid.git] / examples / s4u / io-file-remote / s4u-io-file-remote.cpp
1 /* Copyright (c) 2014-2017. 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 <src/plugins/file_system/FileSystem.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 int host(int argc, char* argv[])
15 {
16   simgrid::s4u::File* file = new simgrid::s4u::File(argv[1], nullptr);
17   const char* filename     = file->getPath();
18   XBT_INFO("Opened file '%s'", filename);
19   file->dump();
20
21   XBT_INFO("Try to read %llu from '%s'", file->size(), filename);
22   sg_size_t read = file->read(file->size());
23   XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu", read, filename, file->tell());
24   XBT_INFO("Seek back to the begining of the stream...");
25   file->seek(0, SEEK_SET);
26   XBT_INFO("Offset is now at: %llu", file->tell());
27
28   delete file;
29
30   if (argc > 5) {
31     file     = new simgrid::s4u::File(argv[2], nullptr);
32     filename = file->getPath();
33     XBT_INFO("Opened file '%s'", filename);
34     XBT_INFO("Try to write %llu MiB to '%s'", file->size() / 1024, filename);
35     sg_size_t write = file->write(file->size() * 1024);
36     XBT_INFO("Have written %llu bytes to '%s'.", write, filename);
37
38     if (std::stoi(argv[5]) != 0) {
39       XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, file->size(),
40                simgrid::s4u::Host::current()->getCname(), argv[3]);
41       file->remoteMove(simgrid::s4u::Host::by_name(argv[3]), argv[4]);
42       delete file;
43     } else {
44       XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, file->size(),
45                simgrid::s4u::Host::current()->getCname(), argv[3]);
46       file->remoteCopy(simgrid::s4u::Host::by_name(argv[3]), argv[4]);
47       delete file;
48     }
49   }
50
51   return 0;
52 }
53
54 int main(int argc, char** argv)
55 {
56   simgrid::s4u::Engine e(&argc, argv);
57   sg_storage_file_system_init();
58   e.loadPlatform(argv[1]);
59   e.registerFunction("host", host);
60   e.loadDeployment(argv[2]);
61   std::map<std::string, simgrid::s4u::Storage*>* allStorages = new std::map<std::string, simgrid::s4u::Storage*>;
62   simgrid::s4u::getStorageList(allStorages);
63
64   for (auto const& s : *allStorages) {
65     XBT_INFO("Init: %llu/%llu MiB used/free on '%s'", sg_storage_get_size_used(s.second) / INMEGA,
66              sg_storage_get_size_free(s.second) / INMEGA, s.second->getCname());
67   }
68
69   e.run();
70
71   for (auto const& s : *allStorages) {
72     XBT_INFO("End: %llu/%llu MiB used/free on '%s'", sg_storage_get_size_used(s.second) / INMEGA,
73              sg_storage_get_size_free(s.second) / INMEGA, s.second->getCname());
74   }
75
76   delete allStorages;
77   XBT_INFO("Simulation time %g", simgrid::s4u::Engine::getClock());
78   return 0;
79 }