4 #define USE_UNORDERED_MAP 1
5 //#undef USE_UNORDERED_MAP
8 #ifdef USE_UNORDERED_MAP
9 # include <tr1/unordered_map>
10 # define MAP_TEMPLATE std::tr1::unordered_map
13 # define MAP_TEMPLATE std::map
17 #include "communicator.h"
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; }
27 process(int argc, char* argv[]);
30 double get_comp() const { return comp; }
31 double get_real_load() const { return real_load; }
36 typedef std::vector<neighbor> neigh_type;
37 typedef std::vector<neighbor*> pneigh_type;
39 pneigh_type pneigh; // list of pointers to neighbors that
40 // we are free to reorder
42 // Calls neighbor::print(verbose, logp, cat) for each member of neigh.
43 void print_loads(bool verbose = false,
44 e_xbt_log_priority_t logp = xbt_log_priority_info,
45 xbt_log_category_t cat = _XBT_LOGV(default)) const;
47 // Calls neighbor::print(verbose, logp, cat) for each member of pneigh.
48 void print_loads_p(bool verbose = false,
49 e_xbt_log_priority_t logp = xbt_log_priority_info,
50 xbt_log_category_t cat = _XBT_LOGV(default)) const;
53 static double total_load_init; // sum of process loads at init
54 static double total_load_running; // sum of loads while running
55 static double total_load_exit; // sum of process loads at exit
57 typedef MAP_TEMPLATE<m_host_t, neighbor*> rev_neigh_type;
58 neigh_type neigh; // list of neighbors (do not alter
59 // after construction!)
60 rev_neigh_type rev_neigh; // map m_host_t -> neighbor
62 communicator comm; // communicator for this process
63 int ctrl_close_pending; // number of "close" messages to wait
65 int data_close_pending; // number of "close" messages to wait
67 bool close_received; // true if we received a "close" message
68 bool finalizing; // true when finalize() is running
70 unsigned lb_iter; // counter of load-balancing iterations
71 unsigned comp_iter; // counter of computation iterations
73 double comp; // total computing done so far (flops)
75 double prev_load_broadcast; // used to ensure that we do not send
76 // a same information messages
77 double real_load; // current load
78 double expected_load; // expected load in bookkeeping mode
80 double& lb_load() { return opt::bookkeeping ? expected_load : real_load; }
82 // The load balancing algorithm comes here...
83 // Parameter "my_load" is the load to take into account for myself
84 // (may be real load or expected load).
85 // Returns the total load sent to neighbors.
86 virtual double load_balance(double my_load);
88 // Virtually do some computation
91 // Send procedures, with helpers for bookkeeping mode or not
92 void send1_no_bookkeeping(neighbor& nb);
93 void send1_bookkeeping(neighbor& nb);
96 // Returns true if there remains neighbors to listen for
97 bool may_receive() { return ctrl_close_pending || data_close_pending; }
100 // Parameter "timeout" may be 0 for non-blocking operation, -1 for
101 // infinite waiting, or any positive timeout.
102 void receive(double timeout);
104 // Finalize sends a "close" message to each neighbor and wait for
105 // all of them to answer.
106 void finalize1(neighbor& nb);