Skip to content

Commit 08316c1

Browse files
authored
Merge pull request #685 from anindex/bug-682-hwloc2-likwid
Fix compilation issues #682 hwloc 2.x and likwid
2 parents c79b644 + 0d3d2fc commit 08316c1

File tree

2 files changed

+56
-30
lines changed

2 files changed

+56
-30
lines changed

dart-if/include/dash/dart/if/dart_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ typedef struct
376376

377377
int numa_id;
378378

379+
int num_sockets;
380+
379381
/** The unit's affine core, unique identifier within a processing
380382
* module. */
381383
int core_id;

dart-impl/base/src/hwinfo.c

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static const int BYTES_PER_MB = (1024 * 1024);
9191
dart_ret_t dart_hwinfo_init(
9292
dart_hwinfo_t * hw)
9393
{
94+
hw->num_sockets = -1;
9495
hw->num_numa = -1;
9596
hw->numa_id = -1;
9697
hw->num_cores = -1;
@@ -150,36 +151,6 @@ dart_ret_t dart_hwinfo(
150151
hw.host[DART_LOCALITY_HOST_MAX_SIZE-1] = '\0';
151152
}
152153

153-
#ifdef DART_ENABLE_LIKWID
154-
DART_LOG_TRACE("dart_hwinfo: using likwid");
155-
/*
156-
* see likwid API documentation:
157-
* https://rrze-hpc.github.io/likwid/Doxygen/C-likwidAPI-code.html
158-
*/
159-
int likwid_ret = topology_init();
160-
if (likwid_ret < 0) {
161-
DART_LOG_ERROR("dart_hwinfo: "
162-
"likwid: topology_init failed, returned %d", likwid_ret);
163-
} else {
164-
CpuInfo_t info = get_cpuInfo();
165-
CpuTopology_t topo = get_cpuTopology();
166-
if (hw.min_cpu_mhz < 0 || hw.max_cpu_mhz < 0) {
167-
hw.min_cpu_mhz = info->clock;
168-
hw.max_cpu_mhz = info->clock;
169-
}
170-
if (hw.num_numa < 0) {
171-
hw.num_numa = hw.num_sockets;
172-
}
173-
if (hw.num_cores < 0) {
174-
hw.num_cores = topo->numCoresPerSocket * hw.num_sockets;
175-
}
176-
topology_finalize();
177-
DART_LOG_TRACE("dart_hwinfo: likwid: "
178-
"num_sockets: %d num_numa: %d num_cores: %d",
179-
hw.num_sockets, hw.num_numa, hw.num_cores);
180-
}
181-
#endif /* DART_ENABLE_LIKWID */
182-
183154
#ifdef DART_ENABLE_HWLOC
184155
DART_LOG_TRACE("dart_hwinfo: using hwloc");
185156

@@ -317,6 +288,18 @@ dart_ret_t dart_hwinfo(
317288
hw.num_numa = n_numa_nodes;
318289
}
319290
}
291+
if (hw.num_sockets < 0) {
292+
int n_sockets = hwloc_get_nbobjs_by_type(topology,
293+
#if HWLOC_API_VERSION > 0x00011000
294+
HWLOC_OBJ_PACKAGE
295+
#else
296+
HWLOC_OBJ_SOCKET
297+
#endif
298+
);
299+
if (n_sockets > 0) {
300+
hw.num_sockets = n_sockets;
301+
}
302+
}
320303
if (hw.num_cores < 0) {
321304
int n_cores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE);
322305
if (n_cores > 0) {
@@ -333,13 +316,21 @@ dart_ret_t dart_hwinfo(
333316
if(hw.system_memory_bytes < 0) {
334317
hwloc_obj_t obj;
335318
obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_MACHINE, 0);
319+
#if HWLOC_API_VERSION < 0x00020000
336320
hw.system_memory_bytes = obj->memory.total_memory / BYTES_PER_MB;
321+
#else
322+
hw.system_memory_bytes = obj->total_memory / BYTES_PER_MB;
323+
#endif
337324
}
338325
if(hw.numa_memory_bytes < 0) {
339326
hwloc_obj_t obj;
340327
obj = hwloc_get_obj_by_type(topology, DART__HWLOC_OBJ_NUMANODE, 0);
341328
if(obj != NULL) {
329+
#if HWLOC_API_VERSION < 0x00020000
342330
hw.numa_memory_bytes = obj->memory.total_memory / BYTES_PER_MB;
331+
#else
332+
hw.numa_memory_bytes = obj->total_memory / BYTES_PER_MB;
333+
#endif
343334
} else {
344335
/* No NUMA domain: */
345336
hw.numa_memory_bytes = hw.system_memory_bytes;
@@ -354,6 +345,39 @@ dart_ret_t dart_hwinfo(
354345
hw.num_cores, hw.core_id, hw.cpu_id);
355346
#endif /* DART_ENABLE_HWLOC */
356347

348+
#ifdef DART_ENABLE_LIKWID
349+
DART_LOG_TRACE("dart_hwinfo: using likwid");
350+
/*
351+
* see likwid API documentation:
352+
* https://rrze-hpc.github.io/likwid/Doxygen/C-likwidAPI-code.html
353+
*/
354+
int likwid_ret = topology_init();
355+
if (likwid_ret < 0) {
356+
DART_LOG_ERROR("dart_hwinfo: "
357+
"likwid: topology_init failed, returned %d", likwid_ret);
358+
} else {
359+
CpuInfo_t info = get_cpuInfo();
360+
CpuTopology_t topo = get_cpuTopology();
361+
if (hw.min_cpu_mhz < 0 || hw.max_cpu_mhz < 0) {
362+
hw.min_cpu_mhz = info->clock;
363+
hw.max_cpu_mhz = info->clock;
364+
}
365+
if (hw.num_numa < 0) {
366+
hw.num_numa = likwid_getNumberOfNodes();
367+
}
368+
if (hw.num_sockets < 0) {
369+
hw.num_sockets = topo->numSockets;
370+
}
371+
if (hw.num_cores < 0) {
372+
hw.num_cores = topo->numCoresPerSocket * hw.num_sockets;
373+
}
374+
topology_finalize();
375+
DART_LOG_TRACE("dart_hwinfo: likwid: "
376+
"num_sockets: %d num_numa: %d num_cores: %d",
377+
hw.num_sockets, hw.num_numa, hw.num_cores);
378+
}
379+
#endif /* DART_ENABLE_LIKWID */
380+
357381
#ifdef DART_ENABLE_PAPI
358382
DART_LOG_TRACE("dart_hwinfo: using PAPI");
359383

0 commit comments

Comments
 (0)