public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgomp/102320] New: Set cpu affinity error
@ 2021-09-14  9:22 zhuguanghong at uniontech dot com
  2021-09-14 12:05 ` [Bug libgomp/102320] " zhuguanghong at uniontech dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: zhuguanghong at uniontech dot com @ 2021-09-14  9:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102320

            Bug ID: 102320
           Summary: Set cpu affinity error
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgomp
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhuguanghong at uniontech dot com
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

libgomp/config/linux/affinity.c
this   is error ?
.......

void
gomp_init_affinity (void)
{
  if (gomp_places_list == NULL)
    {
      if (!gomp_affinity_init_level (1, ULONG_MAX, true))
        return;
    }

  struct gomp_thread *thr = gomp_thread ();
  pthread_setaffinity_np (pthread_self (), gomp_cpuset_size,
                          (cpu_set_t *) gomp_places_list[0]); // this set one
cpu ?because parse_affinity 
  thr->place = 1;
  thr->ts.place_partition_off = 0;
  thr->ts.place_partition_len = gomp_places_list_len;
}
.......






parse_affinity
......

 while (needed--)
 11                 {
 10                   void *p = gomp_places_list[gomp_places_list_len];
  9                   gomp_affinity_init_place (p);
  8                   if (gomp_affinity_add_cpus (p, cpu_beg, 1, 0,
true))//different  cpuset ,GOMP_CPU_AFFINITY=0-x ,gomp_places_list[0] is ?
  7                     ++gomp_places_list_len;
  6                   cpu_beg += cpu_stride;
  5                 }


......

//error

GOMP_CPU_AFFINITY=0-x

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgomp/102320] Set cpu affinity error
  2021-09-14  9:22 [Bug libgomp/102320] New: Set cpu affinity error zhuguanghong at uniontech dot com
@ 2021-09-14 12:05 ` zhuguanghong at uniontech dot com
  2021-09-14 12:10 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: zhuguanghong at uniontech dot com @ 2021-09-14 12:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102320

--- Comment #1 from zhuguanghong <zhuguanghong at uniontech dot com> ---
fix? like  this ?
 while(gomp_places_list_len-- ){
           *(gomp_places_list[0]) | = *(gomp_places_list[gomp_places_list_len])

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgomp/102320] Set cpu affinity error
  2021-09-14  9:22 [Bug libgomp/102320] New: Set cpu affinity error zhuguanghong at uniontech dot com
  2021-09-14 12:05 ` [Bug libgomp/102320] " zhuguanghong at uniontech dot com
@ 2021-09-14 12:10 ` jakub at gcc dot gnu.org
  2021-09-14 12:16 ` zhuguanghong at uniontech dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-14 12:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102320

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I'm sorry but from the above it is impossible to decipher what do you think is
a bug and why.
Can you write a few sentences about what env var or cpu configuration do you
think misbehaves and why?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgomp/102320] Set cpu affinity error
  2021-09-14  9:22 [Bug libgomp/102320] New: Set cpu affinity error zhuguanghong at uniontech dot com
  2021-09-14 12:05 ` [Bug libgomp/102320] " zhuguanghong at uniontech dot com
  2021-09-14 12:10 ` jakub at gcc dot gnu.org
@ 2021-09-14 12:16 ` zhuguanghong at uniontech dot com
  2021-09-14 12:19 ` zhuguanghong at uniontech dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: zhuguanghong at uniontech dot com @ 2021-09-14 12:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102320

--- Comment #3 from zhuguanghong <zhuguanghong at uniontech dot com> ---
hi ,thanks for your reply

 initialize_env (void)
  1 {
  0   ........                                                                  
  1   if (parse_affinity (ignore))
  2     {
  3       if (gomp_global_icv.bind_var == omp_proc_bind_false)
  4         gomp_global_icv.bind_var = true;
  5       ignore = true;
  6     }
  7   if (gomp_global_icv.bind_var != omp_proc_bind_false)
  8     gomp_init_affinity ();

Set the cpuset in the parse_affinity function and set it in different
gomp_places_list .the cpuset is set in the parse_affinity function and is set
in different gomp_places_list, but in the function gomp_init_affinity it is
only set using gomp_places_list[0]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgomp/102320] Set cpu affinity error
  2021-09-14  9:22 [Bug libgomp/102320] New: Set cpu affinity error zhuguanghong at uniontech dot com
                   ` (2 preceding siblings ...)
  2021-09-14 12:16 ` zhuguanghong at uniontech dot com
@ 2021-09-14 12:19 ` zhuguanghong at uniontech dot com
  2021-09-14 12:20 ` zhuguanghong at uniontech dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: zhuguanghong at uniontech dot com @ 2021-09-14 12:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102320

--- Comment #4 from zhuguanghong <zhuguanghong at uniontech dot com> ---
This leads to when I set the environment variable "GOMP_CPU_AFFINITY=0-7" and
call the initialize_env function, the thread will be automatically bound to one
cpu and cannot be scheduled to other cpu.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgomp/102320] Set cpu affinity error
  2021-09-14  9:22 [Bug libgomp/102320] New: Set cpu affinity error zhuguanghong at uniontech dot com
                   ` (3 preceding siblings ...)
  2021-09-14 12:19 ` zhuguanghong at uniontech dot com
@ 2021-09-14 12:20 ` zhuguanghong at uniontech dot com
  2021-09-14 12:32 ` jakub at gcc dot gnu.org
  2021-09-14 12:35 ` zhuguanghong at uniontech dot com
  6 siblings, 0 replies; 8+ messages in thread
