public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53292] New: multi-threaded (OpenMP) is slower than single-threaded
@ 2012-05-09  8:18 fh_p at hotmail dot com
  2012-05-09  9:23 ` [Bug c++/53292] " fh_p at hotmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: fh_p at hotmail dot com @ 2012-05-09  8:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53292

             Bug #: 53292
           Summary: multi-threaded (OpenMP) is slower than single-threaded
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: fh_p@hotmail.com


Created attachment 27352
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27352
cpp file to compile

Hello,

The problem is : multi-threaded (OpenMP) is slower than single-threaded

Test has been ran several times successively.
ChunkSize imposed to avoid false sharing.
Test ran on Ubuntu 12.04 64 bits / 4Gb RAM / CPU i3 (dual core hyper-threaded :
2 physical cores + 2 logical cores) / gcc version : 4.6.2.

Is the problem related to CPU ? i3 hyper-threaded would not be "handled
correctly" by g++ or Ubuntu ?

Can somebody help or give me clue ?

Thanks,

FH

PS : I am not used to post bug, if this bug has not been posted in the right
place feel free to tell me where to post it


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

* [Bug c++/53292] multi-threaded (OpenMP) is slower than single-threaded
  2012-05-09  8:18 [Bug c++/53292] New: multi-threaded (OpenMP) is slower than single-threaded fh_p at hotmail dot com
@ 2012-05-09  9:23 ` fh_p at hotmail dot com
  2012-05-09 10:37 ` fh_p at hotmail dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: fh_p at hotmail dot com @ 2012-05-09  9:23 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53292

--- Comment #1 from FH <fh_p at hotmail dot com> 2012-05-09 09:17:29 UTC ---
I am not sure to know if this problem is related "rather" to gcc or "rather" to
Ubuntu. I started with the assumption that is should "rather" to related to
gcc.


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

* [Bug c++/53292] multi-threaded (OpenMP) is slower than single-threaded
  2012-05-09  8:18 [Bug c++/53292] New: multi-threaded (OpenMP) is slower than single-threaded fh_p at hotmail dot com
  2012-05-09  9:23 ` [Bug c++/53292] " fh_p at hotmail dot com
@ 2012-05-09 10:37 ` fh_p at hotmail dot com
  2012-05-09 12:20 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: fh_p at hotmail dot com @ 2012-05-09 10:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53292

--- Comment #2 from FH <fh_p at hotmail dot com> 2012-05-09 10:16:52 UTC ---
I have just tested on another computer (CPU : Xeon5650 12 cores + OS :
Scientific Linux) => I reproduce the unexpected behavior (OpenMP slower than
single-threaded).

So, I believe the problem is "rather" related to gcc (than to the OS)

When I use more threads (export OMP_NUM_THREADS=2, then 6, then 12), OpenMP is
"more slower" than single-threaded. (behavior related to thread initialisation
?)


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

* [Bug c++/53292] multi-threaded (OpenMP) is slower than single-threaded
  2012-05-09  8:18 [Bug c++/53292] New: multi-threaded (OpenMP) is slower than single-threaded fh_p at hotmail dot com
  2012-05-09  9:23 ` [Bug c++/53292] " fh_p at hotmail dot com
  2012-05-09 10:37 ` fh_p at hotmail dot com
@ 2012-05-09 12:20 ` jakub at gcc dot gnu.org
  2012-05-09 12:56 ` fh_p at hotmail dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-05-09 12:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53292

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|                            |INVALID

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-05-09 12:15:53 UTC ---
This is just a bad "test".  You are storing the values in the different
threads, but then reading everything in a single thread only.


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

* [Bug c++/53292] multi-threaded (OpenMP) is slower than single-threaded
  2012-05-09  8:18 [Bug c++/53292] New: multi-threaded (OpenMP) is slower than single-threaded fh_p at hotmail dot com
                   ` (2 preceding siblings ...)
  2012-05-09 12:20 ` jakub at gcc dot gnu.org
@ 2012-05-09 12:56 ` fh_p at hotmail dot com
  2012-05-09 13:00 ` fh_p at hotmail dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: fh_p at hotmail dot com @ 2012-05-09 12:56 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53292

--- Comment #4 from FH <fh_p at hotmail dot com> 2012-05-09 12:53:46 UTC ---
I don't understand your answer.

Timing just times the for loop. Checking array content is single threaded :
this is added to make sure the for loop has done the job correctly and this
check is not timed. The array to initialize is shared by threads (shared by
default) ans not private to each thread.

To me, the test seems relevant. If it's not, why ? And how to modify it ?


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

* [Bug c++/53292] multi-threaded (OpenMP) is slower than single-threaded
  2012-05-09  8:18 [Bug c++/53292] New: multi-threaded (OpenMP) is slower than single-threaded fh_p at hotmail dot com
                   ` (3 preceding siblings ...)
  2012-05-09 12:56 ` fh_p at hotmail dot com
@ 2012-05-09 13:00 ` fh_p at hotmail dot com
  2012-05-09 13:33 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: fh_p at hotmail dot com @ 2012-05-09 13:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53292

FH <fh_p at hotmail dot com> changed:

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

--- Comment #5 from FH <fh_p at hotmail dot com> 2012-05-09 12:55:56 UTC ---
To me, the test seems relevant. If it's not, why ? And how to modify it ?


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

