1 /* Copyright (c) 2006-2015. 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 #ifndef SIMGRID_S4U_HOST_HPP
7 #define SIMGRID_S4U_HOST_HPP
9 #include <boost/unordered_map.hpp>
13 #include <xbt/string.hpp>
14 #include <xbt/signal.hpp>
15 #include <xbt/Extendable.hpp>
17 #include <simgrid/simix.h>
18 #include <simgrid/datatypes.h>
19 #include <simgrid/s4u/forward.hpp>
24 extern template class XBT_PUBLIC() Extendable<simgrid::s4u::Host>;
32 * An host represents some physical resource with computing and networking capabilities.
34 * All hosts are automatically created during the call of the method
35 * @link{simgrid::s4u::Engine::loadPlatform()}.
36 * You cannot create a host yourself.
38 * You can retrieve a particular host using simgrid::s4u::Host::byName()
39 * and actors can retrieve the host on which they run using simgrid::s4u::Host::current().
41 XBT_PUBLIC_CLASS Host :
42 public simgrid::xbt::Extendable<Host> {
45 explicit Host(const char *name);
46 public: // TODO, make me private
48 /** Do not use this function, it should be private */
49 static Host* by_name_or_create(const char* name);
51 /** Retrieves an host from its name, or return nullptr */
52 static Host* by_name_or_null(const char* name);
53 /** Retrieves an host from its name, or die */
54 static s4u::Host *by_name(std::string name);
55 /** Retrieves the host on which the current actor is running */
56 static s4u::Host *current();
58 simgrid::xbt::string const& name() const { return name_; }
60 /** Turns that host on if it was previously off
62 * All actors on that host which were marked autorestart will be restarted automatically.
63 * This call does nothing if the host is already on.
66 /** Turns that host off. All actors are forcefully stopped. */
68 /** Returns if that host is currently up and running */
70 bool isOff() { return !isOn(); }
74 xbt_dict_t properties();
75 const char*property(const char*key);
76 void setProperty(const char*key, const char *value);
77 xbt_swag_t processes();
78 double getPstateSpeedCurrent();
79 double getPstateSpeed(int pstate_index);
80 int pstatesCount() const;
81 void setPstate(int pstate_index);
83 void parameters(vm_params_t params);
84 void setParameters(vm_params_t params);
85 xbt_dict_t mountedStoragesAsDict(); // HACK
86 xbt_dynar_t attachedStorages();
88 /** Get an associative list [mount point]->[Storage] of all local mount points.
90 * This is defined in the platform file, and cannot be modified programatically (yet).
92 boost::unordered_map<std::string, Storage*> const &mountedStorages();
95 simgrid::xbt::string name_ = "noname";
96 boost::unordered_map<std::string, Storage*> *mounts = nullptr; // caching
99 // TODO, this could be a unique_ptr
100 /** DO NOT USE DIRECTLY (@todo: these should be protected, once our code is clean) */
101 surf::Cpu *pimpl_cpu = nullptr;
102 /** DO NOT USE DIRECTLY (@todo: these should be protected, once our code is clean) */
103 routing::NetCard *pimpl_netcard = nullptr;
106 /*** Called on each newly created object */
107 static simgrid::xbt::signal<void(Host&)> onCreation;
108 /*** Called just before destructing an object */
109 static simgrid::xbt::signal<void(Host&)> onDestruction;
110 /*** Called when the machine is turned on or off */
111 static simgrid::xbt::signal<void(Host&)> onStateChange;
114 }} // namespace simgrid::s4u
116 extern int MSG_HOST_LEVEL;
117 extern int SIMIX_HOST_LEVEL;
118 extern int USER_HOST_LEVEL;
120 #endif /* SIMGRID_S4U_HOST_HPP */
123 /* Bindings to the MSG hosts */
125 /* Copyright (c) 2006-2014. The SimGrid Team.
126 * All rights reserved. */
128 /* This program is free software; you can redistribute it and/or modify it
129 * under the terms of the license (GNU LGPL) which comes with this package. */
131 package org.simgrid.msg;
135 * This static method returns all of the hosts of the installed platform.
137 * @return An array containing all the hosts installed.
140 public native static Host[] all();
143 * This static method sets a mailbox to receive in asynchronous mode.
145 * All messages sent to this mailbox will be transferred to
146 * the receiver without waiting for the receive call.
147 * The receive call will still be necessary to use the received data.
148 * If there is a need to receive some messages asynchronously, and some not,
149 * two different mailboxes should be used.
151 * @param mailboxName The name of the mailbox
153 public static native void setAsyncMailbox(String mailboxName);
156 * This method returns the number of tasks currently running on a host.
157 * The external load (coming from an availability trace) is not taken in account.
159 * @return The number of tasks currently running on a host.
161 public native int getLoad();
164 /** This methods returns the list of storages attached to an host
165 * @return An array containing all storages (name) attached to the host
167 public native String[] getAttachedStorage();