BRL-CAD
Collaboration diagram for Multithreading:

Files

file  parallel.c
 
file  kill.c
 
file  process.c
 
file  parallel.c
 
file  semaphore.c
 

Macros

#define MAX_PSW   1024
 
#define BU_SEM_SYSCALL   0
 
#define BU_SEM_LISTS   1
 
#define BU_SEM_BN_NOISE   2
 
#define BU_SEM_MAPPEDFILE   3
 
#define BU_SEM_THREAD   4
 
#define BU_SEM_MALLOC   5
 
#define BU_SEM_DATETIME   6
 
#define BU_SEM_LAST   (BU_SEM_DATETIME+1) /* allocate this many for LIBBU+LIBBN */
 
#define BU_SETJUMP   setjmp((bu_setjmp_valid[bu_parallel_id()]=1, bu_jmpbuf[bu_parallel_id()]))
 
#define BU_UNSETJUMP   (bu_setjmp_valid[bu_parallel_id()]=0)
 

Functions

DEPRECATED int bu_is_parallel (void)
 
int bu_parallel_id (void)
 
int bu_terminate (int process)
 
int bu_process_id (void)
 
void bu_nice_set (int newnice)
 
size_t bu_avail_cpus (void)
 
void bu_parallel (void(*func)(int func_ncpu, void *func_data), int ncpu, void *data)
 
void bu_semaphore_init (unsigned int nsemaphores)
 
void bu_semaphore_free (void)
 
void bu_semaphore_acquire (unsigned int i)
 
void bu_semaphore_release (unsigned int i)
 

Variables

int bu_setjmp_valid [MAX_PSW]
 
jmp_buf bu_jmpbuf [MAX_PSW]
 

Detailed Description

Macro Definition Documentation

#define MAX_PSW   1024

MAX_PSW - The maximum number of processors that can be expected on this hardware. Used to allocate application-specific per-processor tables at compile-time and represent a hard limit on the number of processors/threads that may be spawned. The actual number of available processors is found at runtime by calling bu_avail_cpus()

Definition at line 48 of file parallel.h.

Referenced by bu_parallel(), BuildPhotonMap(), ged_gqa(), main(), nmg_mc_evaluate(), rt_init_resource(), rt_new_rti(), rt_shoot_many_rays_worker(), and tcl_setup().

#define BU_SEM_LISTS   1

Definition at line 179 of file parallel.h.

Referenced by bu_list_parallel_append(), bu_list_parallel_dequeue(), and db_close().

#define BU_SEM_BN_NOISE   2

Definition at line 180 of file parallel.h.

Referenced by bn_noise_init(), and find_spec_wgt().

#define BU_SEM_MAPPEDFILE   3
#define BU_SEM_THREAD   4

Definition at line 182 of file parallel.h.

Referenced by bu_parallel().

#define BU_SEM_MALLOC   5
#define BU_SEM_DATETIME   6

Definition at line 184 of file parallel.h.

Referenced by bu_utctime().

#define BU_SEM_LAST   (BU_SEM_DATETIME+1) /* allocate this many for LIBBU+LIBBN */

Definition at line 185 of file parallel.h.

#define BU_SETJUMP   setjmp((bu_setjmp_valid[bu_parallel_id()]=1, bu_jmpbuf[bu_parallel_id()]))
#define BU_UNSETJUMP   (bu_setjmp_valid[bu_parallel_id()]=0)

Function Documentation

DEPRECATED int bu_is_parallel ( void  )

This routine is DEPRECATED, do not use it. If you need a means to determine when an application is running bu_parallel(), please report this to our developers.

Previously, this was a library-stateful way for bu_bomb() to tell if a parallel application is running. This routine now simply returns zero all the time, which permits BU_SETJUMP() error handling during bu_bomb().

Definition at line 159 of file parallel.c.

int bu_parallel_id ( void  )

returns the CPU number of the current bu_parallel() invoked thread.

Definition at line 152 of file parallel.c.

References thread_get_cpu().

Referenced by bu_bomb(), bu_crashreport(), bu_heap_get(), bu_parallel(), brlcad::hasSplit(), and surface_GetBoundingBox().

Here is the call graph for this function:

int bu_terminate ( int  process)

terminate a given process.

