public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Openmp sections
@ 2008-03-29 17:27 Christoph Bartoschek
  2008-03-29 17:42 ` Christoph Bartoschek
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Bartoschek @ 2008-03-29 17:27 UTC (permalink / raw)
  To: gcc-help

Hi,

why is the following code not executed in parallel:

#include <iostream>
#include <omp.h>
 
int main()
{
 
#pragma omp sections nowait
{
  #pragma omp section
  {
    int i = 0;
    while (true) {
      ++i;
      if (i % 1000000 == 0) {
         std::cerr << "1. Thread: " << omp_get_thread_num() 
                   << "  i = " << i << std::endl;
      } 
    }
  }

  #pragma omp section
  {
    int i;
    while (true) {
      ++i;
      if (i % 1000000 == 0) {
        std::cerr << "2. Thread: " << omp_get_thread_num()
                  << "  i = " << i << std::endl;
      }
    }
  }
}

}

I know that the usage of std::cerr is not threadsafe. But this is only to see 
that only one thread is running. If I remove it, there still only one thread 
running.

I use g++ 4.3.0 and compile with:

g++ -fopenmp test.C -lgomp

./a.out prints only messages from 1. Thread.

Greetings
Christoph

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

* Re: Openmp sections
  2008-03-29 17:27 Openmp sections Christoph Bartoschek
@ 2008-03-29 17:42 ` Christoph Bartoschek
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Bartoschek @ 2008-03-29 17:42 UTC (permalink / raw)
  To: gcc-help

I have changed the code to

#pragma omp parallel sections 

But now I get an SIGILL.

Here is the console log:

-bash-3.00$ LANG=C gdb ./a.out
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu"...
Using host libthread_db library "/lib64/tls/libthread_db.so.1".
(gdb) run
Starting program: /lfs/user/bartosch/cg/a.out
[Thread debugging using libthread_db enabled]
[New Thread 182898459584 (LWP 16540)]
1
8
[New Thread 1084229984 (LWP 16543)]
[New Thread 1094719840 (LWP 16544)]
[New Thread 1105209696 (LWP 16545)]
[New Thread 1115699552 (LWP 16546)]
[New Thread 1126189408 (LWP 16547)]
[New Thread 1136679264 (LWP 16548)]
[New Thread 1147169120 (LWP 16549)]

Program received signal SIGILL, Illegal instruction.
[Switching to Thread 1094719840 (LWP 16544)]
0x0000000000400a93 in main.omp_fn.0 (.omp_data_i=0x0) at ga.C:10
10      #pragma omp parallel sections
(gdb) where
#0  0x0000000000400a93 in main.omp_fn.0 (.omp_data_i=0x0) at ga.C:10
#1  0x0000002a9555b635 in gomp_thread_start (xdata=<value optimized out>) 
at ../../../gcc-4.3.0/libgomp/team.c:108
#2  0x0000003e90c0610a in start_thread () from /lib64/tls/libpthread.so.0
#3  0x0000003e8fdc68c3 in clone () from /lib64/tls/libc.so.6
#4  0x0000000000000000 in ?? ()
(gdb) wherei
Undefined command: "wherei".  Try "help".
(gdb) disassemble
Dump of assembler code for function main.omp_fn.0:
0x0000000000400a6e <main.omp_fn.0+0>:   push   %rbp
0x0000000000400a6f <main.omp_fn.0+1>:   mov    %rsp,%rbp
0x0000000000400a72 <main.omp_fn.0+4>:   sub    $0x20,%rsp
0x0000000000400a76 <main.omp_fn.0+8>:   mov    %rdi,0xffffffffffffffe8(%rbp)
0x0000000000400a7a <main.omp_fn.0+12>:  mov    $0x2,%edi
0x0000000000400a7f <main.omp_fn.0+17>:  callq  0x400900 
<GOMP_sections_start@plt>
0x0000000000400a84 <main.omp_fn.0+22>:  mov    %eax,0xffffffffffffffe4(%rbp)
0x0000000000400a87 <main.omp_fn.0+25>:  cmpl   $0x1,0xffffffffffffffe4(%rbp)
0x0000000000400a8b <main.omp_fn.0+29>:  je     0x400aa2 <main.omp_fn.0+52>
0x0000000000400a8d <main.omp_fn.0+31>:  cmpl   $0x2,0xffffffffffffffe4(%rbp)
0x0000000000400a91 <main.omp_fn.0+35>:  je     0x400a95 <main.omp_fn.0+39>
0x0000000000400a93 <main.omp_fn.0+37>:  ud2a
0x0000000000400a95 <main.omp_fn.0+39>:  movl   $0x0,0xfffffffffffffff8(%rbp)
0x0000000000400a9c <main.omp_fn.0+46>:  addl   $0x1,0xfffffffffffffff8(%rbp)
0x0000000000400aa0 <main.omp_fn.0+50>:  jmp    0x400a9c <main.omp_fn.0+46>
0x0000000000400aa2 <main.omp_fn.0+52>:  movl   $0x0,0xfffffffffffffffc(%rbp)
0x0000000000400aa9 <main.omp_fn.0+59>:  addl   $0x1,0xfffffffffffffffc(%rbp)
0x0000000000400aad <main.omp_fn.0+63>:  jmp    0x400aa9 <main.omp_fn.0+59>
End of assembler dump.
(gdb)  

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

end of thread, other threads:[~2008-03-29 17:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-29 17:27 Openmp sections Christoph Bartoschek
2008-03-29 17:42 ` Christoph Bartoschek

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).