Commit 7529ef20 authored by Philippe SWARTVAGHER's avatar Philippe SWARTVAGHER
Browse files

Warn if several OpenMP threads are on the same core

parent f9e9e0ff
......@@ -31,19 +31,47 @@ int get_nb_openmp_threads()
}
}
/* Check worker binding in this function, to check it at the beginning of
* the program, in all cases.
* The check can be done several times, because if the binding is wrong,
* threads may move, and only one check can fail. */
get_worker_binding_ids(NULL, nb, NULL);
return nb;
}
void get_worker_binding_ids(hwloc_topology_t topo, int nb_threads, int* thread_binding)
void get_worker_binding_ids(hwloc_topology_t topo, int nb_threads, int* _thread_binding)
{
int* thread_binding = _thread_binding;
if (_thread_binding == NULL)
{
thread_binding = malloc(nb_threads*sizeof(int));
}
#pragma omp parallel for schedule(static, 1)
for (int i = 0; i < nb_threads; i++)
{
int core_os = sched_getcpu();
int logical_core = hwloc_get_pu_obj_by_os_index(topo, core_os)->logical_index;
int logical_core = (topo == NULL) ? core_os : hwloc_get_pu_obj_by_os_index(topo, core_os)->logical_index;
thread_binding[i] = logical_core;
}
for (int i = 0; i < nb_threads-1; i++)
{
for (int j = i+1; j < nb_threads; j++)
{
if (thread_binding[i] == thread_binding[j])
{
fprintf(stderr, "Warning: OpenMP threads %d and %d are bound on the same core %s#%d.\n", i, j, (topo == NULL) ? "P" : "L", thread_binding[i]);
}
}
}
if (_thread_binding == NULL)
{
free(thread_binding);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment