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

Core ROOT-Sim functionalities. More...

#include <ROOT-Sim.h>
#include <stdio.h>
#include <limits.h>
#include <float.h>
#include <math.h>
#include <stdint.h>
#include <setjmp.h>
#include <arch/thread.h>
+ Include dependency graph for core.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _gid_t
 Definition of a GID. More...
 
struct  _lid_t
 Definition of a LID. More...
 
struct  _msg_t
 Message Type definition. More...
 
struct  _msg_hdr_t
 Message envelope definition. This is used to handle the output queue and stores information needed to generate antimessages. More...
 

Macros

#define master_kernel()   (kid == 0)
 This macro expands to true if the local kernel is the master kernel.
 
#define N_KER_MAX   128
 Maximum number of kernels the distributed simulator can handle.
 
#define MAX_LPs   250000
 Maximum number of LPs the simulator will handle.
 
#define likely(exp)   __builtin_expect(exp, 1)
 Optimize the branch as likely taken.
 
#define unlikely(exp)   __builtin_expect(exp, 0)
 Optimize the branch as likely not taken.
 
#define F_EQUAL(a, b)   (fabsf((a) - (b)) < FLT_EPSILON)
 Equality condition for floats.
 
#define F_EQUAL_ZERO(a)   (fabsf(a) < FLT_EPSILON)
 Equality to zero condition for floats.
 
#define F_DIFFER(a, b)   (fabsf((a) - (b)) >= FLT_EPSILON)
 Difference condition for floats.
 
#define F_DIFFER_ZERO(a)   (fabsf(a) >= FLT_EPSILON)
 Difference from zero condition for floats.
 
#define D_EQUAL(a, b)   (fabs((a) - (b)) < DBL_EPSILON)
 Equality condition for doubles.
 
#define D_EQUAL_ZERO(a)   (fabs(a) < DBL_EPSILON)
 Equality to zero condition for doubles.
 
#define D_DIFFER(a, b)   (fabs((a) - (b)) >= DBL_EPSILON)
 Difference condition for doubles.
 
#define D_DIFFER_ZERO(a)   (fabs(a) >= DBL_EPSILON)
 Difference from zero condition for doubles.
 
#define max(a, b)
 Macro to find the maximum among two values. More...
 
#define min(a, b)
 Macro to find the minimum among two values. More...
 
#define UNION_CAST(x, destType)   (((union {__typeof__(x) a; destType b;})x).b)
 Macro to "legitimately" pun a type.
 
#define is_lid(val)   __builtin_types_compatible_p(__typeof__ (val), LID_t)
 
#define is_gid(val)   __builtin_types_compatible_p(__typeof__ (val), GID_t)
 
#define set_lid(lid, value)   (__builtin_choose_expr(is_lid(lid), lid.to_int, (void)0) = (value))
 
#define set_gid(gid, value)   (__builtin_choose_expr(is_gid(gid), gid.to_int, (void)0) = (value))
 
#define MSG_PADDING   offsetof(msg_t, sender)
 
#define MSG_META_SIZE   (offsetof(msg_t, event_content) - MSG_PADDING)
 
#define rootsim_error(fatal, msg, ...)   _rootsim_error(fatal, "%s:%d: %s(): " msg, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
 

Typedefs

typedef struct _gid_t GID_t
 Definition of a GID. More...
 
typedef struct _lid_t LID_t
 Definition of a LID. More...
 
typedef unsigned char phase_colour
 
typedef struct _msg_t msg_t
 Message Type definition.
 
typedef struct _msg_hdr_t msg_hdr_t
 Message envelope definition. This is used to handle the output queue and stores information needed to generate antimessages.
 

Enumerations

enum  { SNAPSHOT_INVALID = 0, SNAPSHOT_FULL }
 
enum  { VERBOSE_INVALID = 0, VERBOSE_INFO, VERBOSE_DEBUG, VERBOSE_NO }
 
enum  { LP_DISTRIBUTION_INVALID = 0, LP_DISTRIBUTION_BLOCK, LP_DISTRIBUTION_CIRCULAR }
 
enum  message_kind_t { positive, negative, control }
 

Functions

void ProcessEvent_light (unsigned int me, simtime_t now, int event_type, void *event_content, unsigned int size, void *state)
 
bool OnGVT_light (unsigned int me, void *snapshot)
 
void ProcessEvent_inc (unsigned int me, simtime_t now, int event_type, void *event_content, unsigned int size, void *state)
 
bool OnGVT_inc (unsigned int me, void *snapshot)
 
void base_init (void)
 
void base_fini (void)
 
unsigned int find_kernel_by_gid (GID_t gid)
 
