BRL-CAD
resource.h
Go to the documentation of this file.
1 /* R E S O U R C E . H
2  * BRL-CAD
3  *
4  * Copyright (c) 1993-2024 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup rt_resource
21  * @brief
22  * Per-CPU statistics and resources.
23  */
24 /** @{ */
25 /** @file resource.h */
26 
27 #ifndef RT_RESOURCE_H
28 #define RT_RESOURCE_H
29 
30 #include "common.h"
31 #include "vmath.h"
32 #include "bu/list.h"
33 #include "bu/ptbl.h"
34 #include "rt/defines.h"
35 #include "rt/tree.h"
36 #include "rt/directory.h"
37 
38 __BEGIN_DECLS
39 
40 /**
41  * One of these structures is needed per thread of execution, usually
42  * with calling applications creating an array with at least MAX_PSW
43  * elements. To prevent excessive competition for free structures,
44  * memory is now allocated on a per-processor basis. The application
45  * structure a_resource element specifies the resource structure to be
46  * used; if uniprocessing, a null a_resource pointer results in using
47  * the internal global structure (&rt_uniresource), making initial
48  * application development simpler.
49  *
50  * Note that if multiple models are being used, the partition and bitv
51  * structures (which are variable length) will require there to be
52  * ncpus * nmodels resource structures, the selection of which will be
53  * the responsibility of the application.
54  *
55  * Applications are responsible for calling rt_init_resource() on each
56  * resource structure before letting LIBRT use them.
57  *
58  * Per-processor statistics are initially collected in here, and then
59  * posted to rt_i by rt_add_res_stats().
60  */
61 struct resource {
62  uint32_t re_magic; /**< @brief Magic number */
63  int re_cpu; /**< @brief processor number, for ID */
64  struct bu_list re_seg; /**< @brief Head of segment freelist */
65  struct bu_ptbl re_seg_blocks; /**< @brief Table of malloc'ed blocks of segs */
66  long re_seglen;
67  long re_segget;
68  long re_segfree;
69  struct bu_list re_parthead; /**< @brief Head of freelist */
70  long re_partlen;
71  long re_partget;
73  struct bu_list re_solid_bitv; /**< @brief head of freelist */
74  struct bu_list re_region_ptbl; /**< @brief head of freelist */
75  struct bu_list re_nmgfree; /**< @brief head of NMG hitmiss freelist */
76  union tree ** re_boolstack; /**< @brief Stack for rt_booleval() */
77  long re_boolslen; /**< @brief # elements in re_boolstack[] */
78  float * re_randptr; /**< @brief ptr into random number table */
79  /* Statistics. Only for examination by rt_add_res_stats() */
80  long re_nshootray; /**< @brief Calls to rt_shootray() */
81  long re_nmiss_model; /**< @brief Rays pruned by model RPP */
82  /* Solid nshots = shot_hit + shot_miss */
83  long re_shots; /**< @brief # calls to ft_shot() */
84  long re_shot_hit; /**< @brief ft_shot() returned a miss */
85  long re_shot_miss; /**< @brief ft_shot() returned a hit */
86  /* Optimizations. Rays not shot at solids */
87  long re_prune_solrpp;/**< @brief shot missed solid RPP, ft_shot skipped */
88  long re_ndup; /**< @brief ft_shot() calls skipped for already-ft_shot() solids */
89  long re_nempty_cells; /**< @brief number of empty spatial partitioning cells passed through */
90  /* Data for accelerating "pieces" of solids */
91  struct rt_piecestate *re_pieces; /**< @brief array [rti_nsolids_with_pieces] */
92  long re_piece_ndup; /**< @brief ft_piece_shot() calls skipped for already-ft_shot() solids */
93  long re_piece_shots; /**< @brief # calls to ft_piece_shot() */
94  long re_piece_shot_hit; /**< @brief ft_piece_shot() returned a miss */
95  long re_piece_shot_miss; /**< @brief ft_piece_shot() returned a hit */
96  struct bu_ptbl re_pieces_pending; /**< @brief pieces with an odd hit pending */
97  /* Per-processor cache of tree unions, to accelerate "tops" and treewalk */
98  union tree * re_tree_hd; /**< @brief Head of free trees */
103  struct bu_ptbl re_directory_blocks; /**< @brief Table of malloc'ed blocks */
104 };
105 
106 /**
107  * Resources for uniprocessor
108  */
109 RT_EXPORT extern struct resource rt_uniresource; /**< @brief default. Defined in librt/globals.c */
110 #define RESOURCE_NULL ((struct resource *)0)
111 #define RT_CK_RESOURCE(_p) BU_CKMAG(_p, RESOURCE_MAGIC, "struct resource")
112 #define RT_RESOURCE_INIT_ZERO { RESOURCE_MAGIC, 0, BU_LIST_INIT_ZERO, BU_PTBL_INIT_ZERO, 0, 0, 0, BU_LIST_INIT_ZERO, 0, 0, 0, BU_LIST_INIT_ZERO, BU_LIST_INIT_ZERO, BU_LIST_INIT_ZERO, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, NULL, 0, 0, 0, 0, BU_PTBL_INIT_ZERO, NULL, 0, 0, 0, NULL, BU_PTBL_INIT_ZERO }
113 
114 /**
115  * Definition of global parallel-processing semaphores.
116  *
117  * res_syscall is now BU_SEM_SYSCALL
118  */
119 RT_EXPORT extern int RT_SEM_WORKER;
120 RT_EXPORT extern int RT_SEM_MODEL;
121 RT_EXPORT extern int RT_SEM_RESULTS;
122 RT_EXPORT extern int RT_SEM_TREE0;
123 RT_EXPORT extern int RT_SEM_TREE1;
124 RT_EXPORT extern int RT_SEM_TREE2;
125 RT_EXPORT extern int RT_SEM_TREE3;
126 
127 
128 __END_DECLS
129 
130 #endif /* RT_RESOURCE_H */
131 /** @} */
132 /*
133  * Local Variables:
134  * tab-width: 8
135  * mode: C
136  * indent-tabs-mode: t
137  * c-file-style: "stroustrup"
138  * End:
139  * ex: shiftwidth=4 tabstop=8
140  */
Header file for the BRL-CAD common definitions.
int RT_SEM_TREE3
int RT_SEM_TREE1
int RT_SEM_RESULTS
int RT_SEM_TREE0
struct resource rt_uniresource
default. Defined in librt/globals.c
int RT_SEM_MODEL
int RT_SEM_WORKER
int RT_SEM_TREE2
Definition: list.h:132
Definition: ptbl.h:53
long re_seglen
Definition: resource.h:66
long re_tree_free
Definition: resource.h:101
long re_partget
Definition: resource.h:71
struct bu_ptbl re_pieces_pending
pieces with an odd hit pending
Definition: resource.h:96
long re_segfree
Definition: resource.h:68
long re_shot_hit
ft_shot() returned a miss
Definition: resource.h:84
long re_partfree
Definition: resource.h:72
union tree ** re_boolstack
Stack for rt_booleval()
Definition: resource.h:76
long re_tree_malloc
Definition: resource.h:100
long re_piece_shots
# calls to ft_piece_shot()
Definition: resource.h:93
long re_shots
# calls to ft_shot()
Definition: resource.h:83
long re_nempty_cells
number of empty spatial partitioning cells passed through
Definition: resource.h:89
long re_tree_get
Definition: resource.h:99
struct bu_list re_parthead
Head of freelist.
Definition: resource.h:69
struct bu_list re_nmgfree
head of NMG hitmiss freelist
Definition: resource.h:75
long re_ndup
ft_shot() calls skipped for already-ft_shot() solids
Definition: resource.h:88
struct bu_list re_solid_bitv
head of freelist
Definition: resource.h:73
long re_shot_miss
ft_shot() returned a hit
Definition: resource.h:85
union tree * re_tree_hd
Head of free trees.
Definition: resource.h:98
struct directory * re_directory_hd
Definition: resource.h:102
int re_cpu
processor number, for ID
Definition: resource.h:63
struct bu_list re_seg
Head of segment freelist.
Definition: resource.h:64
long re_boolslen
# elements in re_boolstack[]
Definition: resource.h:77
long re_piece_shot_miss
ft_piece_shot() returned a hit
Definition: resource.h:95
long re_prune_solrpp
shot missed solid RPP, ft_shot skipped
Definition: resource.h:87
long re_segget
Definition: resource.h:67
struct rt_piecestate * re_pieces
array [rti_nsolids_with_pieces]
Definition: resource.h:91
long re_partlen
Definition: resource.h:70
uint32_t re_magic
Magic number.
Definition: resource.h:62
struct bu_list re_region_ptbl
head of freelist
Definition: resource.h:74
long re_nshootray
Calls to rt_shootray()
Definition: resource.h:80
struct bu_ptbl re_seg_blocks
Table of malloc'ed blocks of segs.
Definition: resource.h:65
float * re_randptr
ptr into random number table
Definition: resource.h:78
long re_piece_shot_hit
ft_piece_shot() returned a miss
Definition: resource.h:94
long re_piece_ndup
ft_piece_shot() calls skipped for already-ft_shot() solids
Definition: resource.h:92
long re_nmiss_model
Rays pruned by model RPP.
Definition: resource.h:81
struct bu_ptbl re_directory_blocks
Table of malloc'ed blocks.
Definition: resource.h:103
Definition: tree.h:148
fundamental vector, matrix, quaternion math macros