Use HWLOC_OBJ_PU instead of CORE if you want hardware thread instead of
cores.

Note that core_numbers above are logical numbers, not the physical numbers.

Brice

Le 28/01/2011 19:35, Jim Burnes a écrit :
> Yes. There is a way to do that. You bind it to a cpuset.
>
> It will be easier if you know the set of cpu cores you want to bind
> to, but I suppose you could dynamically alter the cpuset.
>
> I haven't tried that though.
>
>
>
> On Fri, Jan 28, 2011 at 11:33 AM, guillaume Arnal
> <guillaume.arnal.35_at_[hidden]> wrote:
>
>> Yes, this helps.
>>
>> However, I complete my second question : is there a way to force my current
>> process to run on 'n' cores ?
>> For example : I have 20 cores for real in my architecture (I'm dreaming
>> ...), but I wish that my process run on only 5 cores. Is it possible with
>> hwloc ?
>>
>> Essayez avec cette orthographe : je completerai ma deuxième
>> Saisissez du texte, l'adresse d'un site Web ou importez un document à
>> traduire.
>> Annuler
>> Écouter
>> Lire phonétiquement
>> Thanks for your help.
>> Guillaume
>>
>> 2011/1/28 Brice Goglin <Brice.Goglin_at_[hidden]>
>>
>>> Le 28/01/2011 15:32, guillaume Arnal a écrit :
>>>
>>>> Hi everyone,
>>>>
>>>> I'm beginner in using hwloc and I have some questions.
>>>>
>>>> First: I'm looking for a way to find which core is using by the
>>>> current thread. (maybe with hwloc_get_thread_cpubind ??)
>>>>
>>>> Second: is there a way to set the number of core usable for the
>>>> current process ?
>>>>
>>>> Thank you in advance for your help.
>>>> Guillaume Arnal
>>>>
>>> Hello,
>>>
>>> First, are you talking about cores for real (one core that may contain
>>> multiple hyperthread), or are physical processors ok (those that you see
>>> in /proc/cpuinfo) ?
>>>
>>> hwloc_get_thread_cpubind() returns the binding of a thread specified by
>>> its Linux thread id number. For the current thread, you may also use
>>> hwloc_get_cpubind() with flag HWLOC_CPUBIND_THREAD. Both give a cpuset
>>> listing all physical processors where the thread is currently allowed to
>>> run. Processes are not bound by default, so the cpuset would contain all
>>> existing processors, even if your thread actually uses a single core.
>>>
>>> hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
>>> hwloc_get_cpubind(topology, cpuset, HWLOC_CPUBIND_THREAD);
>>>
>>>
>>> Once you have a cpuset, you may get the corresponding cores with:
>>>
>>> hwloc_obj_t prev = NULL;
>>> while ((prev = hwloc_get_next_obj_inside_cpuset_by_type(topology, cpuset,
>>> HWLOC_OBJ_CORE, prev)) != NULL)
>>> /* do what you want with object core */
>>>
>>>
>>> If the thread is bound to a single physical processors, you can get its
>>> physical id with:
>>>
>>> hwloc_bitmap_first(cpuset);
>>>
>>>
>>> If you want to force your current process to run on the 3rd core, you
>>> can do something like:
>>>
>>> hwloc_obj_t core = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, 2);
>>> hwloc_set_cpubind(topology, core->cpuset, HWLOC_CPUBIND_PROCESS);
>>>
>>>
>>> Hope this helps,
>>> Brice
>>>
>>> _______________________________________________
>>> hwloc-users mailing list
>>> hwloc-users_at_[hidden]
>>> http://www.open-mpi.org/mailman/listinfo.cgi/hwloc-users>>>
>>
>> _______________________________________________
>> hwloc-users mailing list
>> hwloc-users_at_[hidden]
>> http://www.open-mpi.org/mailman/listinfo.cgi/hwloc-users>>
>>
>>
> _______________________________________________
> hwloc-users mailing list
> hwloc-users_at_[hidden]
> http://www.open-mpi.org/mailman/listinfo.cgi/hwloc-users>