returns truthfully whether the process could be killed.

Definition at line 37 of file kill.c.

References TRUE.

Referenced by ged_rtabort().

int bu_process_id ( void  )

returns the process ID of the calling process

Definition at line 31 of file process.c.

Referenced by bu_backtrace(), bu_bomb(), and bu_crashreport().

void bu_nice_set ( int  newnice)

Without knowing what the current UNIX "nice" value is, change to a new absolute "nice" value. (The system routine makes a relative change).

Definition at line 167 of file parallel.c.

References bu_debug, bu_log(), and UNLIKELY.

Here is the call graph for this function:

size_t bu_avail_cpus ( void  )

Return the maximum number of physical CPUs that are considered to be available to this process now.

Definition at line 193 of file parallel.c.

References bu_bomb(), bu_debug, BU_DEBUG_PARALLEL, bu_fgets(), bu_strncmp(), LIKELY, and UNLIKELY.

Referenced by bu_parallel(), ged_gqa(), main(), nmg_mc_evaluate(), parallel_set_affinity(), and Rt_Init().

Here is the call graph for this function:

void bu_parallel ( void(*)(int func_ncpu, void *func_data)  func,
int  ncpu,
void *  data 
)

Create parallel threads of execution.

This function creates (at most) 'ncpu' copies of function 'func' all running in parallel, passing 'data' to each invocation. Specifying ncpu=0 will specify automatic parallelization, invoking parallel threads as cores become available. This is particularly useful during recursive invocations where the ncpu core count is limited by the parent context.

Locking and work dispatching are handled by 'func' using a "self-dispatching" paradigm. This means you must manually protect shared data structures, e.g., via BU_SEMAPHORE_ACQUIRE(). Lock-free execution is often possible by creating data containers with MAX_PSW elements as bu_parallel will never execute more than that many threads of execution.

All invocations of the specified 'func' callback function are passed two parameters: 1) it's assigned thread number and 2) a shared 'data' pointer for application use. Threads are assigned increasing numbers, starting with zero. Processes may also call bu_parallel_id() to obtain their thread number.

Threads created with bu_parallel() may specify utilization of affinity locking to keep threads on a given physical CPU core. This behavior can be enabled at runtime by setting the environment variable LIBBU_AFFINITY=1. Note that this option may increase or even decrease performance, particularly on platforms with advanced scheduling, so testing is recommended.

This function will not return control until all invocations of the subroutine are finished.

Referenced by brep_build_bvh(), BuildPhotonMap(), db_walk_tree(), ged_gqa(), main(), nmg_mc_evaluate(), rt_cut_it(), and rt_shoot_many_rays().

void bu_semaphore_init ( unsigned int  nsemaphores)

Prepare 'nsemaphores' independent critical section semaphores. Die on error.

Takes the place of 'n' separate calls to old RES_INIT(). Start by allocating array of "struct bu_semaphores", which has been arranged to contain whatever this system needs.

Definition at line 82 of file semaphore.c.

References bu_bomb(), memset(), SEMAPHORE_MAGIC, SEMAPHORE_MAX, and UNLIKELY.

Referenced by bu_semaphore_acquire(), and bu_semaphore_release().

Here is the call graph for this function:

void bu_semaphore_free ( void  )

Release all initialized semaphores and any associated memory.

Definition at line 144 of file semaphore.c.

void bu_semaphore_acquire ( unsigned int  i)

Definition at line 180 of file semaphore.c.

References bu_bomb(), BU_CKMAG, bu_semaphore_init(), and SEMAPHORE_MAGIC.

