This source file includes following definitions.
- fill_cache_line_size
- main
1
2
3
4
5
6 #include <stdio.h>
7 #include <unistd.h>
8
9 #include "opal/mca/hwloc/base/base.h"
10 #include "opal/runtime/opal.h"
11
12
13 static hwloc_topology_t my_topology;
14
15 static void fill_cache_line_size(void)
16 {
17 int i = 0;
18 unsigned size;
19 hwloc_obj_t obj;
20 bool found = false;
21
22
23 size = 4096;
24 while (1) {
25 obj = opal_hwloc_base_get_obj_by_type(my_topology,
26 HWLOC_OBJ_CACHE, 2,
27 i, OPAL_HWLOC_LOGICAL);
28 if (NULL == obj) {
29 break;
30 } else {
31 found = true;
32 if (NULL != obj->attr &&
33 size > obj->attr->cache.linesize) {
34 size = obj->attr->cache.linesize;
35 }
36 }
37 ++i;
38 }
39
40
41
42
43 if (found) {
44 opal_cache_line_size = (int) size;
45 }
46 }
47
48 int main(int argc, char* argv[])
49 {
50 hwloc_obj_t obj;
51 unsigned j, k;
52 struct hwloc_topology_support *support;
53 int rc;
54
55 if (2 != argc) {
56 fprintf(stderr, "Usage: opal_hwloc <topofile>\n");
57 exit(1);
58 }
59
60 if (0 > (rc = opal_init(&argc, &argv))) {
61 fprintf(stderr, "opal_hwloc: couldn't init opal - error code %d\n", rc);
62 return rc;
63 }
64
65 if (0 != hwloc_topology_init(&my_topology)) {
66 return OPAL_ERR_NOT_SUPPORTED;
67 }
68 if (0 != hwloc_topology_set_xml(my_topology, argv[1])) {
69 hwloc_topology_destroy(my_topology);
70 return OPAL_ERR_NOT_SUPPORTED;
71 }
72
73
74
75 if (0 != opal_hwloc_base_topology_set_flags(my_topology,
76 HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM)) {
77 hwloc_topology_destroy(my_topology);
78 return OPAL_ERR_NOT_SUPPORTED;
79 }
80 if (0 != hwloc_topology_load(my_topology)) {
81 hwloc_topology_destroy(my_topology);
82 return OPAL_ERR_NOT_SUPPORTED;
83 }
84
85
86
87
88
89 obj = hwloc_get_root_obj(my_topology);
90 for (k=0; k < obj->infos_count; k++) {
91 if (NULL == obj->infos[k].name ||
92 NULL == obj->infos[k].value) {
93 continue;
94 }
95 if (0 == strncmp(obj->infos[k].name, "HostName", strlen("HostName"))) {
96 free(obj->infos[k].name);
97 free(obj->infos[k].value);
98
99 for (j=k; j < obj->infos_count-1; j++) {
100 obj->infos[j] = obj->infos[j+1];
101 }
102 obj->infos[obj->infos_count-1].name = NULL;
103 obj->infos[obj->infos_count-1].value = NULL;
104 obj->infos_count--;
105 break;
106 }
107 }
108
109
110
111
112
113 support = (struct hwloc_topology_support*)hwloc_topology_get_support(my_topology);
114 support->cpubind->set_thisproc_cpubind = true;
115
116
117 opal_hwloc_base_filter_cpus(my_topology);
118
119
120
121 fill_cache_line_size();
122
123
124 if (NULL == hwloc_get_obj_by_type(my_topology, HWLOC_OBJ_CORE, 0)) {
125 fprintf(stderr, "DIDN'T FIND A CORE\n");
126 }
127
128 hwloc_topology_destroy(my_topology);
129
130 opal_finalize();
131
132 return 0;
133 }