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 currentPowerPeak();
79 double powerPeakAt(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 // FIXME: these should be protected, but it leads to many errors
100 // Use the extensions stuff for this? Go through simgrid::surf::Host?
101 // TODO, this could be a unique_ptr
102 surf::Cpu *pimpl_cpu = nullptr;
103 surf::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;
133 import org.simgrid.msg.Storage;
139 jacquelin = Host.getByName("Jacquelin");
140 } catch(HostNotFoundException e) {
141 System.err.println(e.toString());
149 * This static method returns all of the hosts of the installed platform.
151 * @return An array containing all the hosts installed.
154 public native static Host[] all();
157 * This static method sets a mailbox to receive in asynchronous mode.
159 * All messages sent to this mailbox will be transferred to
160 * the receiver without waiting for the receive call.
161 * The receive call will still be necessary to use the received data.
162 * If there is a need to receive some messages asynchronously, and some not,
163 * two different mailboxes should be used.
165 * @param mailboxName The name of the mailbox
167 public static native void setAsyncMailbox(String mailboxName);
170 * This method returns the number of tasks currently running on a host.
171 * The external load (coming from an availability trace) is not taken in account.
173 * @return The number of tasks currently running on a host.
175 public native int getLoad();
178 * This method returns the speed of the processor of a host,
179 * regardless of the current load of the machine.
181 * @return The speed of the processor of the host in flops.
184 public native double getSpeed();
187 * This method returns the number of core of a host.
189 * @return The speed of the processor of the host in flops.
192 public native double getCoreNumber();
195 * Returns the value of a given host property (set from the platform file).
197 public native String getProperty(String name);
200 * Change the value of a given host property.
202 public native void setProperty(String name, String value);
204 /** This methods returns the list of storages attached to an host
205 * @return An array containing all storages (name) attached to the host
207 public native String[] getAttachedStorage();