The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
abm_layer.c File Reference

This file contains the implementation of the the agent based modeling interface offered by ROOT-Sim. More...

#include <ROOT-Sim.h>
#include <lib/abm_layer.h>
#include <core/init.h>
#include <scheduler/scheduler.h>
#include <lib/topology.h>
#include <datatypes/array.h>
#include <datatypes/hash_map.h>
+ Include dependency graph for abm_layer.c:

Go to the source code of this file.

Data Structures

struct  _visit_abm_t
 
struct  _agent_abm_t
 
struct  _region_abm_t
 
struct  _leave_evt
 

Macros

#define ACTION_START   INIT
 
#define retrieve_agent(agent_id)
 

Functions

static unsigned long long get_agent_mark (region_abm_t *region)
 
static unsigned agent_dump_size (const struct _agent_abm_t *agent)
 
static struct _agent_abm_tagent_from_buffer (const unsigned char *event_content, unsigned event_size)
 
static void agent_to_buffer (struct _agent_abm_t *agent, unsigned char *buffer)
 
unsigned char * abm_do_checkpoint (region_abm_t *region)
 
void abm_restore_checkpoint (unsigned char *data, region_abm_t *region)
 
void abm_layer_init (void)
 
static void receive_update (void)
 
static void update_neighbours (void)
 
static void on_abm_visit (void)
 
static void on_abm_leave (void)
 
void ProcessEventABM (void)
 
int GetNeighbourInfo (direction_t i, unsigned int *region_id, void **data_p)
 
void TrackNeighbourInfo (void *neighbour_data)
 
bool IterAgents (agent_t *agent_p)
 
unsigned CountAgents (void)
 
agent_t SpawnAgent (unsigned user_data_size)
 
void KillAgent (agent_t agent_id)
 
void * DataAgent (agent_t agent_id, unsigned *data_size_p)
 
void ScheduleNewLeaveEvent (simtime_t time, unsigned int event_type, agent_t agent_id)
 
unsigned CountPastVisits (agent_t agent_id)
 
void GetPastVisit (agent_t agent_id, unsigned *region_p, unsigned *event_type_p, simtime_t *time_p, unsigned i)
 
unsigned CountVisits (agent_t agent_id)
 
void GetVisit (agent_t agent_id, unsigned *region_p, unsigned *event_type_p, unsigned i)
 
void SetVisit (agent_t agent_id, unsigned region, unsigned event_type, unsigned i)
 
void EnqueueVisit (agent_t agent_id, unsigned region, unsigned event_type)
 
void AddVisit (agent_t agent_id, unsigned region, unsigned event_type, unsigned i)
 
void RemoveVisit (agent_t agent_id, unsigned i)
 

Detailed Description

This file contains the implementation of the the agent based modeling interface offered by ROOT-Sim.

Copyright (C) 2008-2018 HPDCS Group http://www.dis.uniroma1.it/~hpdcs

This file is part of ROOT-Sim (ROme OpTimistic Simulator).

ROOT-Sim is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; only version 3 of the License applies.

ROOT-Sim is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with ROOT-Sim; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Author
Andrea Piccione
Date
16/06/2018

Definition in file abm_layer.c.

Macro Definition Documentation

#define retrieve_agent (   agent_id)
Value:
({ \
struct _agent_abm_t *__ret = hash_map_lookup(current->region->agents_table, agent_id); \
if(unlikely(!__ret)) \
rootsim_error(true, "Looking for non existing agent id!"); \
assert(agent_id == __ret->key); \
__ret; \
})
__thread struct lp_struct * current
This is a per-thread variable pointing to the block state of the LP currently scheduled.
Definition: scheduler.c:72
region_abm_t * region
pointer to the region struct
Definition: process.h:155
#define unlikely(exp)
Optimize the branch as likely not taken.
Definition: core.h:74

Definition at line 38 of file abm_layer.c.

Function Documentation

unsigned char* abm_do_checkpoint ( region_abm_t region)

Checkpoint the region state, saving it into a buffer. This is periodically called by the checkpointing module to save the region state. The returned buffer needs to be freed.

Parameters
regionA pointer to the region struct to be checkpointed
Returns
A malloc'ed buffer holding all the region data

Definition at line 161 of file abm_layer.c.

+ Here is the caller graph for this function:

void abm_layer_init ( void  )

Initializes the abm layer internals for all the lps hosted on the machine. This needs to be called before starting processing events, after basic initialization of the lps.

Definition at line 235 of file abm_layer.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void abm_restore_checkpoint ( unsigned char *  data,
region_abm_t region 
)

Restore a region struct from a previously checkpointed state.

Parameters
dataA pointer to the region struct to be checkpointed
Returns
A malloc'ed buffer holding all the region data

Definition at line 198 of file abm_layer.c.

+ Here is the caller graph for this function:

static unsigned agent_dump_size ( const struct _agent_abm_t agent)
static

Compute the size in bytes of an eventual agent serialization.

Parameters
agentA pointer to the agent

Definition at line 90 of file abm_layer.c.

+ Here is the caller graph for this function:

static struct _agent_abm_t* agent_from_buffer ( const unsigned char *  event_content,
unsigned  event_size 
)
static

Deserialize an agent from a buffer.

Parameters
event_contentA pointer to the buffer containing the serialzied agent
event_sizeThe size in bytes of the buffer
Returns
a newly instantiated agent struct, the deserialized agent

Definition at line 103 of file abm_layer.c.

+ Here is the caller graph for this function:

static void agent_to_buffer ( struct _agent_abm_t agent,
unsigned char *  buffer 
)
static

Serialize an agent into a buffer, the buffer is caller supplied and its required size can be calculated with the function agent_dump_size.

Parameters
agentA pointer to the agent struct to be serialized
bufferA pointer to the buffer to fill with the serialized agent

Definition at line 136 of file abm_layer.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void on_abm_leave ( void  )
static

Handle an agent departure. This is called by the abm layer when a leave message is received. We expect the event to have the the agent key as payload.

Definition at line 326 of file abm_layer.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void on_abm_visit ( void  )
static

Handle a visit to a region. This is called by the abm layer when a visit message is received. We expect the event to have the serialized visiting agent as payload.

Definition at line 297 of file abm_layer.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ProcessEventABM ( void  )

The event handler which gets called instead of the user supplied ProcessEvent() function when the abm_layer is in use. The unrecognized events get passed to ProcessEventTopology() since the abm layer is based on the topology APIs.

Definition at line 461 of file abm_layer.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void receive_update ( void  )
static

Handle an update receive. This updates the corresponding entry in the region struct, which will be used to serve fresh neighbour data to the user.

Definition at line 419 of file abm_layer.c.

+ Here is the caller graph for this function:

static void update_neighbours ( void  )
static

Keep updated the neighbours of changes in the tracked data. This is called after each event and boradcasts eventual changes to neighbours

Definition at line 438 of file abm_layer.c.

+ Here is the caller graph for this function: