]> AND Private Git Repository - loba.git/blob - process.h
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Add more documentation.
[loba.git] / process.h
1 #ifndef PROCESS_H
2 #define PROCESS_H
3
4 #define USE_UNORDERED_MAP 1
5 //#undef USE_UNORDERED_MAP
6
7 #include <vector>
8 #ifdef USE_UNORDERED_MAP
9 #  include <tr1/unordered_map>
10 #  define MAP_TEMPLATE std::tr1::unordered_map
11 #else
12 #  include <map>
13 #  define MAP_TEMPLATE std::map
14 #endif
15 #include <msg/msg.h>
16 #include "communicator.h"
17 #include "neighbor.h"
18
19 class process {
20 public:
21     process(int argc, char* argv[]);
22     ~process();
23     int run();
24
25 protected:
26     typedef std::vector<neighbor> neigh_type;
27     typedef std::vector<neighbor*> pneigh_type;
28
29     pneigh_type pneigh;         // list of pointers to neighbors that
30                                 // we are free to reorder
31
32     // Returns the sum of "to_send" for all neighbors.
33     double sum_of_to_send() const;
34
35 private:
36     typedef MAP_TEMPLATE<m_host_t, neighbor*> rev_neigh_type;
37
38     neigh_type neigh;           // list of neighbors (do not alter
39                                 // after construction!)
40     rev_neigh_type rev_neigh;   // map m_host_t -> neighbor
41
42     communicator comm;          // communicator for this process
43     int ctrl_close_pending;     // number of "close" messages to wait
44                                 // on ctrl channel
45     int data_close_pending;     // number of "close" messages to wait
46                                 // on data channel
47
48     unsigned iter;              // counter of iterations
49
50     double prev_load_broadcast; // used to ensure that we do not send
51                                 // a same information messages
52     double load;                // current load
53     double expected_load;       // expected load in bookkeeping mode
54
55     // The load balancing algorithm comes here...
56     // Parameter "my_load" is the load to take into account for myself
57     // (may be load or expected load).
58     // Returns the total load sent to neighbors.
59     virtual double load_balance(double my_load);
60
61     // Virtually do some computation
62     void compute();
63
64     // Send procedures, with helpers for bookkeeping mode or not
65     void send1_no_bookkeeping(neighbor& nb);
66     void send1_bookkeeping(neighbor& nb);
67     void send();
68
69     // Receive procedure: wait (or not) for a message to come.
70     // Returns false if some "close" message was received, returns true
71     // otherwise.
72     enum recv_wait_mode { NO_WAIT = 0, WAIT, WAIT_FOR_CLOSE };
73     bool receive(recv_wait_mode wait);
74
75     // Finalize sends a "close" message to each neighbor and wait for
76     // all of them to answer.
77     void finalize1(neighbor& nb);
78     void finalize();
79
80     // Print with given priority what we know about our neighbors' loads
81     void print_loads(e_xbt_log_priority_t logp = xbt_log_priority_info);
82 };
83
84 #endif // !PROCESS_H
85
86 // Local variables:
87 // mode: c++
88 // End: