Parallel processing, semaphores
[libbu (utility functions)]

Collaboration diagram for Parallel processing, semaphores:


Files

file  ispar.c
 subroutine to determine if we are multi-threaded
file  parallel.c
 routines for parallel processing
file  semaphore.c
 semaphore implementation

Defines

#define PUBLIC_CPUS1   "/var/tmp/public_cpus"
#define PUBLIC_CPUS2   "/usr/tmp/public_cpus"
#define BU_SEMAPHORE_MAGIC   0x62757365

Functions

int bu_is_parallel ()
void bu_kill_parallel ()
void bu_nice_set (int newnice)
int bu_cpulimit_get ()
void bu_cpulimit_set (int sec)
int bu_avail_cpus ()
fastf_t bu_get_load_average ()
int bu_get_public_cpus ()
int bu_set_realtime ()
void bu_parallel (void(*func)(), int ncpu, genptr_t arg)
void bu_semaphore_init (unsigned int nsemaphores)
void bu_semaphore_acquire (unsigned int i)
void bu_semaphore_release (unsigned int i)
void bu_parallel (void *func, int ncpu, genptr_t arg)

Variables

int bu_pid_of_initiating_thread = 0

Define Documentation

#define PUBLIC_CPUS1   "/var/tmp/public_cpus"
 

B U _ G E T _ P U B L I C _ C P U S

A general mechanism for non-privleged users of a server system to control how many processors of their server get consumed by multi-thread cruncher processes, by leaving a world-writable file.

If the number in the file is negative, it means "all but that many."

Returns the number of processors presently available for "public" use.

Definition at line 564 of file parallel.c.

Referenced by bu_get_public_cpus().

#define PUBLIC_CPUS2   "/usr/tmp/public_cpus"
 

Definition at line 565 of file parallel.c.

Referenced by bu_get_public_cpus().

#define BU_SEMAPHORE_MAGIC   0x62757365
 

Definition at line 188 of file semaphore.c.

Referenced by bu_semaphore_acquire(), bu_semaphore_init(), and bu_semaphore_release().


Function Documentation

int bu_is_parallel void   ) 
 

B U _ I S _ P A R A L L E L

A clean way for bu_bomb() to tell if this is a parallel application. If bu_parallel() is active, this routine will return non-zero.

Definition at line 70 of file ispar.c.

References bu_pid_of_initiating_thread.

Referenced by bn_catch_FPE(), bn_poly_cubic_roots(), bu_bomb(), and rt_submodel_wireframe_leaf().

void bu_kill_parallel void   ) 
 

B U _ K I L L _ P A R A L L E L

Used by bu_bomb() to help terminate parallel threads, without dragging in the whole parallel library if it isn't being used.

Definition at line 83 of file ispar.c.

References bu_pid_of_initiating_thread, and void().

Referenced by bu_bomb().

Here is the call graph for this function:

void bu_nice_set int  newnice  ) 
 

B U _ N I C E _ S E T

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 212 of file parallel.c.

References bu_debug, bu_log(), and void().

Here is the call graph for this function:

int bu_cpulimit_get void   ) 
 

B U _ C P U L I M I T _ G E T

Return the current CPU limit, in seconds. Zero or negative return indicates that limits are not in effect.

Definition at line 258 of file parallel.c.

References HZ, and perror().

Referenced by bu_cpulimit_set().

Here is the call graph for this function:

void bu_cpulimit_set int  sec  ) 
 

B U _ C P U L I M I T _ S E T

Set CPU time limit, in seconds.

Definition at line 282 of file parallel.c.

References bu_cpulimit_get(), bu_log(), HZ, and perror().

Here is the call graph for this function:

int bu_avail_cpus void   ) 
 

B U _ A V A I L _ C P U S

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

Definition at line 319 of file parallel.c.

References bu_bomb(), bu_debug, BU_DEBUG_PARALLEL, DEFAULT_PSW, fp, int, NULL, perror(), and status.

Referenced by bu_get_public_cpus(), bu_parallel(), and Rt_Init().

Here is the call graph for this function:

fastf_t bu_get_load_average void   ) 
 

B U _ G E T _ L O A D _ A V E R A G E

A generally portable method for obtaining the 1-minute load average. Vendor-specific methods which don't involve a fork/exec sequence would be preferable. Alas, very very few systems put the load average in /proc, most still grunge the avenrun[3] array out of /dev/kmem, which requires special privleges to open.

Definition at line 534 of file parallel.c.

References fp, and NULL.

int bu_get_public_cpus  ) 
 

Definition at line 568 of file parallel.c.

References bu_avail_cpus(), chmod(), fp, NULL, PUBLIC_CPUS1, PUBLIC_CPUS2, and void().

Here is the call graph for this function:

int bu_set_realtime void   ) 
 

B U _ S E T _ R E A L T I M E

If possible, mark this process for real-time scheduler priority. Will often need root privs to succeed.

