00001 #ifndef _DIVINE_DISTRIBUTED_HH_
00002 #define _DIVINE_DISTRIBUTED_HH_
00003
00006 #ifndef DOXYGEN_PROCESSING
00007 #include <string>
00008 #include "common/error.hh"
00009 #include "system/state.hh"
00010 #include "distributed/network.hh"
00011
00012 #define DISTRIBUTED_ERR_TYPE 12
00013
00014 using namespace std;
00015
00016 namespace divine {
00017 #endif // DOXYGEN_PROCESSING
00018
00019
00021 const int DIVINE_TAG_SYNC_READY = 0;
00023 const int DIVINE_TAG_SYNC_ONE = 1;
00025 const int DIVINE_TAG_SYNC_TWO = 2;
00027 const int DIVINE_TAG_SYNC_COMPLETION = 3;
00029 const int DIVINE_TAG_USER = 144;
00030
00032 const int NETWORK_ID_MANAGER = 0;
00033
00035 const int NETWORK_HASH_SEED = 0xbafbaf99;
00036
00037 class abstract_info_t {
00038 public:
00039 virtual void update(void) {}
00040 virtual void get_data_ptr(char *&ptr) = 0;
00041 virtual void get_data_size(int &size) = 0;
00042 virtual ~abstract_info_t() {}
00043 };
00044
00045
00046 struct no_const_data_type_t {
00047 int x;
00048 };
00049
00051
00062 template <class updateable_data_t, class constant_data_t = no_const_data_type_t>
00063 class updateable_info_t : public abstract_info_t {
00064 public:
00067 constant_data_t const_data;
00069 updateable_data_t data;
00070 virtual void update(void);
00071 virtual void get_data_ptr(char *&ptr);
00072 virtual void get_data_size(int &size);
00073 virtual ~updateable_info_t() {}
00074 };
00075
00077
00088 template <class updateable_data_t>
00089 class updateable_info_t<updateable_data_t, no_const_data_type_t>: public abstract_info_t {
00090 public:
00092 updateable_data_t data;
00093 virtual void update(void);
00094 virtual void get_data_ptr(char *&ptr);
00095 virtual void get_data_size(int &size);
00096 virtual ~updateable_info_t() {}
00097 };
00098
00100
00109 template <class static_data_t>
00110 class static_info_t : public abstract_info_t {
00111 private:
00112 static_data_t data;
00113 public:
00114 virtual void get_data_ptr(char *&ptr);
00115 virtual void get_data_size(int &size);
00116 virtual ~static_info_t() {}
00117 };
00118
00119 struct distr_stat_t {
00120 int all_sent_sync_msgs_cnt;
00121 int all_received_sync_msgs_cnt;
00122 };
00123
00124 class message_processor_t
00125 {
00126 public:
00127 virtual void process_message(char *buf, int size, int src, int tag, bool urgent) = 0;
00128 virtual ~message_processor_t() {}
00129 };
00130
00131
00133
00135 class distributed_t {
00136 private:
00137 message_processor_t * process_message_functor;
00138
00139 bool fbusy;
00140 int fsync_state;
00141 bool fsynchronized;
00142 bool fproc_msgs_buf_exclusive_mem;
00143
00144 bool finfo_exchange;
00145 char *ptr_info_data;
00146 int info_data_size;
00147 abstract_info_t *pinfo;
00148
00149 int fstat_all_sync_barriers_cnt;
00150 vector<distr_stat_t> *fstatistics;
00151
00152 int* tmp_buf_cl_size;
00153 char* sync_sr_buf;
00154
00155 enum distr_comm_matrix_type_t { dcmt_ssm, dcmt_rsm };
00156 void get_comm_matrix(distr_comm_matrix_type_t cm_type, pcomm_matrix_t& ret, int target);
00157 protected:
00158 divine::error_vector_t& errvec;
00159
00160 enum distr_mode_t {PRE_INIT,PRE_INIT_NET_OK,NORMAL};
00161 distr_mode_t mode;
00162
00163 struct sync_data_t {int sent_msgs; int received_msgs; };
00164 sync_data_t sync_one_result, sync_collector;
00165
00166 hash_function_t hasher;
00167
00168 public:
00169 network_t network;
00170
00171 int cluster_size;
00172 int network_id;
00173 string processor_name;
00174
00176
00180 bool is_manager() const
00181 { return (network_id == NETWORK_ID_MANAGER); }
00182
00185 distributed_t(divine::error_vector_t& arg0 = divine::gerr);
00186 ~distributed_t(void);
00188
00199 void network_initialize(int &argc,char **&argv);
00201 void initialize();
00203 void finalize();
00205 void set_message_processor(message_processor_t * proc_message)
00206 { process_message_functor = proc_message; }
00208 const message_processor_t * get_message_processor() const
00209 { return process_message_functor; }
00210
00211
00212
00214
00227 void get_comm_matrix_ssm(pcomm_matrix_t& ret, int target);
00228
00229
00231
00236 void get_comm_matrix_rsm(pcomm_matrix_t& ret, int target);
00237
00239
00240 int get_all_sent_sync_msgs_cnt(void);
00242
00243 int get_all_received_sync_msgs_cnt(void);
00245
00246 int get_all_sync_barriers_cnt(void);
00247
00249
00250 void set_busy(void);
00252
00253 void set_idle(void);
00254
00255
00256
00257
00258
00261
00265 void set_proc_msgs_buf_exclusive_mem(bool value);
00268
00272 void get_proc_msgs_buf_excluseve_mem(bool &value);
00273
00275 void set_hash_function(hash_functions_t);
00276
00278
00284 int partition_function(divine::state_t &state);
00286 int get_state_net_id(divine::state_t &state);
00287
00289
00299 void process_messages(void);
00300 #if !defined(ORIG_POLL)
00301
00302
00303
00304
00305
00306 void force_poll(void);
00307 #endif
00309
00319 void (*process_user_message) (char *buf, int size, int src, int tag, bool urgent);
00320
00322
00341 bool synchronized(void);
00344
00357 bool synchronized(abstract_info_t &info);
00358 };
00359
00360 template <class updateable_data_t>
00361 void updateable_info_t<updateable_data_t, no_const_data_type_t>::update()
00362 {
00363 data.update();
00364 }
00365
00366 template <class updateable_data_t>
00367 void updateable_info_t<updateable_data_t, no_const_data_type_t>::get_data_ptr(char *&ptr)
00368 {
00369 ptr = static_cast<char *>(static_cast<void *>(&data));
00370 }
00371
00372 template <class updateable_data_t>
00373 void updateable_info_t<updateable_data_t, no_const_data_type_t>::get_data_size(int &size)
00374 {
00375 size = sizeof(updateable_data_t);
00376 }
00377
00378 template <class updateable_data_t, class constant_data_t>
00379 void updateable_info_t<updateable_data_t, constant_data_t>::update()
00380 {
00381 data.update(const_data);
00382 }
00383
00384 template <class updateable_data_t, class constant_data_t>
00385 void updateable_info_t<updateable_data_t, constant_data_t>::get_data_ptr(char *&ptr)
00386 {
00387 ptr = static_cast<char *>(static_cast<void *>(&data));
00388 }
00389
00390 template <class updateable_data_t, class constant_data_t>
00391 void updateable_info_t<updateable_data_t, constant_data_t>::get_data_size(int &size)
00392 {
00393 size = sizeof(updateable_data_t);
00394 }
00395
00396
00397 template <class static_data_t>
00398 void static_info_t<static_data_t>::get_data_ptr(char *&ptr)
00399 {
00400 ptr = static_cast<char *>(static_cast<void *>(&data));
00401 }
00402
00403 template <class static_data_t>
00404 void static_info_t<static_data_t>::get_data_size(int &size)
00405 {
00406 size = sizeof(static_data_t);
00407 }
00408
00409 #ifndef DOXYGEN_PROCESSING
00410 }
00411 #endif // DOXYGEN_PROCESSING
00412
00413 #endif
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424