From: zhuguanghong at uniontech dot com @ 2021-09-14 12:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102320

--- Comment #5 from zhuguanghong <zhuguanghong at uniontech dot com> ---
But what I want is that 0-7cpu can run this thread

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgomp/102320] Set cpu affinity error
  2021-09-14  9:22 [Bug libgomp/102320] New: Set cpu affinity error zhuguanghong at uniontech dot com
                   ` (4 preceding siblings ...)
  2021-09-14 12:20 ` zhuguanghong at uniontech dot com
@ 2021-09-14 12:32 ` jakub at gcc dot gnu.org
  2021-09-14 12:35 ` zhuguanghong at uniontech dot com
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-14 12:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102320

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
That is just a wrong expectation.  GOMP_CPU_AFFINITY is IMHO clearly documented
what it does:
Binds threads to specific CPUs.  The variable should contain a space-separated
or comma-separated list of CPUs.  This list may contain different kinds of
entries: either single CPU numbers in any order, a range of CPUs (M-N)
or a range with some stride (M-N:S).  CPU numbers are zero based.  For example,
@code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
and 14 respectively and then start assigning back from the beginning of
the list.  @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.

So, if you use 0-7, the first thread (initial thread) goes to cpu 0, second to
1, etc. up to 7 and then again from the beginning of the list.

If you want something else, you can use the standard OMP_PLACES variable, which
allows you to define a place as having a set of CPUs and then bind threads to
selected places.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgomp/102320] Set cpu affinity error
  2021-09-14  9:22 [Bug libgomp/102320] New: Set cpu affinity error zhuguanghong at uniontech dot com
                   ` (5 preceding siblings ...)
  2021-09-14 12:32 ` jakub at gcc dot gnu.org
@ 2021-09-14 12:35 ` zhuguanghong at uniontech dot com
  6 siblings, 0 replies; 8+ messages in thread
From: zhuguanghong at uniontech dot com @ 2021-09-14 12:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102320

--- Comment #7 from zhuguanghong <zhuguanghong at uniontech dot com> ---
I get it, thank you for your answer

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-09-14 12:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14  9:22 [Bug libgomp/102320] New: Set cpu affinity error zhuguanghong at uniontech dot com
2021-09-14 12:05 ` [Bug libgomp/102320] " zhuguanghong at uniontech dot com
2021-09-14 12:10 ` jakub at gcc dot gnu.org
2021-09-14 12:16 ` zhuguanghong at uniontech dot com
2021-09-14 12:19 ` zhuguanghong at uniontech dot com
2021-09-14 12:20 ` zhuguanghong at uniontech dot com
2021-09-14 12:32 ` jakub at gcc dot gnu.org
2021-09-14 12:35 ` zhuguanghong at uniontech dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).