BRL-CAD
many.c File Reference
#include "common.h"
#include <math.h>
#include "bio.h"
#include "bu/parallel.h"
#include "vmath.h"
#include "bn.h"
#include "raytrace.h"
Include dependency graph for many.c:

Go to the source code of this file.

Data Structures

struct  rt_many_internal
 

Macros

#define RT_MANY_INTERNAL_MAGIC   0x526d6970 /* Rmip */
 
#define RT_CK_RMI(_p)   BU_CKMAG(_p, RT_MANY_INTERNAL_MAGIC, "rt_many_internal")
 

Functions

void rt_shoot_many_rays_worker (int cpu, void *arg)
 
void rt_shoot_many_rays (const struct application *proto_ap, int(*callback)(struct application *, int), int ncpus, long int nrays, struct resource *resources)
 

Detailed Description

Wrapper routines to help fire multiple rays in parallel, without exposing the caller to the details of running in parallel.

Definition in file many.c.

Macro Definition Documentation

#define RT_MANY_INTERNAL_MAGIC   0x526d6970 /* Rmip */

Definition at line 53 of file many.c.

Referenced by rt_shoot_many_rays().

#define RT_CK_RMI (   _p)    BU_CKMAG(_p, RT_MANY_INTERNAL_MAGIC, "rt_many_internal")

Definition at line 54 of file many.c.

Referenced by rt_shoot_many_rays_worker().

Function Documentation

void rt_shoot_many_rays_worker ( int  cpu,
void *  arg 
)

Internal helper routine for rt_shoot_many_rays().

Runs in PARALLEL, one instance per thread.

In order to reduce the traffic through the critical section, a multiple pixel block may be removed from the work queue at once.

Definition at line 65 of file many.c.

References application::a_resource, application::a_x, bu_bomb(), bu_log(), bu_semaphore_acquire(), bu_semaphore_release(), rt_many_internal::callback, rt_many_internal::cur_index, rt_many_internal::max_index, MAX_PSW, rt_many_internal::proto_ap, rt_many_internal::resources, RT_CK_APPLICATION, RT_CK_RESOURCE, RT_CK_RMI, RT_SEM_WORKER, rt_shootray(), rt_many_internal::sem_chunk, and rt_many_internal::stop_worker.

Referenced by rt_shoot_many_rays().

Here is the call graph for this function:

void rt_shoot_many_rays ( const struct application proto_ap,
int(*)(struct application *, int)  callback,
int  ncpus,
long int  nrays,
struct resource resources 
)

A convenience routine for application developers who wish to fire a large but fixed number of rays in parallel, without wanting to create a parallel "self dispatcher" routine of their own.

Basic setup of the application structure is done by the caller, and provided via the proto_ap pointer.

Per-ray setup of the application structure is done by the callback routine, which takes an index in the range 0..(nrays-1) and uses that to fill in each specific instance of application structure as required.

The a_hit() and a_miss() routines must save any results; their formal return codes, and the return code from rt_shootray(), are ignored.

a_x is changed by this wrapper, and may be overridden by the callback.

Note that the cost of spawning threads is sufficiently expensive that 'nrays' should be at least dozens or hundreds to get a real benefit from parallelism.

Return codes expected from the callback() - -1 End processing before all nrays have been fired. 0 Normal return, proceed with firing the ray.

Note that bu_parallel() is not re-entrant, so you can't have an a_hit() routine which is already running in parallel call into this routine and expect to get even more parallelism. This is not a limitation, as you usually can't construct more CPUs.

resources[ncpus]

Definition at line 152 of file many.c.

References bu_parallel(), rt_many_internal::callback, rt_many_internal::cur_index, rt_many_internal::magic, rt_many_internal::max_index, rt_many_internal::proto_ap, rt_many_internal::resources, RT_CK_APPLICATION, RT_CK_RESOURCE, RT_MANY_INTERNAL_MAGIC, rt_shoot_many_rays_worker(), RTG, rt_g::rtg_parallel, rt_many_internal::sem_chunk, and rt_many_internal::stop_worker.

Here is the call graph for this function: