distributed_t Class Reference

Main distributed support class. More...

#include <distributed.hh>

List of all members.

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


Detailed Description

Main distributed support class.

The class provides support for common operations necessary for distributed computing such as partition function and termination detection (synchronization).


Constructor & Destructor Documentation

distributed_t ( divine::error_vector_t &  arg0 = divine::gerr  ) 

A constructor, does't initialize anything!,
non-default error handling vector can be specified


Member Function Documentation

int get_all_received_sync_msgs_cnt ( void   ) 

Get all received synchronization messages count.

Returns:
Number of synchronization messages received by the calling workstation.

int get_all_sent_sync_msgs_cnt ( void   ) 

Get all sent synchronization messages count.

Returns:
Number of synchronization messages sent by the calling workstation.

int get_all_sync_barriers_cnt ( void   ) 

Get all synchronization barriers count.

Returns:
Number of synchronization barriers on the calling workstation.

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.

Parameters:
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
Returns:
true if the function suceeds, false otherwise
Synchronization process requires communication between workstations. Use this function to get the counts of synchronization messages sent by each workstation to each workstation. The function must be called in a way explained for the network_t::barrier() function.

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.

Parameters:
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.
Initializes network, since then cluster_size, network_id and processor_name are valid. You can also set send buffer's limits using functions of network. But you still cannot send/receive messages, etc. To complete initialization call the initialize() function.

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.

Parameters:
state = a state, which association with a computer is to be retrieved
Returns:
computer unique identifier of the state owner
Partition function, returns the number of the computer which the state passed as the argument belongs to.

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

Parameters:
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.

Returns:
true if workstations are synchronized.
It works in the following way. By first call to this function (on all workstations in the cluster) you are telling that you want to perform some distributed computation and at the end you wan to synchronize. During the computation you send messages using network_t::send_message() or network_t::send_urgent_message(). To receive message use the process_messages() function which calls process_user_message(), where you can do something with the received message. By subsequent calls to synchronized() you determine if all workstations finished their work. In distributed computation, work mosly implies sending messages, but if you want to do some bigger amount of work without sending messages and you don't want to synchronize, use the set_busy() function. Don't forget to call set_idle() function when your work is finished and remember to call them before process_messages(). synchronized() and process_messages() should be called quite often to make the computation efficient.

Warning:
Synchronization is performed in process_messages() method.

References network_t::barrier(), DIVINE_TAG_SYNC_READY, and network.


Member Data Documentation

void(* process_user_message)(char *buf, int size, int src, int tag, bool urgent)

Pointer to user-defined function that processes user messages.

Parameters:
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
To be able to use synchronization together with sending your own messages, you must write this function and assign it's pointer to process_user_message().

Referenced by process_messages().


The documentation for this class was generated from the following files:

Reference Manual for Library, 2006 developed in ParaDiSe laboratory, Faculty of Informatics, Masaryk University