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

Private GIT Repository
Cosmetics: reindent and remove unused variables.
[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 <xbt/log.h>
17 #include "communicator.h"
18 #include "neighbor.h"
19
20 class process {
21 public:
22     static double get_total_load_init() { return total_load_init; }
23     static double get_total_load_exit() { return total_load_exit; }
24
25     process(int argc, char* argv[]);
26     virtual ~process();
27
28     int run();
29
30 protected:
31     typedef std::vector<neighbor> neigh_type;
32     typedef std::vector<neighbor*> pneigh_type;
33
34     pneigh_type pneigh;         // list of pointers to neighbors that
35                                 // we are free to reorder
36
37     // Returns the sum of "to_send" for all neighbors.
38     double sum_of_to_send() const;
39
40     // Calls neighbor::print(verbose, logp, cat) for each member of neigh.
41     void print_loads(bool verbose = false,
42                      e_xbt_log_priority_t logp = xbt_log_priority_info,
43                      xbt_log_category_t cat = _XBT_LOGV(default)) const;
44
45     // Calls neighbor::print(verbose, logp, cat) for each member of pneigh.
46     void print_loads_p(bool verbose = false,
47                        e_xbt_log_priority_t logp = xbt_log_priority_info,
48                        xbt_log_category_t cat = _XBT_LOGV(default)) const;
49
50 private:
51     static double total_load_init; // sum of neighbor loads at init
52     static double total_load_exit; // sum of neighbor loads at exit
53
54     typedef MAP_TEMPLATE<m_host_t, neighbor*> rev_neigh_type;
55     neigh_type neigh;           // list of neighbors (do not alter
56                                 // after construction!)
57     rev_neigh_type rev_neigh;   // map m_host_t -> neighbor
58
59     communicator comm;          // communicator for this process
60     int ctrl_close_pending;     // number of "close" messages to wait
61                                 // on ctrl channel
62     int data_close_pending;     // number of "close" messages to wait
63                                 // on data channel
64
65     unsigned iter;              // counter of iterations
66
67     double prev_load_broadcast; // used to ensure that we do not send
68                                 // a same information messages
69     double load;                // current load
70     double expected_load;       // expected load in bookkeeping mode
71
72     // The load balancing algorithm comes here...
73     // Parameter "my_load" is the load to take into account for myself
74     // (may be load or expected load).
75     // Returns the total load sent to neighbors.
76     virtual double load_balance(double my_load);
77
78     // Virtually do some computation
79     void compute();
80
81     // Send procedures, with helpers for bookkeeping mode or not
82     void send1_no_bookkeeping(neighbor& nb);
83     void send1_bookkeeping(neighbor& nb);
84     void send();
85
86     // Receive procedure: wait (or not) for a message to come.
87     // Returns false if some "close" message was received, returns true
88     // otherwise.
89     enum recv_wait_mode { NO_WAIT = 0, WAIT, WAIT_FOR_CLOSE };
90     bool receive(recv_wait_mode wait);
91
92     // Finalize sends a "close" message to each neighbor and wait for
93     // all of them to answer.
94     void finalize1(neighbor& nb);
95     void finalize();
96 };
97
98 #endif // !PROCESS_H
99
100 // Local variables:
101 // mode: c++
102 // End: