1 /* Copyright (c) 2014-2023. The SimGrid Team. All rights reserved. */
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. */
6 #include <simgrid/plugins/file_system.h>
7 #include <simgrid/s4u.hpp>
10 #define INMEGA (1024 * 1024)
12 XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io, "Messages specific for this io example");
13 namespace sg4 = simgrid::s4u;
15 static void host(std::vector<std::string> args)
17 sg4::File* file = sg4::File::open(args[1], nullptr);
18 const char* filename = file->get_path();
19 XBT_INFO("Opened file '%s'", filename);
21 XBT_INFO("Try to write %llu MiB to '%s'", file->size() / 1024, filename);
22 sg_size_t write = file->write(file->size() * 1024);
23 XBT_INFO("Have written %llu MiB to '%s'.", write / (1024 * 1024), filename);
25 if (args.size() > 4) {
26 if (std::stoi(args[4]) != 0) {
27 XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, file->size(), sg4::Host::current()->get_cname(),
29 file->remote_move(sg4::Host::by_name(args[2]), args[3]);
31 XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, file->size(), sg4::Host::current()->get_cname(),
33 file->remote_copy(sg4::Host::by_name(args[2]), args[3]);
39 int main(int argc, char** argv)
41 sg4::Engine e(&argc, argv);
42 sg_storage_file_system_init();
43 e.load_platform(argv[1]);
44 e.register_function("host", host);
45 e.load_deployment(argv[2]);
46 std::vector<sg4::Host*> all_hosts = e.get_all_hosts();
48 for (auto const& h : all_hosts) {
49 for (auto const& d : h->get_disks())
50 XBT_INFO("Init: %s: %llu/%llu MiB used/free on '%s@%s'", h->get_cname(), sg_disk_get_size_used(d) / INMEGA,
51 sg_disk_get_size_free(d) / INMEGA, d->get_cname(), d->get_host()->get_cname());
56 for (auto const& h : all_hosts) {
57 for (auto const& d : h->get_disks())
58 XBT_INFO("End: %llu/%llu MiB used/free on '%s@%s'", sg_disk_get_size_used(d) / INMEGA,
59 sg_disk_get_size_free(d) / INMEGA, d->get_cname(), h->get_cname());
62 XBT_INFO("Simulation time %g", sg4::Engine::get_clock());