Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
74b826bb2b1ee9fab754ca100c59a1362eae816e
[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 "simgrid/simix.h"
13
14 namespace simgrid {
15 namespace s4u {
16
17 class Actor;
18 class Storage;
19 class File;
20
21 /** @brief Simulated machine that can host some actors
22  *
23  * It represents some physical resource with computing and networking capabilities.
24  *
25  * All hosts are automatically created during the call of the method
26  * @link{simgrid::s4u::Engine::loadPlatform()}.
27  * You cannot create a host yourself.
28  *
29  * You can retrieve a particular host using @link{simgrid::s4u::Host.byName()},
30  * and actors can retrieve the host on which they run using @link{simgrid::s4u::Host.current()}.
31  */
32 class Host {
33         friend Actor;
34         friend File;
35 private:
36         Host(const char *name);
37 protected:
38         ~Host();
39 public:
40         /** Retrieves an host from its name. */
41         static s4u::Host *byName(std::string name);
42         /** Retrieves the host on which the current actor is running */
43         static s4u::Host *current();
44
45         const char* name();
46
47         /** Turns that host on if it was previously off
48          *
49          * All actors on that host which were marked autorestart will be restarted automatically.
50          * This call does nothing if the host is already on.
51          */
52         void turnOn();
53         /** Turns that host off. All actors are forcefully stopped. */
54         void turnOff();
55         /** Returns if that host is currently up and running */
56         bool isOn();
57
58
59         /** Allows to store user data on that host */
60         void set_userdata(void *data) {p_userdata = data;}
61         /** Retrieves the previously stored data */
62         void* userdata() {return p_userdata;}
63
64         /** Get an associative list [mount point]->[Storage] off all local mount points.
65          *
66          *      This is defined in the platform file, and cannot be modified programatically (yet).
67          *
68          *      Do not change the returned value in any way.
69          */
70         boost::unordered_map<std::string, Storage&> &mountedStorages();
71 private:
72         boost::unordered_map<std::string, Storage&> *mounts = NULL; // caching
73
74 protected:
75         sg_host_t inferior() {return p_inferior;}
76 private:
77         void*p_userdata=NULL;
78         sg_host_t p_inferior;
79         static boost::unordered_map<std::string, s4u::Host *> *hosts;
80 };
81
82 }} // namespace simgrid::s4u
83
84 #endif /* SIMGRID_S4U_HOST_HPP */
85
86 #if 0
87 /* Bindings to the MSG hosts */
88
89 /* Copyright (c) 2006-2014. The SimGrid Team.
90  * All rights reserved.                                                     */
91
92 /* This program is free software; you can redistribute it and/or modify it
93  * under the terms of the license (GNU LGPL) which comes with this package. */
94
95 package org.simgrid.msg;
96
97 import org.simgrid.msg.Storage;
98
99 /*
100 Host jacquelin;
101
102 try { 
103         jacquelin = Host.getByName("Jacquelin");
104 } catch(HostNotFoundException e) {
105         System.err.println(e.toString());
106 }
107 ...
108 \endverbatim
109  *
110  */ 
111 public class Host {
112         /**
113          * This static method returns all of the hosts of the installed platform.
114          *
115          * @return                      An array containing all the hosts installed.
116          *
117          */ 
118         public native static Host[] all();
119
120         /** 
121          * This static method sets a mailbox to receive in asynchronous mode.
122          * 
123          * All messages sent to this mailbox will be transferred to 
124          * the receiver without waiting for the receive call. 
125          * The receive call will still be necessary to use the received data.
126          * If there is a need to receive some messages asynchronously, and some not, 
127          * two different mailboxes should be used.
128          *
129          * @param mailboxName The name of the mailbox
130          */
131         public static native void setAsyncMailbox(String mailboxName);
132
133         /**
134          * This method returns the number of tasks currently running on a host.
135          * The external load (comming from an availability trace) is not taken in account.
136          *
137          * @return                      The number of tasks currently running on a host.
138          */ 
139         public native int getLoad();
140
141         /**
142          * This method returns the speed of the processor of a host,
143          * regardless of the current load of the machine.
144          *
145          * @return                      The speed of the processor of the host in flops.
146          *
147          */ 
148         public native double getSpeed();
149
150         /**
151          * This method returns the number of core of a host.
152          *
153          * @return                      The speed of the processor of the host in flops.
154          *
155          */ 
156         public native double getCoreNumber();
157
158         /**
159          * Returns the value of a given host property (set from the platform file).
160          */
161         public native String getProperty(String name);
162
163         /**
164          * Change the value of a given host property. 
165          */
166         public native void setProperty(String name, String value);
167
168         /** This methods returns the list of storages attached to an host
169          * @return An array containing all storages (name) attached to the host
170          */
171         public native String[] getAttachedStorage();
172
173
174
175 #endif