Returns - 1 realtime priority obtained 0 running with non-realtime scheduler behavior

Definition at line 610 of file parallel.c.

void bu_parallel void(*)()  func,
int  ncpu,
genptr_t  arg
 

Referenced by rt_cut_it().

void bu_semaphore_init unsigned int  nsemaphores  ) 
 

B U _ S E M A P H O R E _ I N I T

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 269 of file semaphore.c.

References BU_SEMAPHORE_MAGIC, calloc(), and void().

Referenced by Rt_Init().

Here is the call graph for this function:

void bu_semaphore_acquire unsigned int  i  ) 
 

B U _ S E M A P H O R E _ A C Q U I R E

Definition at line 377 of file semaphore.c.

References BU_CKMAG, BU_SEMAPHORE_MAGIC, NULL, and void().

Referenced by bn_noise_init(), bn_print_table_and_tabdata(), bn_read_table_and_tabdata(), bn_tabdata_binary_read(), bn_table_read(), bn_table_write(), bu_close_mapped_file(), bu_flog(), bu_fopen_uniq(), bu_free(), bu_free_mapped_files(), bu_list_parallel_append(), bu_list_parallel_dequeue(), bu_log(), bu_mem_barriercheck(), bu_memdebug_add(), bu_memdebug_check(), bu_open_mapped_file(), bu_realloc(), bu_strdupm(), bu_struct_get(), bu_vls_fwrite(), bu_vls_gets(), bu_vls_read(), bu_vls_write(), db_close(), db_read(), db_shader_mat(), db_sync(), db_walk_dispatcher(), db_write(), dgo_drawH_part2(), rt_arb_uv(), rt_ct_free(), rt_ct_get(), rt_cut_optimize_parallel(), rt_dsp_norm(), rt_dsp_prep(), rt_ebm_import(), rt_ebm_import5(), rt_find_identical_solid(), rt_hf_import(), rt_hf_prep(), rt_prealloc(), rt_prep_parallel(), rt_shoot_many_rays_worker(), rt_submodel_prep(), rt_vol_import(), rt_vol_import5(), spm_load(), spm_px_load(), spm_px_save(), and spm_save().

Here is the call graph for this function:

void bu_semaphore_release unsigned int  i  ) 
 

B U _ S E M A P H O R E _ R E L E A S E

Definition at line 448 of file semaphore.c.

References BU_CKMAG, BU_SEMAPHORE_MAGIC, NULL, and void().

Referenced by bn_noise_init(), bn_print_table_and_tabdata(), bn_read_table_and_tabdata(), bn_tabdata_binary_read(), bn_table_read(), bn_table_write(), bu_close_mapped_file(), bu_flog(), bu_fopen_uniq(), bu_free(), bu_free_mapped_files(), bu_list_parallel_append(), bu_list_parallel_dequeue(), bu_log(), bu_mem_barriercheck(), bu_memdebug_add(), bu_memdebug_check(), bu_open_mapped_file(), bu_realloc(), bu_strdupm(), bu_struct_get(), bu_vls_fwrite(), bu_vls_gets(), bu_vls_read(), bu_vls_write(), db_close(), db_read(), db_shader_mat(), db_sync(), db_walk_dispatcher(), db_write(), dgo_drawH_part2(), rt_arb_uv(), rt_ct_free(), rt_ct_get(), rt_cut_optimize_parallel(), rt_dsp_norm(), rt_dsp_prep(), rt_ebm_import(), rt_ebm_import5(), rt_find_identical_solid(), rt_hf_import(), rt_hf_prep(), rt_prealloc(), rt_prep_parallel(), rt_shoot_many_rays_worker(), rt_submodel_prep(), rt_vol_import(), rt_vol_import5(), spm_load(), spm_px_load(), spm_px_save(), and spm_save().

Here is the call graph for this function:

void bu_parallel void *  func,
int  ncpu,
genptr_t  arg
 

B U _ P A R A L L E L

Create 'ncpu' copies of function 'func' all running in parallel, with private stack areas. Locking and work dispatching are handled by 'func' using a "self-dispatching" paradigm.

'func' is called with one parameter, it's thread number. Threads are given increasing numbers, starting with zero.

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

Don't use registers in this function (bu_parallel). At least on the Alliant, register context is NOT preserved when exiting the parallel mode, because the serial portion resumes on some arbitrary processor, not necessarily the one that serial execution started on. The registers are not shared.

Definition at line 789 of file parallel.c.

References bu_avail_cpus(), bu_bomb(), bu_debug, BU_DEBUG_PARALLEL, bu_log(), and bzero.

Here is the call graph for this function:


Variable Documentation

int bu_pid_of_initiating_thread = 0
 

don't declare in include/bu.h

Definition at line 61 of file ispar.c.

Referenced by bu_is_parallel(), and bu_kill_parallel().


Generated on Mon Sep 18 01:25:20 2006 for BRL-CAD by  doxygen 1.4.6