Main execution loop
[GridLAB-D Core]


Detailed Description

The main execution loop sets up the main simulation, initializes the objects, and runs the simulation until it either settles to equilibrium or runs into a problem.

It also takes care multicore/multiprocessor parallelism when possible. Objects of the same rank will be synchronized simultaneously, resources permitting.

The main processing loop calls each object passing to it a TIMESTAMP indicating the desired synchronization time. The sync() call attempts to advance the object's internal clock to the time indicated, and if successful it returns the time of the next expected change in the object's state. An object state change is one which requires the equilibrium equations of the object to be updated. When an object's state changes, all the other objects in the simulator are given an opportunity to consider the change and possibly alter the time of their next state change. The core continues calling objects, advancing the global clock when necessary, and continuing in this way until all objects indicate that no further state changes are expected. This is the equilibrium condition and the simulation consequently ends.

Future [Chassin Oct'07]
There is some value in exploring whether it is necessary to update all objects when a particular objects implements a state change. The idea is based on the fact that updates propagate through the model based on known relations, such at the parent-child relation or the link-node relation. Consequently, it should obvious that unless a value in a related object has changed, there can be no significant change to an object that hasn't reached it's declared update time. Thus only the object that "won" the next update time and those that are immediately related to it need be updated. This change could result in a very significant improvement in performance, particularly in models with many lightly coupled objects.


Classes

struct  sync_data
struct  thread_data

Defines

#define _MAX_PATH   PATH_MAX
#define PASSCMP(i, p)   (p % 2 ? i <= ranks[p]->last_used : i >= ranks[p]->first_used)
#define PASSINC(p)   (p % 2 ? 1 : -1)
#define PASSINIT(p)   (p % 2 ? ranks[p]->first_used : ranks[p]->last_used)

Functions

int exec_init ()
 The main system initialization sequence.
STATUS exec_start (void)
 This is the main simulation loop.
STATUS exec_test (struct sync_data *data,int pass,OBJECT *obj)
 Starts the executive test loop.
char * simtime (void)
STATUS t_setup_ranks (void)
STATUS t_sync_all (PASSCONFIG pass)

Variables

int iteration_counter = 0
int64 lock_count = 0
int64 lock_spin = 0
const PASSCONFIG passtype [] = {PC_PRETOPDOWN, PC_BOTTOMUP, PC_POSTTOPDOWN}
int stop_now
 flag indicating the the debugger needs to be activated


Function Documentation

int exec_init ( void   ) 

The main system initialization sequence.

Returns:
1 on success, 0 on failure

Definition at line 67 of file exec.c.

References FAILED, global_init(), random_init(), and timestamp_set_tz().

Referenced by main(), and mexFunction().

STATUS exec_start ( void   ) 

This is the main simulation loop.

Returns:
STATUS is SUCCESS if the simulation reached equilibrium, and FAILED if a problem was encountered.

Definition at line 273 of file exec.c.

References convert_from_timestamp(), thread_data::count, s_listitem::data, thread_data::data, exec_debug(), exec_sigint(), FAILED, sync_data::hard_event, int64, iteration_counter, module_checkall(), s_listitem::next, output_debug(), output_error(), output_message(), output_verbose(), PASSCMP, PASSINC, PASSINIT, simtime(), sync_data::status, sync_data::step_to, stop_now, SUCCESS, THROW, TRY, and TS_NEVER.

Referenced by cmex_start(), and environment_start().

STATUS exec_test ( struct sync_data data,
int  pass,
OBJECT obj 
)

Starts the executive test loop.

Returns:
STATUS is SUCCESS if all test passed, FAILED is any test failed.

< the current object

Parameters:
data  the synchronization state data
pass  the pass number

Definition at line 496 of file exec.c.

References FAILED, sync_data::hard_event, s_object_list::id, s_object_list::in_svc, iteration_counter, s_class_list::name, object_name(), object_sync(), s_object_list::oclass, output_error(), output_verbose(), simtime(), sync_data::status, sync_data::step_to, SUCCESS, and TS_NEVER.

Referenced by t_sync_all().


GridLAB-DTM Version 1.0
An open-source project initiated by the US Department of Energy