Referenced by _db_walk_dispatcher(), _rt_find_identical_solid(), _rt_gettree_region_end(), add_unique_pair(), alloc(), append_solid_to_display_list(), bn_noise_init(), bn_print_table_and_tabdata(), bn_read_table_and_tabdata(), bn_spm_load(), bn_spm_pix_load(), bn_spm_pix_save(), bn_spm_save(), bn_tabdata_binary_read(), bn_table_read(), bn_table_write(), bu_bomb(), bu_close_mapped_file(), bu_flog(), bu_free(), bu_free_mapped_files(), bu_getprogname(), bu_list_parallel_append(), bu_list_parallel_dequeue(), bu_log(), bu_mem_barriercheck(), bu_open_mapped_file(), bu_parallel(), bu_realloc(), bu_setprogname(), bu_strdupm(), bu_strlcatm(), bu_strlcpym(), bu_struct_get(), bu_utctime(), bu_vls_fwrite(), bu_vls_read(), bu_vls_write(), BuildIrradianceCache(), db_close(), db_read(), db_sync(), db_write(), dl_add_path(), exposed_air(), find_spec_wgt(), get_next_row(), grass_render(), hit(), isect_ray_triangle(), memdebug_add(), memdebug_check(), nmg_mc_realize_cube(), osl_render(), overlap(), plane_worker(), plot_cell_top(), plot_layers(), plot_seg(), prj_free(), rr_render(), rt_arb_uv(), rt_ct_free(), rt_ct_get(), rt_cut_optimize_parallel(), rt_dsp_bbox(), rt_dsp_norm(), rt_dsp_prep(), rt_ebm_import4(), rt_ebm_import5(), rt_hf_import4(), rt_hf_prep(), rt_prep_parallel(), rt_shader_mat(), rt_shoot_many_rays_worker(), rt_submodel_prep(), rt_vol_import4(), rt_vol_import5(), shade_inputs(), and surface_GetBoundingBox().

Here is the call graph for this function:

void bu_semaphore_release ( unsigned int  i)

Definition at line 218 of file semaphore.c.

References bu_bomb(), BU_CKMAG, bu_semaphore_init(), and SEMAPHORE_MAGIC.

Referenced by _db_walk_dispatcher(), _rt_find_identical_solid(), _rt_gettree_region_end(), add_unique_pair(), alloc(), append_solid_to_display_list(), bn_noise_init(), bn_print_table_and_tabdata(), bn_read_table_and_tabdata(), bn_spm_load(), bn_spm_pix_load(), bn_spm_pix_save(), bn_spm_save(), bn_tabdata_binary_read(), bn_table_read(), bn_table_write(), bu_bomb(), bu_close_mapped_file(), bu_flog(), bu_free(), bu_free_mapped_files(), bu_getprogname(), bu_list_parallel_append(), bu_list_parallel_dequeue(), bu_log(), bu_mem_barriercheck(), bu_open_mapped_file(), bu_parallel(), bu_realloc(), bu_setprogname(), bu_strdupm(), bu_strlcatm(), bu_strlcpym(), bu_struct_get(), bu_utctime(), bu_vls_fwrite(), bu_vls_read(), bu_vls_write(), BuildIrradianceCache(), db_close(), db_read(), db_sync(), db_write(), dl_add_path(), exposed_air(), find_spec_wgt(), get_next_row(), grass_render(), hit(), isect_ray_triangle(), memdebug_add(), memdebug_check(), nmg_mc_realize_cube(), osl_render(), overlap(), plane_worker(), plot_cell_top(), plot_layers(), plot_seg(), prj_free(), rr_render(), rt_arb_uv(), rt_ct_free(), rt_ct_get(), rt_cut_optimize_parallel(), rt_dsp_bbox(), rt_dsp_norm(), rt_dsp_prep(), rt_ebm_import4(), rt_ebm_import5(), rt_hf_import4(), rt_hf_prep(), rt_prep_parallel(), rt_shader_mat(), rt_shoot_many_rays_worker(), rt_submodel_prep(), rt_vol_import4(), rt_vol_import5(), shade_inputs(), and surface_GetBoundingBox().

Here is the call graph for this function:

Variable Documentation

int bu_setjmp_valid[MAX_PSW]

Marker for knowing if an exception handler is set. bu_setjmp_valid is global array because BU_SETJUMP() must be a macro (jump calls must be embedded into the frame they return to).

If you replace bu_bomb() with one of your own, you must also provide these variables, even if you don't use them.

Definition at line 74 of file globals.c.

Referenced by bu_bomb().

jmp_buf bu_jmpbuf[MAX_PSW]

Exception handling contexts used by BU_SETJUMP(). bu_jmpbuf is a global array because BU_SETJUMP() must be a macro (jump calls must be embedded into the frame they return to).

If you replace bu_bomb() with one of your own, you must also provide these variables, even if you don't use them.

Definition at line 84 of file globals.c.

Referenced by bu_bomb().