Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'condvar'
[simgrid.git] / include / simgrid / s4u / host.hpp
1 /* Copyright (c) 2006-2015. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_S4U_HOST_HPP
7 #define SIMGRID_S4U_HOST_HPP
8
9 #include <boost/unordered_map.hpp>
10 #include <vector>
11
12 #include <xbt/base.h>
13 #include <xbt/string.hpp>
14 #include <xbt/signal.hpp>
15 #include <xbt/Extendable.hpp>
16
17 #include <simgrid/simix.h>
18 #include <simgrid/datatypes.h>
19 #include <simgrid/s4u/forward.hpp>
20
21 namespace simgrid {
22
23 namespace xbt {
24   extern template class XBT_PUBLIC() Extendable<simgrid::s4u::Host>;
25 }
26 namespace s4u {
27
28 /** @ingroup s4u_api
29  *
30  * @tableofcontents
31  *
32  * An host represents some physical resource with computing and networking capabilities.
33  *
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.
37  *
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().
40  */
41 XBT_PUBLIC_CLASS Host :
42   public simgrid::xbt::Extendable<Host> {
43
44 private:
45   explicit Host(const char *name);
46 public: // TODO, make me private
47   ~Host();
48   /** Do not use this function, it should be private */
49   static Host* by_name_or_create(const char* name);
50
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();
57
58   simgrid::xbt::string const& name() const { return name_; }
59
60   /** Turns that host on if it was previously off
61    *
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.
64    */
65   void turnOn();
66   /** Turns that host off. All actors are forcefully stopped. */
67   void turnOff();
68   /** Returns if that host is currently up and running */
69   bool isOn();
70   bool isOff() { return !isOn(); }
71
72   double speed();
73   int coresCount();
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);
82   int pstate();
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();
87
88   /** Get an associative list [mount point]->[Storage] of all local mount points.
89    *
90    *  This is defined in the platform file, and cannot be modified programatically (yet).
91    */
92   boost::unordered_map<std::string, Storage*> const &mountedStorages();
93
94 private:
95   simgrid::xbt::string name_ = "noname";
96   boost::unordered_map<std::string, Storage*> *mounts = nullptr; // caching
97
98 public:
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;
104
105 public:
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;
112 };
113
114 }} // namespace simgrid::s4u
115
116 extern int MSG_HOST_LEVEL;
117 extern int SIMIX_HOST_LEVEL;
118 extern int USER_HOST_LEVEL;
119
120 #endif /* SIMGRID_S4U_HOST_HPP */
121
122 #if 0
123 /* Bindings to the MSG hosts */
124
125 /* Copyright (c) 2006-2014. The SimGrid Team.
126  * All rights reserved.                                                     */
127
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. */
130
131 package org.simgrid.msg;
132
133 public class Host {
134   /**
135    * This static method returns all of the hosts of the installed platform.
136    *
137    * @return      An array containing all the hosts installed.
138    *
139    */ 
140   public native static Host[] all();
141
142   /** 
143    * This static method sets a mailbox to receive in asynchronous mode.
144    * 
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.
150    *
151    * @param mailboxName The name of the mailbox
152    */
153   public static native void setAsyncMailbox(String mailboxName);
154
155   /**
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.
158    *
159    * @return      The number of tasks currently running on a host.
160    */ 
161   public native int getLoad();
162
163
164   /** This methods returns the list of storages attached to an host
165    * @return An array containing all storages (name) attached to the host
166    */
167   public native String[] getAttachedStorage();
168
169
170
171 #endif