Open MPI logo

Hardware Locality Users' Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Hardware Locality Users mailing list

Subject: Re: [hwloc-users] Thread core affinity
From: Brice Goglin (Brice.Goglin_at_[hidden])
Date: 2011-07-29 07:42:11


I think both codes are equivalent and correct on this machine.
hwloc_get_obj_by_type() returns logically-index ojects, that what's you
want for consecutive binding. There's one hyperthread/PU per Core on
your machine. So binding on core #3 is equivalent to binding on PU #3
(they should have the same cpusets here). No physical index is ever
involved in this code.

If you ever want to support SMT machines as well:
* if you still want one process per core, use the code with HWLOC_OBJ_CORE
* if you want one process per hyperthread, use the code with HWLOC_OBJ_PU

Brice

Le 29/07/2011 13:33, Gabriele Fatigati a écrit :
> Sorry,
>
> I forgot to tell you these code block is inside a parallel OpenMP
> region. This is the complete code:
>
> #pragma omp parallel num_threads(6)
> {
> int tid = omp_get_thread_num();
>
> hwloc_obj_t core = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, tid);
> hwloc_cpuset_t set = hwloc_bitmap_dup(core->cpuset);
> hwloc_bitmap_singlify(set);
>
> hwloc_set_cpubind(topology, set, HWLOC_CPUBIND_THREAD);
>
> hwloc_bitmap_free(set);
>
> }
>
> and other code block is:
>
> #pragma omp parallel num_threads(6)
> {
> int tid = omp_get_thread_num();
>
> hwloc_obj_t core = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, tid);
> hwloc_cpuset_t set = hwloc_bitmap_dup(core->cpuset);
> hwloc_bitmap_singlify(set);
>
> hwloc_set_cpubind(topology, set, HWLOC_CPUBIND_THREAD);
>
> hwloc_bitmap_free(set);
>
> }
>
>
> The goal is physically bind threads as near as possible, one thread
> per core. Since core ids reported on hwloc-hello.c are not
> consecutive and not exclusive, I suppose is better and more sure to
> use PU id. Or not?
>
>
>
> 2011/7/29 Samuel Thibault <samuel.thibault_at_[hidden]
> <mailto:samuel.thibault_at_[hidden]>>
>
> Gabriele Fatigati, le Fri 29 Jul 2011 13:24:17 +0200, a écrit :
> > yhanks for yout quick reply!
> >
> > But i have a litte doubt. in a non SMT machine, Is it better use
> this:
> >
> > hwloc_obj_t core = hwloc_get_obj_by_type(topology,
> HWLOC_OBJ_CORE, tid);
> > hwloc_cpuset_t set = hwloc_bitmap_dup(core->cpuset);
> > hwloc_bitmap_singlify(set);
> > hwloc_set_cpubind(topology, set, HWLOC_CPUBIND_THREAD);
> >
> > or:
> >
> > hwloc_obj_t core = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU,
> tid);
> > hwloc_cpuset_t set = hwloc_bitmap_dup(core->cpuset);
> > hwloc_bitmap_singlify(set);
> > hwloc_set_cpubind(topology, set, HWLOC_CPUBIND_THREAD);
> >
> > because work in the same way( i suppose).
>
> They'll both work about the same way on SMT too, since in the end
> it'll
> pick up only one thread. Whether you want to assign threads to
> cores or
> threads then depends on your application: do you want to let its
> threads
> share a core or not.
>
> Samuel
> _______________________________________________
> hwloc-users mailing list
> hwloc-users_at_[hidden] <mailto:hwloc-users_at_[hidden]>
> http://www.open-mpi.org/mailman/listinfo.cgi/hwloc-users
>
>
>
>
> --
> Ing. Gabriele Fatigati
>
> Parallel programmer
>
> CINECA Systems & Tecnologies Department
>
> Supercomputing Group
>
> Via Magnanelli 6/3, Casalecchio di Reno (BO) Italy
>
> www.cineca.it <http://www.cineca.it> Tel: +39 051
> 6171722
>
> g.fatigati [AT] cineca.it <http://cineca.it>
>
>
> _______________________________________________
> hwloc-users mailing list
> hwloc-users_at_[hidden]
> http://www.open-mpi.org/mailman/listinfo.cgi/hwloc-users