X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/315c1504ff4aec5188611d052a65c97aec85cd92..1ca81fc277d3274d398224de56f34427161de314:/examples/s4u/io-file-remote/s4u-io-file-remote.cpp diff --git a/examples/s4u/io-file-remote/s4u-io-file-remote.cpp b/examples/s4u/io-file-remote/s4u-io-file-remote.cpp index 46fbede2e3..35793244f7 100644 --- a/examples/s4u/io-file-remote/s4u-io-file-remote.cpp +++ b/examples/s4u/io-file-remote/s4u-io-file-remote.cpp @@ -1,10 +1,10 @@ -/* Copyright (c) 2014-2016. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2014-2019. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include #include -#include #include #define INMEGA (1024 * 1024) @@ -13,40 +13,25 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io, "Messages specific for this io example") static int host(int argc, char* argv[]) { - simgrid::s4u::File* file = new simgrid::s4u::File(argv[1], nullptr); - const char* filename = file->getPath(); + simgrid::s4u::File file(argv[1], nullptr); + const char* filename = file.get_path(); XBT_INFO("Opened file '%s'", filename); - file->dump(); - - XBT_INFO("Try to read %llu from '%s'", file->size(), filename); - sg_size_t read = file->read(file->size()); - XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu", read, filename, file->tell()); - XBT_INFO("Seek back to the begining of the stream..."); - file->seek(0, SEEK_SET); - XBT_INFO("Offset is now at: %llu", file->tell()); - - delete file; - - if (argc > 5) { - file = new simgrid::s4u::File(argv[2], nullptr); - filename = file->getPath(); - XBT_INFO("Opened file '%s'", filename); - XBT_INFO("Try to write %llu MiB to '%s'", file->size() / 1024, filename); - sg_size_t write = file->write(file->size() * 1024); - XBT_INFO("Have written %llu bytes to '%s'.", write, filename); - - if (std::stoi(argv[5]) != 0) { - XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, file->size(), - simgrid::s4u::Host::current()->getCname(), argv[3]); - file->remoteMove(simgrid::s4u::Host::by_name(argv[3]), argv[4]); + file.dump(); + XBT_INFO("Try to write %llu MiB to '%s'", file.size() / 1024, filename); + sg_size_t write = file.write(file.size() * 1024); + XBT_INFO("Have written %llu MiB to '%s'.", write / (1024 * 1024), filename); + + if (argc > 4) { + if (std::stoi(argv[4]) != 0) { + XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, file.size(), + simgrid::s4u::Host::current()->get_cname(), argv[2]); + file.remote_move(simgrid::s4u::Host::by_name(argv[2]), argv[3]); } else { - XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, file->size(), - simgrid::s4u::Host::current()->getCname(), argv[3]); - file->remoteCopy(simgrid::s4u::Host::by_name(argv[3]), argv[4]); - delete file; + XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, file.size(), + simgrid::s4u::Host::current()->get_cname(), argv[2]); + file.remote_copy(simgrid::s4u::Host::by_name(argv[2]), argv[3]); } } - return 0; } @@ -54,22 +39,25 @@ int main(int argc, char** argv) { simgrid::s4u::Engine e(&argc, argv); sg_storage_file_system_init(); - e.loadPlatform(argv[1]); - e.registerFunction("host", host); - e.loadDeployment(argv[2]); - - for (auto const& s : *simgrid::s4u::allStorages()) { - XBT_INFO("Init: %llu/%llu MiB used/free on '%s'", sg_storage_get_size_used(s.second) / INMEGA, - sg_storage_get_size_free(s.second) / INMEGA, s.second->getCname()); + e.load_platform(argv[1]); + e.register_function("host", host); + e.load_deployment(argv[2]); + std::vector all_hosts = e.get_all_hosts(); + + for (auto const& h : all_hosts) { + for (auto const& d : h->get_disks()) + XBT_INFO("Init: %s: %llu/%llu MiB used/free on '%s@%s'", h->get_cname(), sg_disk_get_size_used(d) / INMEGA, + sg_disk_get_size_free(d) / INMEGA, d->get_cname(), d->get_host()->get_cname()); } e.run(); - for (auto const& s : *simgrid::s4u::allStorages()) { - XBT_INFO("End: %llu/%llu MiB used/free on '%s'", sg_storage_get_size_used(s.second) / INMEGA, - sg_storage_get_size_free(s.second) / INMEGA, s.second->getCname()); + for (auto const& h : all_hosts) { + for (auto const& d : h->get_disks()) + XBT_INFO("End: %llu/%llu MiB used/free on '%s@%s'", sg_disk_get_size_used(d) / INMEGA, + sg_disk_get_size_free(d) / INMEGA, d->get_cname(), h->get_cname()); } - XBT_INFO("Simulation time %g", simgrid::s4u::Engine::getClock()); + XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock()); return 0; }