-
Notifications
You must be signed in to change notification settings - Fork 168
/
memattrs.c
513 lines (463 loc) · 20.6 KB
/
memattrs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
/*
* Copyright © 2020 Inria. All rights reserved.
* See COPYING in top-level directory.
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "hwloc.h"
static void
check_memattr(hwloc_topology_t topology, const char *name, hwloc_memattr_id_t id, unsigned long flags)
{
hwloc_memattr_id_t gotid;
const char *gotname;
unsigned long gotflags;
int err;
err = hwloc_memattr_get_by_name(topology, name, &gotid);
assert(!err);
assert(id == gotid);
err = hwloc_memattr_get_name(topology, id, &gotname);
assert(!err);
assert(!strcmp(gotname, name));
err = hwloc_memattr_get_flags(topology, id, &gotflags);
assert(!err);
assert(gotflags == flags);
}
int
main(void)
{
hwloc_topology_t topology;
const char *gotname;
hwloc_memattr_id_t id, id2, gotid;
struct hwloc_location loc, locs[2];
unsigned nrlocs, nrtgs, i;
hwloc_uint64_t gotvalue;
hwloc_obj_t node, targets[4];
int err;
hwloc_bitmap_t bitmap;
err = hwloc_topology_init(&topology);
assert(!err);
err = hwloc_topology_set_synthetic(topology, "node:4 pu:2");
assert(!err);
err = hwloc_topology_load(topology);
assert(!err);
/* check get local nodes */
err = hwloc_get_local_numanode_objs(topology, NULL, NULL, NULL, 0);
assert(err < 0);
/* get all nodes */
loc.type = HWLOC_LOCATION_TYPE_OBJECT;
loc.location.object = hwloc_get_root_obj(topology);
nrtgs = 4;
err = hwloc_get_local_numanode_objs(topology, &loc, &nrtgs, targets, HWLOC_LOCAL_NUMANODE_FLAG_ALL);
assert(!err);
assert(nrtgs == 4);
assert(targets[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0));
assert(targets[1] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 1));
assert(targets[2] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 2));
assert(targets[3] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 3));
/* get root local nodes (none) */
loc.type = HWLOC_LOCATION_TYPE_OBJECT;
loc.location.object = hwloc_get_root_obj(topology);
nrtgs = 4;
err = hwloc_get_local_numanode_objs(topology, &loc, &nrtgs, targets, 0);
assert(!err);
assert(nrtgs == 0);
/* get root-or-smaller local nodes (all) */
loc.type = HWLOC_LOCATION_TYPE_OBJECT;
loc.location.object = hwloc_get_root_obj(topology);
nrtgs = 4;
err = hwloc_get_local_numanode_objs(topology, &loc, &nrtgs, targets, HWLOC_LOCAL_NUMANODE_FLAG_SMALLER_LOCALITY);
assert(!err);
assert(nrtgs == 4);
assert(targets[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0));
assert(targets[1] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 1));
assert(targets[2] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 2));
assert(targets[3] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 3));
/* get PU local nodes (none) */
loc.type = HWLOC_LOCATION_TYPE_OBJECT;
loc.location.object = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 1);
nrtgs = 4;
err = hwloc_get_local_numanode_objs(topology, &loc, &nrtgs, targets, 0);
assert(!err);
assert(nrtgs == 0);
/* get PU-or-larger local nodes (1) */
loc.type = HWLOC_LOCATION_TYPE_OBJECT;
loc.location.object = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 7);
nrtgs = 4;
err = hwloc_get_local_numanode_objs(topology, &loc, &nrtgs, targets, HWLOC_LOCAL_NUMANODE_FLAG_LARGER_LOCALITY);
assert(!err);
assert(nrtgs == 1);
assert(targets[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 3));
/* get node local nodes (1) */
loc.type = HWLOC_LOCATION_TYPE_OBJECT;
loc.location.object = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 2);
nrtgs = 4;
err = hwloc_get_local_numanode_objs(topology, &loc, &nrtgs, targets, 0);
assert(!err);
assert(nrtgs == 1);
assert(targets[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 2));
/* get 2-node local nodes (0) */
loc.type = HWLOC_LOCATION_TYPE_CPUSET;
loc.location.cpuset = hwloc_bitmap_alloc();
hwloc_bitmap_set_range(loc.location.cpuset, 2, 5);
nrtgs = 4;
err = hwloc_get_local_numanode_objs(topology, &loc, &nrtgs, targets, 0);
assert(!err);
assert(nrtgs == 0);
/* get 2-node-or-larger local nodes (0) */
nrtgs = 4;
err = hwloc_get_local_numanode_objs(topology, &loc, &nrtgs, targets, HWLOC_LOCAL_NUMANODE_FLAG_LARGER_LOCALITY);
assert(!err);
assert(nrtgs == 0);
/* get 2-node-or-smaller local nodes (2) */
nrtgs = 4;
err = hwloc_get_local_numanode_objs(topology, &loc, &nrtgs, targets, HWLOC_LOCAL_NUMANODE_FLAG_SMALLER_LOCALITY);
assert(!err);
assert(nrtgs == 2);
assert(targets[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 1));
assert(targets[1] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 2));
hwloc_bitmap_free(loc.location.cpuset);
/* check default memattrs */
check_memattr(topology, "Capacity", HWLOC_MEMATTR_ID_CAPACITY, HWLOC_MEMATTR_FLAG_HIGHER_FIRST);
check_memattr(topology, "Locality", HWLOC_MEMATTR_ID_LOCALITY, HWLOC_MEMATTR_FLAG_LOWER_FIRST);
check_memattr(topology, "Bandwidth", HWLOC_MEMATTR_ID_BANDWIDTH, HWLOC_MEMATTR_FLAG_HIGHER_FIRST|HWLOC_MEMATTR_FLAG_NEED_INITIATOR);
check_memattr(topology, "Latency", HWLOC_MEMATTR_ID_LATENCY, HWLOC_MEMATTR_FLAG_LOWER_FIRST|HWLOC_MEMATTR_FLAG_NEED_INITIATOR);
/* check convenience memattr values */
err = hwloc_memattr_get_value(topology, HWLOC_MEMATTR_ID_CAPACITY,
hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 1), NULL, 0,
&gotvalue);
assert(!err);
assert(gotvalue == 1024*1024*1024);
err = hwloc_memattr_get_value(topology, HWLOC_MEMATTR_ID_LOCALITY,
hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 2), NULL, 0,
&gotvalue);
assert(!err);
assert(gotvalue == 2);
nrtgs = 0;
err = hwloc_memattr_get_targets(topology, HWLOC_MEMATTR_ID_LOCALITY, NULL, 0, &nrtgs, targets, NULL);
assert(!err);
assert(nrtgs == 4);
nrtgs = 4;
err = hwloc_memattr_get_targets(topology, HWLOC_MEMATTR_ID_LOCALITY, NULL, 0, &nrtgs, targets, NULL);
assert(!err);
assert(nrtgs == 4);
assert(targets[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0));
assert(targets[1] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 1));
assert(targets[2] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 2));
assert(targets[3] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 3));
/* look for unexisting memattr */
err = hwloc_memattr_get_by_name(topology, "foobarrrrr", &gotid);
assert(err < 0);
err = hwloc_memattr_get_name(topology, HWLOC_MEMATTR_ID_MAX, &gotname);
assert(err < 0);
/* (fail to) register with invalid flags */
err = hwloc_memattr_register(topology, "foobar", 0, &id);
assert(err < 0);
assert(errno == EINVAL);
/* (fail to) register with existing name */
err = hwloc_memattr_register(topology, "Capacity", HWLOC_MEMATTR_FLAG_HIGHER_FIRST, &id);
assert(err < 0);
assert(errno == EBUSY);
/********************************
* new attribute with initiators
*/
/* register with initiator */
err = hwloc_memattr_register(topology, "foobar", HWLOC_MEMATTR_FLAG_LOWER_FIRST|HWLOC_MEMATTR_FLAG_NEED_INITIATOR, &id);
assert(!err);
/* check it */
check_memattr(topology, "foobar", id, HWLOC_MEMATTR_FLAG_LOWER_FIRST|HWLOC_MEMATTR_FLAG_NEED_INITIATOR);
/* check 0 target */
nrtgs = 0;
err = hwloc_memattr_get_targets(topology, id, NULL, 0, &nrtgs, NULL, NULL);
assert(!err);
assert(!nrtgs);
/* add a new value for the first NUMA node */
node = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0);
loc.type = HWLOC_LOCATION_TYPE_OBJECT;
loc.location.object = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_PU)-1);
err = hwloc_memattr_set_value(topology, id, node,
&loc, 0, 2345);
assert(!err);
/* check 1 target */
nrtgs = 4;
err = hwloc_memattr_get_targets(topology, id, NULL, 0, &nrtgs, targets, NULL);
assert(!err);
assert(nrtgs == 1);
assert(targets[0] == node);
/* check that value */
err = hwloc_memattr_get_value(topology, id, node, &loc, 0, &gotvalue);
assert(!err);
assert(gotvalue == 2345);
/* try with NULL or unknown initiators */
loc.type = HWLOC_LOCATION_TYPE_OBJECT;
loc.location.object = NULL;
err = hwloc_memattr_get_value(topology, id, node, &loc, 0, &gotvalue);
assert(err < 0);
loc.type = HWLOC_LOCATION_TYPE_OBJECT;
loc.location.object = hwloc_get_root_obj(topology);
err = hwloc_memattr_get_value(topology, id, node, &loc, 0, &gotvalue);
assert(err < 0);
loc.type = HWLOC_LOCATION_TYPE_CPUSET;
loc.location.cpuset = NULL;
err = hwloc_memattr_get_value(topology, id, node, &loc, 0, &gotvalue);
assert(err < 0);
loc.type = HWLOC_LOCATION_TYPE_CPUSET;
loc.location.cpuset = hwloc_get_root_obj(topology)->cpuset;
err = hwloc_memattr_get_value(topology, id, node, &loc, 0, &gotvalue);
assert(err < 0);
/* check initiators */
nrlocs = 0;
err = hwloc_memattr_get_initiators(topology, id, node, 0, &nrlocs, NULL, NULL);
assert(!err);
assert(nrlocs == 1);
/* try first without values */
err = hwloc_memattr_get_initiators(topology, id, node, 0, &nrlocs, &loc, NULL);
assert(!err);
assert(nrlocs == 1);
assert(loc.type == HWLOC_LOCATION_TYPE_OBJECT);
assert(loc.location.object != NULL);
assert(loc.location.object->type == HWLOC_OBJ_PU);
assert(loc.location.object->logical_index == (unsigned) (hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_PU) - 1));
/* try again with values */
err = hwloc_memattr_get_initiators(topology, id, node, 0, &nrlocs, &loc, &gotvalue);
assert(!err);
assert(nrlocs == 1);
assert(loc.type == HWLOC_LOCATION_TYPE_OBJECT);
assert(loc.location.object != NULL);
assert(loc.location.object->type == HWLOC_OBJ_PU);
assert(loc.location.object->logical_index == (unsigned) (hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_PU) - 1));
assert(gotvalue == 2345);
/***********************************
* new attribute without initiators
*/
/* register without initiator */
err = hwloc_memattr_register(topology, "barnoinit", HWLOC_MEMATTR_FLAG_HIGHER_FIRST, &id2);
assert(!err);
/* check it */
check_memattr(topology, "barnoinit", id2, HWLOC_MEMATTR_FLAG_HIGHER_FIRST);
/* check 0 target */
nrtgs = 0;
err = hwloc_memattr_get_targets(topology, id2, NULL, 0, &nrtgs, NULL, NULL);
assert(!err);
assert(!nrtgs);
/* add a new value for the last NUMA node */
node = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NUMANODE)-1);
err = hwloc_memattr_set_value(topology, id2, node,
NULL, 0, 3456);
assert(!err);
/* force refresh */
err = hwloc_topology_refresh(topology);
assert(!err);
/* check 1 target */
nrtgs = 4;
err = hwloc_memattr_get_targets(topology, id2, NULL, 0, &nrtgs, targets, NULL);
assert(!err);
assert(nrtgs == 1);
assert(targets[0] == node);
/* check that value */
err = hwloc_memattr_get_value(topology, id2, node, NULL, 0, &gotvalue);
assert(!err);
assert(gotvalue == 3456);
/* check that initiator is ignored when getting values */
loc.type = HWLOC_LOCATION_TYPE_OBJECT;
loc.location.object = hwloc_get_root_obj(topology);
gotvalue = 0;
err = hwloc_memattr_get_value(topology, id2, node, &loc, 0, &gotvalue);
assert(!err);
assert(gotvalue == 3456);
loc.type = HWLOC_LOCATION_TYPE_CPUSET;
loc.location.cpuset = hwloc_get_root_obj(topology)->cpuset;
gotvalue = 0;
err = hwloc_memattr_get_value(topology, id2, node, &loc, 0, &gotvalue);
assert(!err);
assert(gotvalue == 3456);
/* check no initiators are returned */
nrlocs = 0;
err = hwloc_memattr_get_initiators(topology, id2, node, 0, &nrlocs, NULL, NULL);
assert(!err);
assert(nrlocs == 0);
/**********************************************
* add value for both attributes for all nodes
*/
/* use first node as initiator for first attribute */
loc.type = HWLOC_LOCATION_TYPE_CPUSET;
loc.location.cpuset = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0)->cpuset;
for(i=0; i<(unsigned)hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NUMANODE); i++) {
node = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, i);
/* increasing value for first attribute, best target will be first node */
err = hwloc_memattr_set_value(topology, id, node,
&loc, 0, (i+1)*10);
assert(!err);
/* increasing value for second attribute without initiator, best target will be last node */
err = hwloc_memattr_set_value(topology, id2, node,
NULL, 0, (i+1)*10);
assert(!err);
}
/* check 4 targets for id */
nrtgs = 4;
err = hwloc_memattr_get_targets(topology, id, NULL, 0, &nrtgs, targets, NULL);
assert(!err);
assert(nrtgs == 4);
/* first target */
assert(targets[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0));
nrlocs = 2;
err = hwloc_memattr_get_initiators(topology, id, targets[0], 0, &nrlocs, locs, NULL);
assert(!err);
assert(nrlocs == 2);
assert(locs[0].type == HWLOC_LOCATION_TYPE_OBJECT);
assert(locs[0].location.object->type == HWLOC_OBJ_PU);
assert(locs[0].location.object->os_index == 7);
assert(locs[1].type == HWLOC_LOCATION_TYPE_CPUSET);
assert(hwloc_bitmap_isequal(locs[1].location.cpuset, hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0)->cpuset));
/* second target */
assert(targets[1] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 1));
nrlocs = 2;
err = hwloc_memattr_get_initiators(topology, id, targets[1], 0, &nrlocs, locs, NULL);
assert(!err);
assert(nrlocs == 1);
assert(locs[0].type == HWLOC_LOCATION_TYPE_CPUSET);
assert(hwloc_bitmap_isequal(locs[0].location.cpuset, hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0)->cpuset));
/* third target */
assert(targets[2] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 2));
nrlocs = 2;
err = hwloc_memattr_get_initiators(topology, id, targets[2], 0, &nrlocs, locs, NULL);
assert(!err);
assert(nrlocs == 1);
assert(locs[0].type == HWLOC_LOCATION_TYPE_CPUSET);
assert(hwloc_bitmap_isequal(locs[0].location.cpuset, hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0)->cpuset));
/* fourth target */
assert(targets[3] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 3));
nrlocs = 2;
err = hwloc_memattr_get_initiators(topology, id, targets[3], 0, &nrlocs, locs, NULL);
assert(!err);
assert(nrlocs == 1);
assert(locs[0].type == HWLOC_LOCATION_TYPE_CPUSET);
assert(hwloc_bitmap_isequal(locs[0].location.cpuset, hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0)->cpuset));
/* check 4 targets for id with entire topology cpuset */
nrtgs = 4;
err = hwloc_memattr_get_targets(topology, id, &loc, 0, &nrtgs, targets, NULL);
assert(!err);
assert(nrtgs == 4);
/* check 0 targets for id with entire topology cpuset */
nrtgs = 4;
loc.type = HWLOC_LOCATION_TYPE_CPUSET;
loc.location.cpuset = (hwloc_bitmap_t) hwloc_topology_get_topology_cpuset(topology);
err = hwloc_memattr_get_targets(topology, id, &loc, 0, &nrtgs, targets, NULL);
assert(!err);
assert(nrtgs == 0);
/* check 4 targets for id2, no initiators to check */
nrtgs = 4;
err = hwloc_memattr_get_targets(topology, id2, NULL, 0, &nrtgs, targets, NULL);
assert(!err);
assert(nrtgs == 4);
assert(targets[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 3)); /* node 3 was added first */
assert(targets[1] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0));
assert(targets[2] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 1));
assert(targets[3] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 2));
/* now check best targets from first PU (included in first node used as initiator above) */
loc.type = HWLOC_LOCATION_TYPE_CPUSET;
loc.location.cpuset = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 0)->cpuset;
/* check best is the first node for first attribute (lower first) */
err = hwloc_memattr_get_best_target(topology, id, &loc, 0, &node, NULL);
assert(!err);
assert(node);
assert(node->type == HWLOC_OBJ_NUMANODE);
assert(node == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0));
/* check best is the last node for last attribute (lower first) */
err = hwloc_memattr_get_best_target(topology, id2, &loc, 0, &node, NULL);
assert(!err);
assert(node);
assert(node->type == HWLOC_OBJ_NUMANODE);
assert(node == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NUMANODE)-1));
/* check best initiator for first NUMA is its own cpuset */
err = hwloc_memattr_get_best_initiator(topology, id, node, 0, &loc, NULL);
assert(!err);
assert(locs[0].type == HWLOC_LOCATION_TYPE_CPUSET);
/* check best initiator is invalid for no-initiator memattr */
assert(hwloc_bitmap_isequal(locs[0].location.cpuset, hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0)->cpuset));
err = hwloc_memattr_get_best_initiator(topology, id2, node, 0, &loc, NULL);
assert(err == -1);
assert(errno == EINVAL);
/***************************
* restrict to only 3 nodes
*/
bitmap = hwloc_bitmap_alloc();
hwloc_bitmap_set_range(bitmap, 0, 2);
err = hwloc_topology_restrict(topology, bitmap, HWLOC_RESTRICT_FLAG_BYNODESET);
assert(!err);
hwloc_bitmap_free(bitmap);
/* now only 3 targets for id, last target was removed */
nrtgs = 4;
err = hwloc_memattr_get_targets(topology, id, NULL, 0, &nrtgs, targets, NULL);
assert(!err);
assert(nrtgs == 3);
/* first target unchanged */
assert(targets[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0));
nrlocs = 2;
err = hwloc_memattr_get_initiators(topology, id, targets[0], 0, &nrlocs, locs, NULL);
assert(!err);
assert(nrlocs == 2);
assert(locs[0].type == HWLOC_LOCATION_TYPE_OBJECT);
assert(locs[0].location.object->type == HWLOC_OBJ_PU);
assert(locs[0].location.object->os_index == 7);
assert(locs[1].type == HWLOC_LOCATION_TYPE_CPUSET);
assert(hwloc_bitmap_isequal(locs[1].location.cpuset, hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0)->cpuset));
/* second target unchanged */
assert(targets[1] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 1));
nrlocs = 2;
err = hwloc_memattr_get_initiators(topology, id, targets[1], 0, &nrlocs, locs, NULL);
assert(!err);
assert(nrlocs == 1);
assert(locs[0].type == HWLOC_LOCATION_TYPE_CPUSET);
assert(hwloc_bitmap_isequal(locs[0].location.cpuset, hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0)->cpuset));
/* third target unchanged */
assert(targets[2] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 2));
nrlocs = 2;
err = hwloc_memattr_get_initiators(topology, id, targets[2], 0, &nrlocs, locs, NULL);
assert(!err);
assert(nrlocs == 1);
assert(locs[0].type == HWLOC_LOCATION_TYPE_CPUSET);
assert(hwloc_bitmap_isequal(locs[0].location.cpuset, hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0)->cpuset));
/* fourth target removed */
/* now only 3 targets for id2, last target was removed */
nrtgs = 4;
err = hwloc_memattr_get_targets(topology, id2, NULL, 0, &nrtgs, targets, NULL);
assert(!err);
assert(nrtgs == 3);
assert(targets[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0));
assert(targets[1] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 1));
assert(targets[2] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 2));
/********************************************
* restrict to only the second half of cores
*/
bitmap = hwloc_bitmap_alloc();
hwloc_bitmap_set_range(bitmap, 4, 7);
err = hwloc_topology_restrict(topology, bitmap, 0);
assert(!err);
hwloc_bitmap_free(bitmap);
/* now only 1 target for id, all cpuset initiators removed */
nrtgs = 4;
err = hwloc_memattr_get_targets(topology, id, NULL, 0, &nrtgs, targets, NULL);
assert(!err);
assert(nrtgs == 1);
/* first target only has one initiator */
assert(targets[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 2)); /* CPUless node:0 became node:2 */
nrlocs = 2;
err = hwloc_memattr_get_initiators(topology, id, targets[0], 0, &nrlocs, locs, NULL);
assert(!err);
assert(nrlocs == 1);
assert(locs[0].type == HWLOC_LOCATION_TYPE_OBJECT);
assert(locs[0].location.object->type == HWLOC_OBJ_PU);
assert(locs[0].location.object->os_index == 7);
/* second, third and fourth targets removed */
/* still only 3 targets for id2 */
nrtgs = 4;
err = hwloc_memattr_get_targets(topology, id2, NULL, 0, &nrtgs, targets, NULL);
assert(!err);
assert(nrtgs == 3);
assert(targets[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 2)); /* CPUless node:0 became node:2 */
assert(targets[1] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 1)); /* 0 and 1 should be reversed, but the core doesn't current reordered those, see FIXME in restrict_object_by_nodeset() */
assert(targets[2] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0));
hwloc_topology_destroy(topology);
return 0;
}