* [Bug c++/53292] multi-threaded (OpenMP) is slower than single-threaded
  2012-05-09  8:18 [Bug c++/53292] New: multi-threaded (OpenMP) is slower than single-threaded fh_p at hotmail dot com
                   ` (4 preceding siblings ...)
  2012-05-09 13:00 ` fh_p at hotmail dot com
@ 2012-05-09 13:33 ` jakub at gcc dot gnu.org
  2012-05-09 14:48 ` fh_p at hotmail dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-05-09 13:33 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53292

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> 2012-05-09 13:29:00 UTC ---
Sorry, missed you aren't measuring it with the single-threaded loop.  Anyway,
the test is still not relevant, it is purely memory bound, and as you can see
from running it with very small arguments, the thread creation and omp for
initial overhead is in the noise, what you see is just how the cache hierarchy
of your CPU works.  The inner loop in which all the measured time is spent in
is very similar (and even if hand edited to be identical it doesn't help at
all).


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

* [Bug c++/53292] multi-threaded (OpenMP) is slower than single-threaded
  2012-05-09  8:18 [Bug c++/53292] New: multi-threaded (OpenMP) is slower than single-threaded fh_p at hotmail dot com
                   ` (5 preceding siblings ...)
  2012-05-09 13:33 ` jakub at gcc dot gnu.org
@ 2012-05-09 14:48 ` fh_p at hotmail dot com
  2012-05-09 15:02 ` jakub at gcc dot gnu.org
  2012-05-12 21:35 ` fh_p at hotmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: fh_p at hotmail dot com @ 2012-05-09 14:48 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53292

--- Comment #7 from FH <fh_p at hotmail dot com> 2012-05-09 14:36:00 UTC ---
Well...

Still don't really get why it is not possible to improve performance for such
basic things. I tried with allocations up to 7 Gb or more (RAM full + SWAP
full) : I still get the same result that looks unexpected to me ?!

Anyway, I guess I won't be able to get the logic of this...


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

* [Bug c++/53292] multi-threaded (OpenMP) is slower than single-threaded
  2012-05-09  8:18 [Bug c++/53292] New: multi-threaded (OpenMP) is slower than single-threaded fh_p at hotmail dot com
                   ` (6 preceding siblings ...)
  2012-05-09 14:48 ` fh_p at hotmail dot com
@ 2012-05-09 15:02 ` jakub at gcc dot gnu.org
  2012-05-12 21:35 ` fh_p at hotmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-05-09 15:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53292

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-05-09 15:01:24 UTC ---
Just try equivalent pthread program and you'll note the same behavior.

#include <pthread.h>
#include <stdlib.h>

double *p;
int c;

void *tf (void *x)
{
  int i, s = ((long) x) * c, e = s + c;
  for (i = s; i < e; i++)
    p[i] = 1.0;
  return NULL;
}

int
main (int argc, char **argv)
{
  int n = atoi (argv[1]), i;
  int sz = atoi (argv[2]);
  if (n > 32 || n < 1 || sz < 128 || (sz % n) != 0)
    return 1;
  p = malloc (sz * sizeof (double));
  if (p == NULL)
    return 1;
  c = sz / n;
  pthread_t t[32];
  for (i = 1; i < n; i++)
    pthread_create (&t[i], NULL, tf, (void *)(long) i);
  tf ((void *) 0L);
  for (i = 1; i < n; i++)
    pthread_join (t[i], NULL);
  return 0;
}


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

* [Bug c++/53292] multi-threaded (OpenMP) is slower than single-threaded
  2012-05-09  8:18 [Bug c++/53292] New: multi-threaded (OpenMP) is slower than single-threaded fh_p at hotmail dot com
                   ` (7 preceding siblings ...)
  2012-05-09 15:02 ` jakub at gcc dot gnu.org
@ 2012-05-12 21:35 ` fh_p at hotmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: fh_p at hotmail dot com @ 2012-05-12 21:35 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53292

--- Comment #9 from FH <fh_p at hotmail dot com> 2012-05-12 21:27:31 UTC ---
Well...

I tested an OpenMP benchmarch (design to demonstrate OpenMP performances) found
on the web : multi-threaded (OpenMP) is again slower than single-threaded. I
looked at coding with pthreads : same thing.

So, I have a dual-core hyper-threaded PC : I end up with multi-threaded
applications slower than single-threaded and this is supposed to be a "normal"
behavior ?!... Anyway this is still illogical to me ?!?!


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

end of thread, other threads:[~2012-05-12 21:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-09  8:18 [Bug c++/53292] New: multi-threaded (OpenMP) is slower than single-threaded fh_p at hotmail dot com
2012-05-09  9:23 ` [Bug c++/53292] " fh_p at hotmail dot com
2012-05-09 10:37 ` fh_p at hotmail dot com
2012-05-09 12:20 ` jakub at gcc dot gnu.org
2012-05-09 12:56 ` fh_p at hotmail dot com
2012-05-09 13:00 ` fh_p at hotmail dot com
2012-05-09 13:33 ` jakub at gcc dot gnu.org
2012-05-09 14:48 ` fh_p at hotmail dot com
2012-05-09 15:02 ` jakub at gcc dot gnu.org
2012-05-12 21:35 ` fh_p at hotmail 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).