SimGrid  3.14.159
Versatile Simulation of Distributed Systems
smx_context.cpp File Reference
#include <cerrno>
#include <cstring>
#include <utility>
#include <string>
#include <xbt/config.hpp>
#include <xbt/log.h>
#include <xbt/range.hpp>
#include <xbt/sysdep.h>
#include "src/internal_config.h"
#include "xbt/swag.h"
#include "xbt/xbt_os_thread.h"
#include "smx_private.h"
#include "simgrid/sg_config.h"
#include "simgrid/modelchecker.h"
#include <sys/mman.h>

Functions

 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (simix_context, simix, "Context switching mechanism")
 
static std::string contexts_list ()
 
void SIMIX_context_mod_init ()
 This function is called by SIMIX_global_init() to initialize the context module. More...
 
void SIMIX_context_mod_exit ()
 This function is called by SIMIX_clean() to finalize the context module. More...
 
voidSIMIX_context_stack_new ()
 
void SIMIX_context_stack_delete (void *stack)
 
int SIMIX_context_is_parallel ()
 Returns whether some parallel threads are used for the user contexts. More...
 
int SIMIX_context_get_nthreads ()
 Returns the number of parallel threads used for the user contexts. More...
 
void SIMIX_context_set_nthreads (int nb_threads)
 Sets the number of parallel threads to use for the user contexts. More...
 
int SIMIX_context_get_parallel_threshold ()
 Returns the threshold above which user processes are run in parallel. More...
 
void SIMIX_context_set_parallel_threshold (int threshold)
 Sets the threshold above which user processes are run in parallel. More...
 
e_xbt_parmap_mode_t SIMIX_context_get_parallel_mode ()
 Returns the synchronization mode used when processes are run in parallel. More...
 
void SIMIX_context_set_parallel_mode (e_xbt_parmap_mode_t mode)
 Sets the synchronization mode to use when processes are run in parallel. More...
 
smx_context_t SIMIX_context_get_current ()
 Returns the current context of this thread. More...
 
void SIMIX_context_set_current (smx_context_t context)
 Sets the current context of this thread. More...
 

Variables

static std::pair< const char *, simgrid::kernel::context::ContextFactoryInitializercontext_factories []
 
static simgrid::config::Flag< std::stringcontext_factory_name ("contexts/factory",(std::string("Possible values: ")+contexts_list()).c_str(), context_factories[0].first)
 
int smx_context_stack_size
 
int smx_context_stack_size_was_set = 0
 
int smx_context_guard_size
 
int smx_context_guard_size_was_set = 0
 
static xbt_os_thread_key_t smx_current_context_key = 0
 
static smx_context_t smx_current_context_serial
 
static int smx_parallel_contexts = 1
 
static int smx_parallel_threshold = 2
 
static e_xbt_parmap_mode_t smx_parallel_synchronization_mode = XBT_PARMAP_DEFAULT
 

Function Documentation

§ XBT_LOG_NEW_DEFAULT_SUBCATEGORY()

XBT_LOG_NEW_DEFAULT_SUBCATEGORY ( simix_context  ,
simix  ,
"Context switching mechanism"   
)

§ contexts_list()

static std::string contexts_list ( )
inlinestatic

§ SIMIX_context_mod_init()

void SIMIX_context_mod_init ( )

This function is called by SIMIX_global_init() to initialize the context module.

§ SIMIX_context_mod_exit()

void SIMIX_context_mod_exit ( )

This function is called by SIMIX_clean() to finalize the context module.

§ SIMIX_context_stack_new()

void* SIMIX_context_stack_new ( )

§ SIMIX_context_stack_delete()

void SIMIX_context_stack_delete ( void stack)

§ SIMIX_context_is_parallel()

int SIMIX_context_is_parallel ( )

Returns whether some parallel threads are used for the user contexts.

§ SIMIX_context_get_nthreads()

int SIMIX_context_get_nthreads ( )

Returns the number of parallel threads used for the user contexts.

Returns
the number of threads (1 means no parallelism)

§ SIMIX_context_set_nthreads()

void SIMIX_context_set_nthreads ( int  nb_threads)

Sets the number of parallel threads to use for the user contexts.

This function should be called before initializing SIMIX. A value of 1 means no parallelism (1 thread only). If the value is greater than 1, the thread support must be enabled.

Parameters
nb_threadsthe number of threads to use

§ SIMIX_context_get_parallel_threshold()

int SIMIX_context_get_parallel_threshold ( )

Returns the threshold above which user processes are run in parallel.

If the number of threads is set to 1, there is no parallelism and this threshold has no effect.

Returns
when the number of user processes ready to run is above this threshold, they are run in parallel

§ SIMIX_context_set_parallel_threshold()

void SIMIX_context_set_parallel_threshold ( int  threshold)

Sets the threshold above which user processes are run in parallel.

If the number of threads is set to 1, there is no parallelism and this threshold has no effect.

Parameters
thresholdwhen the number of user processes ready to run is above this threshold, they are run in parallel

§ SIMIX_context_get_parallel_mode()

e_xbt_parmap_mode_t SIMIX_context_get_parallel_mode ( )

Returns the synchronization mode used when processes are run in parallel.

Returns
how threads are synchronized if processes are run in parallel

§ SIMIX_context_set_parallel_mode()

void SIMIX_context_set_parallel_mode ( e_xbt_parmap_mode_t  mode)

Sets the synchronization mode to use when processes are run in parallel.

Parameters
modehow to synchronize threads if processes are run in parallel

§ SIMIX_context_get_current()

smx_context_t SIMIX_context_get_current ( )

Returns the current context of this thread.

Returns
the current context of this thread

§ SIMIX_context_set_current()

void SIMIX_context_set_current ( smx_context_t  context)

Sets the current context of this thread.

Parameters
contextthe context to set

Variable Documentation

§ context_factories

std::pair<const char*, simgrid::kernel::context::ContextFactoryInitializer> context_factories[]
static
Initial value:
= {
}

§ context_factory_name

simgrid::config::Flag<std::string> context_factory_name("contexts/factory",(std::string("Possible values: ")+contexts_list()).c_str(), context_factories[0].first)
static

§ smx_context_stack_size

int smx_context_stack_size

§ smx_context_stack_size_was_set

int smx_context_stack_size_was_set = 0

§ smx_context_guard_size

int smx_context_guard_size

§ smx_context_guard_size_was_set

int smx_context_guard_size_was_set = 0

§ smx_current_context_key

xbt_os_thread_key_t smx_current_context_key = 0
static

§ smx_current_context_serial

smx_context_t smx_current_context_serial
static

§ smx_parallel_contexts

int smx_parallel_contexts = 1
static

§ smx_parallel_threshold

int smx_parallel_threshold = 2
static

§ smx_parallel_synchronization_mode

e_xbt_parmap_mode_t smx_parallel_synchronization_mode = XBT_PARMAP_DEFAULT
static