#include <distributed.hh>
Public Member Functions | |
distributed_t (divine::error_vector_t &arg0=divine::gerr) | |
void | finalize () |
Finalizes network. Remember that you can finalize only once. | |
void | force_poll (void) |
int | get_all_received_sync_msgs_cnt (void) |
Get all received synchronization messages count. | |
int | get_all_sent_sync_msgs_cnt (void) |
Get all sent synchronization messages count. | |
int | get_all_sync_barriers_cnt (void) |
Get all synchronization barriers count. | |
void | get_comm_matrix_rsm (pcomm_matrix_t &ret, int target) |
Get communication matrix of received sync messages. | |
void | get_comm_matrix_ssm (pcomm_matrix_t &ret, int target) |
Get communication matrix of sent sync messages. | |
const message_processor_t * | get_message_processor () const |
Returns a message processor. | |
void | get_proc_msgs_buf_excluseve_mem (bool &value) |
int | get_state_net_id (divine::state_t &state) |
The same as partition_function(), left here for historical reasons. | |
void | initialize () |
Completes initialization. Remember that you can initialize only once. | |
bool | is_manager () const |
Returns, whether this workstation is a manager of the distributed computation. | |
void | network_initialize (int &argc, char **&argv) |
Network initialization. | |
int | partition_function (divine::state_t &state) |
Function to determine owner of a state. | |
void | process_messages (void) |
Function that checks for arrived messages and participates in synchronization. | |
void | set_busy (void) |
Avoids synchronization. | |
void | set_hash_function (hash_functions_t) |
Sets hash function to be used for partitioning. | |
void | set_idle (void) |
Allows synchronization. | |
void | set_message_processor (message_processor_t *proc_message) |
Sets a message processor. | |
void | set_proc_msgs_buf_exclusive_mem (bool value) |
bool | synchronized (abstract_info_t &info) |
bool | synchronized (void) |
Function that together with process_messages does synchronization. | |
Public Attributes | |
int | cluster_size |
Total number of computers. | |
network_t | network |
instance of network_t, you can use it to send/receive messages, etc. | |
int | network_id |
Unique computer identifier. | |
void(* | process_user_message )(char *buf, int size, int src, int tag, bool urgent) |
Pointer to user-defined function that processes user messages. | |
string | processor_name |
Name of the computer. | |
Protected Types | |
enum | distr_mode_t { PRE_INIT, PRE_INIT_NET_OK, NORMAL } |
Protected Attributes | |
divine::error_vector_t & | errvec |
hash_function_t | hasher |
distr_mode_t | mode |
sync_data_t | sync_collector |
sync_data_t | sync_one_result |
The class provides support for common operations necessary for distributed computing such as partition function and termination detection (synchronization).
distributed_t | ( | divine::error_vector_t & | arg0 = divine::gerr |
) |
A constructor, does't initialize anything!,
non-default error handling vector can be specified
int get_all_received_sync_msgs_cnt | ( | void | ) |
Get all received synchronization messages count.
int get_all_sent_sync_msgs_cnt | ( | void | ) |
Get all sent synchronization messages count.
int get_all_sync_barriers_cnt | ( | void | ) |
Get all synchronization barriers count.
void get_comm_matrix_rsm | ( | pcomm_matrix_t & | ret, | |
int | target | |||
) |
Get communication matrix of received sync messages.
Similar to get_comm_matrix_ssm(), but the position (i, j) of the matrix contains the count of synchronization messages received on workstation with id i from workstation with id j.
void get_comm_matrix_ssm | ( | pcomm_matrix_t & | ret, | |
int | target | |||
) |
Get communication matrix of sent sync messages.
ret | - output parameter, pointer to communication matrix (of type comm_matrix_t) that contains at position (i, j) the count of synchronization messages sent by workstation with id i to workstation with id j | |
target | - only one workstation gets valid pointer ret, this workstation is specified by target parameter, which must be the same on all workstations |
void get_proc_msgs_buf_excluseve_mem | ( | bool & | value | ) |
Gets the value of a variable that determines whether the parameter buf in process_user_message() points directly to internal buffers.
true means buf points to newly allocated (exclusive) memory, false means it points to internal buffers.
false is default, it saves both time and memory.
bool is_manager | ( | ) | const [inline] |
Returns, whether this workstation is a manager of the distributed computation.
The same as
distributed.network_id == NETWORK_ID_MANAGER
References NETWORK_ID_MANAGER.
void network_initialize | ( | int & | argc, | |
char **& | argv | |||
) |
Network initialization.
argc | = Number of command line parameters. Passing the first argument of main is common. | |
argv | = Array of command line parameters. Passing the second argument of main is common. |
References cluster_size, network_t::get_cluster_size(), network_t::get_id(), network_t::get_processor_name(), network_t::initialize_network(), network, network_id, and processor_name.
int partition_function | ( | divine::state_t & | state | ) |
Function to determine owner of a state.
state | = a state, which association with a computer is to be retrieved |
void process_messages | ( | void | ) |
Function that checks for arrived messages and participates in synchronization.
This function checks for new messages. If some message arrived, it receives it and calls process_user_message() function, that's function user must write and give to distributed_t by assigning it's pointer to process_user_message().
When called on manager worstation (the one with id NETWORK_ID_MANAGER), it checks whether the workstation is idle (that is no user message was received in this process_messages() call and user did not call set_busy()), if yes and user also called synchronized() function previously, then synchronization process is initiated.
References DIVINE_TAG_SYNC_COMPLETION, DIVINE_TAG_SYNC_ONE, DIVINE_TAG_SYNC_READY, DIVINE_TAG_SYNC_TWO, DIVINE_TAG_USER, network_t::flush_all_buffers_timed_out_only(), network_t::get_all_received_msgs_cnt(), network_t::get_all_sent_msgs_cnt(), network_t::is_new_message(), network_t::is_new_urgent_message(), network, network_id, NETWORK_ID_MANAGER, process_user_message, network_t::receive_message(), network_t::receive_message_non_exc(), network_t::receive_urgent_message(), network_t::receive_urgent_message_non_exc(), network_t::send_urgent_message(), network_t::stats_num(), network_t::stats_Recv_bytes, and network_t::stats_Sent_bytes_local.
void set_busy | ( | void | ) |
Avoids synchronization.
This method must be called before process_messages() to be effective.
void set_idle | ( | void | ) |
Allows synchronization.
This method must be called before process_messages() to be effective.
References network_t::flush_all_buffers(), network_t::flush_some_buffers(), and network.
void set_proc_msgs_buf_exclusive_mem | ( | bool | value | ) |
Determines whether the parameter buf in the process_user_message() function points
directly to internal buffers
value | - if true, then the buf parameter in process_user_message() points to exclusive memory and the user is responsible for freeing it. if false, then no special memory is allocated and buf points directly to internal buffer and user must not free it. |
bool synchronized | ( | abstract_info_t & | info | ) |
Function that together with process_messages does synchronization and allows to collect some information during the synchronization process
Similar to synchronized() but it allows to collect some information. Let's take updateable info as an example (see updateable_info_t). You must create a structure (of type struct), attributes of the structure will be used for the collected data. The structure also contains update() function, which manipulates with the attributes. Create an instance of updateable_info_t and pass the structure as its template parameter (the actual structure used for collected data is accessible via the updateable_info_t::data parameter). Pass the instance as the parameter of this function. After all workstations are synchronized, manager workstation (0) sends the contents of the structure to workstation 1, workstation 1 sends it to workstation 2, etc. The last workstation then completes the round. On every workstation the update() function is called, which can manipulate with the attributes.
bool synchronized | ( | void | ) |
Function that together with process_messages does synchronization.
References network_t::barrier(), DIVINE_TAG_SYNC_READY, and network.
void(* process_user_message)(char *buf, int size, int src, int tag, bool urgent) |
Pointer to user-defined function that processes user messages.
buf | - pointer to message data, it points either to newly allocated memory or to internal buffers (see set_proc_msgs_buf_exclusive_mem()) | |
size | - size of the received message | |
src | - id of the sender workstation | |
tag | - tag of the message (Remember that all user messages must have tag greater or equal to DIVINE_TAG_USER. | |
urgent | - specifies whether the received message is urgent or not |
Referenced by process_messages().