QR_MUMPS
qrm_hwloc_utils.c
Go to the documentation of this file.
1 /* ##############################################################################################
2 **
3 ** Copyright 2012 CNRS, INPT
4 **
5 ** This file is part of qr_mumps.
6 **
7 ** qr_mumps is free software: you can redistribute it and/or modify
8 ** it under the terms of the GNU Lesser General Public License as
9 ** published by the Free Software Foundation, either version 3 of
10 ** the License, or (at your option) any later version.
11 **
12 ** qr_mumps is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU Lesser General Public License for more details.
16 **
17 ** You can find a copy of the GNU Lesser General Public License
18 ** in the qr_mumps/doc directory.
19 **
20 ** ##############################################################################################*/
21 
22 
23 /*##############################################################################################*/
33 /*##############################################################################################*/
34 
35 
36 #if defined(hwloc)
37 #include <hwloc.h>
38 
39 /* Wrapper routines for hwloc */
40 void qrm_hwloc_bind(int id)
41 {
42  int depth, ret;
43  unsigned i, n;
44  int topodepth;
45  hwloc_topology_t topology;
46  hwloc_cpuset_t cpuset;
47  hwloc_obj_t obj;
48 
49  hwloc_topology_init(&topology);
50 
51  hwloc_topology_load(topology);
52 
53  obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, id);
54 
55  ret = hwloc_set_cpubind(topology, obj->cpuset, HWLOC_CPUBIND_THREAD);
56  if (ret) {
57  printf("Couldn't bind to core %d\n", id);
58  assert(0);
59  } else {
60  printf("Bound to core %d\n", id);
61  }
62 
63  hwloc_topology_destroy(topology);
64 
65  return;
66 }
67 
68 
69 void qrm_hwloc_info(int *ncores, int *nnodes, int *cnode)
70 {
71  int depth, ret;
72  unsigned i, n, j;
73  int topodepth, numa;
74  hwloc_topology_t topology;
75  hwloc_cpuset_t cpuset;
76  hwloc_obj_t obj, cobj;
77  hwloc_obj_type_t otype;
78 
79  hwloc_topology_init(&topology);
80 
81  hwloc_topology_load(topology);
82 
83  /* get the number os cores and NUMA nodes */
84  *ncores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE);
85  /* printf("ncores: %d\n",*ncores); */
86 
87  *nnodes = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NODE);
88  if(*nnodes == 0){
89  otype = HWLOC_OBJ_SOCKET;
90  /* printf("grouping with sockets\n"); */
91  *nnodes = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_SOCKET);
92  } else {
93  otype = HWLOC_OBJ_NODE;
94  /* printf("grouping with NUMA nodes\n"); */
95  }
96 
97  /* get the handle for the first NUMA node */
98  obj = hwloc_get_obj_by_type(topology, otype, 0);
99 
100  /* get the number of cores in one NUMA node (supposedly the same for all nodes) */
101  *cnode = hwloc_get_nbobjs_inside_cpuset_by_type(topology, obj->cpuset, HWLOC_OBJ_CORE);
102 
103  hwloc_topology_destroy(topology);
104  return;
105 }
106 
107 
108 void qrm_hwloc_topo(int *nodes, int *topo)
109 {
110  int depth, ret;
111  unsigned i, n, j, ncores, nnodes, cnode;
112  int topodepth, numa;
113  hwloc_topology_t topology;
114  hwloc_cpuset_t cpuset;
115  hwloc_obj_t obj, cobj;
116  hwloc_obj_type_t otype;
117 
118  hwloc_topology_init(&topology);
119 
120  hwloc_topology_load(topology);
121 
122  /* get the number os cores and NUMA nodes */
123  ncores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE);
124  printf("ncores: %d\n",ncores);
125 
126  nnodes = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NODE);
127  if(nnodes == 0){
128  otype = HWLOC_OBJ_SOCKET;
129  printf("grouping with sockets\n");
130  nnodes = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_SOCKET);
131  } else {
132  otype = HWLOC_OBJ_NODE;
133  printf("grouping with NUMA nodes\n");
134  }
135 
136  /* get the handle for the first NUMA node */
137  obj = hwloc_get_obj_by_type(topology, otype, 0);
138 
139  /* get the number of cores in one NUMA node (supposedly the same for all nodes) */
140  cnode = hwloc_get_nbobjs_inside_cpuset_by_type(topology, obj->cpuset, HWLOC_OBJ_CORE);
141 
142  for(i=0; i<nnodes; i++){
143  /* get the handle for the first i-th node */
144  obj = hwloc_get_obj_by_type(topology, otype, i);
145  /* get the number of cores in i-th NUMA node (supposedly the same for all nodes) */
146  cnode = hwloc_get_nbobjs_inside_cpuset_by_type(topology, obj->cpuset, HWLOC_OBJ_CORE);
147 
148  /* get the first core in this node */
149  cobj = hwloc_get_next_obj_inside_cpuset_by_type(topology, obj->cpuset, HWLOC_OBJ_CORE, NULL);
150  topo[(i*cnode)] = cobj->logical_index;
151  /* printf("%2d -- group: %2d",i,cobj->logical_index); */
152  for(j=1; j<cnode; j++){
153  cobj = hwloc_get_next_obj_inside_cpuset_by_type(topology, obj->cpuset, HWLOC_OBJ_CORE, cobj);
154  topo[(i*cnode)+j] = cobj->logical_index;
155  /* printf(" %2d",cobj->logical_index); */
156  }
157  /* printf("\n"); */
158  }
159 
160 
161  hwloc_topology_destroy(topology);
162  return;
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 /* void qrm_hwloc_topo(int *topo) */
192 /* { */
193 /* int depth, ret; */
194 /* unsigned i, n, cnode, j, ncores, nnodes; */
195 /* int topodepth, dryrun; */
196 /* hwloc_topology_t topology; */
197 /* hwloc_cpuset_t cpuset; */
198 /* hwloc_obj_t obj, cobj; */
199 
200 /* hwloc_topology_init(&topology); */
201 /* hwloc_topology_load(topology); */
202 
203 /* /\* get the number os cores and NUMA nodes *\/ */
204 /* ncores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE); */
205 /* nnodes = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NODE); */
206 
207 /* for(i=0; i<nnodes; i++){ */
208 /* /\* get the handle for the first i-th node *\/ */
209 /* obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NODE, i); */
210 /* /\* get the number of cores in i-th NUMA node (supposedly the same for all nodes) *\/ */
211 /* cnode = hwloc_get_nbobjs_inside_cpuset_by_type(topology, obj->cpuset, HWLOC_OBJ_CORE); */
212 
213 /* /\* get the first core in this node *\/ */
214 /* cobj = hwloc_get_next_obj_inside_cpuset_by_type(topology, obj->cpuset, HWLOC_OBJ_CORE, NULL); */
215 /* topo[(i*cnode)] = cobj->logical_index; */
216 /* for(j=1; j<cnode; j++){ */
217 /* cobj = hwloc_get_next_obj_inside_cpuset_by_type(topology, obj->cpuset, HWLOC_OBJ_CORE, cobj); */
218 /* topo[(i*cnode)+j] = cobj->logical_index; */
219 /* } */
220 /* } */
221 
222 /* hwloc_topology_destroy(topology); */
223 /* return; */
224 /* } */
225 
226 
227 /* void qrm_hwloc_info(int *ncores, int *nnodes, int *cnode) */
228 /* { */
229 /* int depth, ret; */
230 /* unsigned i, n, icnode, j; */
231 /* int topodepth, dryrun; */
232 /* hwloc_topology_t topology; */
233 /* hwloc_cpuset_t cpuset; */
234 /* hwloc_obj_t obj, cobj; */
235 
236 /* hwloc_topology_init(&topology); */
237 
238 /* hwloc_topology_load(topology); */
239 
240 /* /\* get the number os cores and NUMA nodes *\/ */
241 /* *ncores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE); */
242 /* *nnodes = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NODE); */
243 
244 /* if(*nnodes == 0){ */
245 /* *nnodes = 1; */
246 /* *cnode = *ncores; */
247 /* hwloc_topology_destroy(topology); */
248 /* return; */
249 /* } */
250 /* /\* get the handle for the first NUMA node *\/ */
251 /* obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NODE, 0); */
252 
253 /* /\* get the number of cores in one NUMA node (supposedly the same for all nodes) *\/ */
254 /* *cnode = hwloc_get_nbobjs_inside_cpuset_by_type(topology, obj->cpuset, HWLOC_OBJ_CORE); */
255 
256 /* hwloc_topology_destroy(topology); */
257 /* return; */
258 /* } */
259 
260 
261 #endif
void qrm_hwloc_topo(int *nodes, int *topo)
void qrm_hwloc_info(int *ncores, int *nnodes, int *cnode)
int i
Definition: secs.c:40
void qrm_hwloc_bind(int id)