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

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