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

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