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

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