1 /* Copyright (c) 2014-2020. 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/actor.h"
7 #include "simgrid/disk.h"
8 #include "simgrid/engine.h"
9 #include "simgrid/host.h"
10 #include <simgrid/plugins/file_system.h>
12 #include "xbt/asserts.h"
15 #define INMEGA (1024 * 1024)
17 XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io, "Messages specific for this io example");
19 static void host(int argc, char* argv[])
21 sg_file_t file = sg_file_open(argv[1], NULL);
22 const char* filename = sg_file_get_name(file);
23 XBT_INFO("Opened file '%s'", filename);
26 XBT_INFO("Try to write %llu MiB to '%s'", sg_file_get_size(file) / 1024, filename);
27 sg_size_t write = sg_file_write(file, sg_file_get_size(file) * 1024);
28 XBT_INFO("Have written %llu MiB to '%s'.", write / (1024 * 1024), filename);
31 if (atoi(argv[4]) != 0) {
32 XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, sg_file_get_size(file), sg_host_self_get_name(),
34 sg_file_rmove(file, sg_host_by_name(argv[2]), argv[3]);
36 XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, sg_file_get_size(file), sg_host_self_get_name(),
38 sg_file_rcopy(file, sg_host_by_name(argv[2]), argv[3]);
44 int main(int argc, char** argv)
46 simgrid_init(&argc, argv);
47 sg_storage_file_system_init();
48 simgrid_load_platform(argv[1]);
50 simgrid_register_function("host", host);
51 simgrid_load_deployment(argv[2]);
53 size_t host_count = sg_host_count();
54 sg_host_t* hosts = sg_host_list();
56 for (long i = 0; i < host_count; i++) {
57 unsigned int disk_count;
59 sg_host_get_disks(hosts[i], &disk_count, &disks);
60 for (unsigned int j = 0; j < disk_count; j++)
61 XBT_INFO("Init: %s: %llu/%llu MiB used/free on '%s@%s'", sg_host_get_name(hosts[i]),
62 sg_disk_get_size_used(disks[j]) / INMEGA, sg_disk_get_size_free(disks[j]) / INMEGA,
63 sg_disk_get_name(disks[j]), sg_host_get_name(sg_disk_get_host(disks[j])));
69 for (long i = 0; i < host_count; i++) {
70 unsigned int disk_count;
72 sg_host_get_disks(hosts[i], &disk_count, &disks);
73 for (unsigned int j = 0; j < disk_count; j++)
74 XBT_INFO("End: %llu/%llu MiB used/free on '%s@%s'", sg_disk_get_size_used(disks[j]) / INMEGA,
75 sg_disk_get_size_free(disks[j]) / INMEGA, sg_disk_get_name(disks[j]), sg_host_get_name(hosts[i]));
81 XBT_INFO("Simulation time %g", simgrid_get_clock());