Hardware Locality (hwloc) 2.0.3

distances.h
1 /*
2 * Copyright © 2010-2017 Inria. All rights reserved.
3 * See COPYING in top-level directory.
4 */
5
10 #ifndef HWLOC_DISTANCES_H
11 #define HWLOC_DISTANCES_H
12
13 #ifndef HWLOC_H
14 #error Please include the main hwloc.h instead
15 #endif
16
17
18 #ifdef __cplusplus
19 extern "C" {
20 #elif 0
21 }
22 #endif
23
24
41 struct hwloc_distances_s {
42 unsigned nbobjs;
43 hwloc_obj_t *objs;
48 unsigned long kind;
49 hwloc_uint64_t *values;
54 };
55
67 enum hwloc_distances_kind_e {
71 HWLOC_DISTANCES_KIND_FROM_OS = (1UL<<0),
75 HWLOC_DISTANCES_KIND_FROM_USER = (1UL<<1),
76
83 HWLOC_DISTANCES_KIND_MEANS_LATENCY = (1UL<<2),
90 HWLOC_DISTANCES_KIND_MEANS_BANDWIDTH = (1UL<<3)
91 };
92
115 HWLOC_DECLSPEC int
116 hwloc_distances_get(hwloc_topology_t topology,
117 unsigned *nr, struct hwloc_distances_s **distances,
118 unsigned long kind, unsigned long flags);
119
124 HWLOC_DECLSPEC int
125 hwloc_distances_get_by_depth(hwloc_topology_t topology, int depth,
126 unsigned *nr, struct hwloc_distances_s **distances,
127 unsigned long kind, unsigned long flags);
128
133 static __hwloc_inline int
134 hwloc_distances_get_by_type(hwloc_topology_t topology, hwloc_obj_type_t type,
135 unsigned *nr, struct hwloc_distances_s **distances,
136 unsigned long kind, unsigned long flags)
137 {
138 int depth = hwloc_get_type_depth(topology, type);
139 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE) {
140 *nr = 0;
141 return 0;
142 }
143 return hwloc_distances_get_by_depth(topology, depth, nr, distances, kind, flags);
144 }
145
147 HWLOC_DECLSPEC void
148 hwloc_distances_release(hwloc_topology_t topology, struct hwloc_distances_s *distances);
149
162 static __hwloc_inline int
163 hwloc_distances_obj_index(struct hwloc_distances_s *distances, hwloc_obj_t obj)
164 {
165 unsigned i;
166 for(i=0; i<distances->nbobjs; i++)
167 if (distances->objs[i] == obj)
168 return (int)i;
169 return -1;
170 }
171
179 static __hwloc_inline int
180 hwloc_distances_obj_pair_values(struct hwloc_distances_s *distances,
181 hwloc_obj_t obj1, hwloc_obj_t obj2,
182 hwloc_uint64_t *value1to2, hwloc_uint64_t *value2to1)
183 {
184 int i1 = hwloc_distances_obj_index(distances, obj1);
185 int i2 = hwloc_distances_obj_index(distances, obj2);
186 if (i1 < 0 || i2 < 0)
187 return -1;
188 *value1to2 = distances->values[i1 * distances->nbobjs + i2];
189 *value2to1 = distances->values[i2 * distances->nbobjs + i1];
190 return 0;
191 }
192
202 enum hwloc_distances_add_flag_e {
206 HWLOC_DISTANCES_ADD_FLAG_GROUP = (1UL<<0),
212 HWLOC_DISTANCES_ADD_FLAG_GROUP_INACCURATE = (1UL<<1)
213 };
214
229 HWLOC_DECLSPEC int hwloc_distances_add(hwloc_topology_t topology,
230 unsigned nbobjs, hwloc_obj_t *objs, hwloc_uint64_t *values,
231 unsigned long kind, unsigned long flags);
232
241 HWLOC_DECLSPEC int hwloc_distances_remove(hwloc_topology_t topology);
242
247 HWLOC_DECLSPEC int hwloc_distances_remove_by_depth(hwloc_topology_t topology, int depth);
248
253 static __hwloc_inline int
254 hwloc_distances_remove_by_type(hwloc_topology_t topology, hwloc_obj_type_t type)
255 {
256 int depth = hwloc_get_type_depth(topology, type);
257 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
258 return 0;
259 return hwloc_distances_remove_by_depth(topology, depth);
260 }
261
265 #ifdef __cplusplus
266 } /* extern "C" */
267 #endif
268
269
270 #endif /* HWLOC_DISTANCES_H */
hwloc_distances_release
void hwloc_distances_release(hwloc_topology_t topology, struct hwloc_distances_s *distances)
Release a distance structure previously returned by hwloc_distances_get().
hwloc_distances_get_by_depth
int hwloc_distances_get_by_depth(hwloc_topology_t topology, int depth, unsigned *nr, struct hwloc_distances_s **distances, unsigned long kind, unsigned long flags)
Retrieve distance matrices for object at a specific depth in the topology.
hwloc_distances_remove_by_depth
int hwloc_distances_remove_by_depth(hwloc_topology_t topology, int depth)
Remove distance matrices for objects at a specific depth in the topology.
hwloc_distances_get_by_type
static int hwloc_distances_get_by_type(hwloc_topology_t topology, hwloc_obj_type_t type, unsigned *nr, struct hwloc_distances_s **distances, unsigned long kind, unsigned long flags)
Retrieve distance matrices for object of a specific type.
Definition: distances.h:134
hwloc_distances_s
Matrix of distances between a set of objects.
Definition: distances.h:41
HWLOC_DISTANCES_KIND_MEANS_BANDWIDTH
Distance values are similar to bandwidths between objects. Values are higher for closer objects...
Definition: distances.h:90
HWLOC_DISTANCES_KIND_MEANS_LATENCY
Distance values are similar to latencies between objects. Values are smaller for closer objects...
Definition: distances.h:83
hwloc_obj
Structure of a topology object.
Definition: hwloc.h:357
hwloc_distances_remove_by_type
static int hwloc_distances_remove_by_type(hwloc_topology_t topology, hwloc_obj_type_t type)
Remove distance matrices for objects of a specific type in the topology.
Definition: distances.h:254
hwloc_obj_type_t
hwloc_obj_type_t
Definition: hwloc.h:176
HWLOC_DISTANCES_ADD_FLAG_GROUP_INACCURATE
If grouping, consider the distance values as inaccurate and relax the comparisons during the grouping...
Definition: distances.h:212
hwloc_distances_add_flag_e
hwloc_distances_add_flag_e
Flags for adding a new distances to a topology.
Definition: distances.h:202
hwloc_distances_obj_pair_values
static int hwloc_distances_obj_pair_values(struct hwloc_distances_s *distances, hwloc_obj_t obj1, hwloc_obj_t obj2, hwloc_uint64_t *value1to2, hwloc_uint64_t *value2to1)
Find the values between two objects in a distances structure.
Definition: distances.h:180
hwloc_distances_get
int hwloc_distances_get(hwloc_topology_t topology, unsigned *nr, struct hwloc_distances_s **distances, unsigned long kind, unsigned long flags)
Retrieve distance matrices.
HWLOC_DISTANCES_KIND_FROM_USER
These distances were provided by the user.
Definition: distances.h:75
hwloc_distances_s::values
hwloc_uint64_t * values
Matrix of distances between objects, stored as a one-dimension array.
Definition: distances.h:49
hwloc_distances_add
int hwloc_distances_add(hwloc_topology_t topology, unsigned nbobjs, hwloc_obj_t *objs, hwloc_uint64_t *values, unsigned long kind, unsigned long flags)
Provide a distance matrix.
HWLOC_DISTANCES_KIND_FROM_OS
These distances were obtained from the operating system or hardware.
Definition: distances.h:71
hwloc_distances_remove
int hwloc_distances_remove(hwloc_topology_t topology)
Remove all distance matrices from a topology.
hwloc_topology_t
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:636
hwloc_distances_s::objs
hwloc_obj_t * objs
Array of objects described by the distance matrix. These objects are not in any particular order...
Definition: distances.h:43
HWLOC_TYPE_DEPTH_MULTIPLE
Objects of given type exist at different depth in the topology (only for Groups). ...
Definition: hwloc.h:767
hwloc_distances_obj_index
static int hwloc_distances_obj_index(struct hwloc_distances_s *distances, hwloc_obj_t obj)
Find the index of an object in a distances structure.
Definition: distances.h:163
HWLOC_TYPE_DEPTH_UNKNOWN
No object of given type exists in the topology.
Definition: hwloc.h:766
HWLOC_DISTANCES_ADD_FLAG_GROUP
Try to group objects based on the newly provided distance information.
Definition: distances.h:206
hwloc_distances_s::nbobjs
unsigned nbobjs
Number of objects described by the distance matrix.
Definition: distances.h:42
hwloc_distances_kind_e
hwloc_distances_kind_e
Kinds of distance matrices.
Definition: distances.h:67
hwloc_get_type_depth
int hwloc_get_type_depth(hwloc_topology_t topology, hwloc_obj_type_t type)
Returns the depth of objects of type type.
hwloc_distances_s::kind
unsigned long kind
OR&#39;ed set of hwloc_distances_kind_e.
Definition: distances.h:48