void _rootsim_error (bool fatal, const char *msg,...)
 
void distribute_lps_on_kernels (void)
 
void simulation_shutdown (int code)
 
bool user_requested_exit (void)
 
bool simulation_error (void)
 
void initialization_complete (void)
 

Variables

jmp_buf exit_jmp
 
barrier_t all_thread_barrier
 Barrier for all worker threads.
 
unsigned int kid
 Identifier of the local kernel.
 
unsigned int n_ker
 Total number of simulation kernel instances running.
 
unsigned int n_cores
 Total number of cores required for simulation.
 
unsigned int n_prc
 Number of logical processes hosted by the current kernel instance.
 
unsigned int * kernel
 Mapping between kernel instances and logical processes.
 

Detailed Description

Core ROOT-Sim functionalities.

Core ROOT-Sim functionalities

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
Francesco Quaglia
Alessandro Pellegrini
Roberto Vitali
Date
3/18/2011

Definition in file core.h.

Macro Definition Documentation

#define max (   a,
 
)
Value:
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })

Macro to find the maximum among two values.

Definition at line 106 of file core.h.

#define min (   a,
 
)
Value:
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })

Macro to find the minimum among two values.

Definition at line 115 of file core.h.

Typedef Documentation

typedef struct _gid_t GID_t

Definition of a GID.

This structure defines a GID. The purpose of this structure is to make functions dealing with GIDs and LIDs type safe, to avoid runtime problems if the two are mixed when calling a function.

typedef struct _lid_t LID_t

Definition of a LID.

This structure defines a LID. The purpose of this structure is to make functions dealing with GIDs and LIDs type safe, to avoid runtime problems if the two are mixed when calling a function.

Enumeration Type Documentation

anonymous enum
Enumerator
SNAPSHOT_INVALID 

By convention 0 is the invalid field

SNAPSHOT_FULL 

xxx documentation

Definition at line 50 of file core.h.

anonymous enum
Enumerator
VERBOSE_INVALID 

By convention 0 is the invalid field

VERBOSE_INFO 

xxx documentation

VERBOSE_DEBUG 

xxx documentation

VERBOSE_NO 

xxx documentation

Definition at line 62 of file core.h.

anonymous enum
Enumerator
LP_DISTRIBUTION_INVALID 

By convention 0 is the invalid field

LP_DISTRIBUTION_BLOCK 

Distribute exceeding LPs according to a block policy

LP_DISTRIBUTION_CIRCULAR 

Distribute exceeding LPs according to a circular policy

Definition at line 77 of file core.h.

Function Documentation

void _rootsim_error ( bool  fatal,
const char *  msg,
  ... 
)

A variadic function which prints out error messages. If the errors are marked as fatal, the simulation is correctly shut down.

Author
Alessandro Pellegrini
Parameters
fatalThis flag marks an error as fatal (true) or not (false)
msgThe error message to be printed out. This can be specified as in the printf() format message, thus a matching number of extra parameters can be passed.

Definition at line 220 of file core.c.

void base_fini ( void  )

This function finalizes the core structures of ROOT-Sim, just before terminating a simulation

Author
Roberto Vitali

Definition at line 151 of file core.c.

+ Here is the caller graph for this function:

void base_init ( void  )

This function initilizes basic functionalities within ROOT-Sim. In particular, it creates a mapping between logical processes and kernel instances.

Author
Francesco Quaglia
Roberto Vitali
Alessandro Pellegrini

Definition at line 129 of file core.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void distribute_lps_on_kernels ( void  )

This function maps logical processes onto kernel instances

Author
Francesco Quaglia
Alessandro Pellegrini

Definition at line 258 of file core.c.

unsigned int find_kernel_by_gid ( GID_t  gid)

Creates a mapping between logical processes and kernel instances

Author
Francesco Quaglia
Parameters
gidThe logical process' global identifier
Returns
The id of the kernel currently hosting the logical process

Definition at line 164 of file core.c.

+ Here is the caller graph for this function:

void initialization_complete ( void  )

This function records that the initialization is complete.

Definition at line 316 of file core.c.

+ Here is the caller graph for this function:

void simulation_shutdown ( int  code)

This function calls all the finalization functions exposed by subsystems and then exits.

Author
Alessandro Pellegrini
Parameters
codeThe exit code to be returned by the process

Definition at line 178 of file core.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

jmp_buf exit_jmp

This jump buffer allows rootsim_error, in case of a failure, to jump out of any point in the code to the final part of the loop in which all threads synchronize. This avoids side effects like, e.g., accessing a NULL pointer.

Definition at line 62 of file main.c.