public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Ask for help
@ 2009-03-17 14:45 Wei, Wanxia
  2009-03-17 14:51 ` Andrew Haley
  2009-03-17 15:02 ` John Fine
  0 siblings, 2 replies; 13+ messages in thread
From: Wei, Wanxia @ 2009-03-17 14:45 UTC (permalink / raw)
  To: gcc-help

Dear Sir/Madam:

I am sorry I met a problem when I used gcc to compile my C program and ran the
executables on servers. I compiled my C program with the following two different ways
with different options.

gcc -m32 -O3 -DNDEBUG -fno-strict-aliasing -static –lm

gcc -m32 –O3 –lm

My problem is that the two executables obtained by using the above two ways have the
same performance on some inputs but have different performance on other inputs. I am
sorry I do not know whether executables with different options should always have the
same performance if the parameters are the same when executing these two executables.
If two executables with different options should always have the same performance, the
different performance of the two executables of my C program means there are bugs in
this program?

Thank you for your time and help. 

Yours sincerely, 

Wanxia Wei

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

* Re: Ask for help
  2009-03-17 14:45 Ask for help Wei, Wanxia
@ 2009-03-17 14:51 ` Andrew Haley
  2009-03-17 15:02 ` John Fine
  1 sibling, 0 replies; 13+ messages in thread
From: Andrew Haley @ 2009-03-17 14:51 UTC (permalink / raw)
  To: wanxia.wei; +Cc: gcc-help

Wei, Wanxia wrote:
> Dear Sir/Madam:
> 
> I am sorry I met a problem when I used gcc to compile my C program and ran the
> executables on servers. I compiled my C program with the following two different ways
> with different options.
> 
> gcc -m32 -O3 -DNDEBUG -fno-strict-aliasing -static –lm
> 
> gcc -m32 –O3 –lm
> 
> My problem is that the two executables obtained by using the above two ways have the
> same performance on some inputs but have different performance on other inputs.

I'd expect that.  -fno-strict-aliasing has some performance impact.

> If two executables with different options should always have the same performance,

Certainly not, no, especially when one of the options controls optimization.

Andrew.

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

* Re: Ask for help
  2009-03-17 14:45 Ask for help Wei, Wanxia
  2009-03-17 14:51 ` Andrew Haley
@ 2009-03-17 15:02 ` John Fine
  2009-03-17 15:36   ` Wei, Wanxia
  1 sibling, 1 reply; 13+ messages in thread
From: John Fine @ 2009-03-17 15:02 UTC (permalink / raw)
  To: gcc-help; +Cc: wanxia.wei, Andrew Haley

If your meaning for the word "performance" is the usual meaning, the 
earlier response by Andrew Haley answers the whole question.

But the way you phrased the question makes me think you meant "behavior" 
when you wrote "performance".

-fno-strict-aliasing can give you correct behavior from a program that 
incorrectly uses a reinterpret_cast or similar operation. That should be 
considered a bug, and if there are few of those in your code, you should 
find and correct them.

Some old code has enough incorrect reinterpret_cast operations that 
correcting them is impractical and you need the -fno-strict-aliasing

I'm not sure what -DNDEBUG or -static might change in the behavior or 
performance of your code. I'm just guessing that -fno-strict-aliasing is 
the important difference.

Wei, Wanxia wrote:
> gcc -m32 -O3 -DNDEBUG -fno-strict-aliasing -static –lm
>
> gcc -m32 –O3 –lm
>
>   
...
>  the
> different performance of the two executables of my C program means there are bugs in
> this program?
>
>   

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

* Re: Ask for help
  2009-03-17 15:02 ` John Fine
@ 2009-03-17 15:36   ` Wei, Wanxia
  2009-03-17 15:42     ` Michael Wieher
  2009-03-17 16:05     ` Andrew Haley
  0 siblings, 2 replies; 13+ messages in thread
From: Wei, Wanxia @ 2009-03-17 15:36 UTC (permalink / raw)
  To: John Fine; +Cc: gcc-help, Andrew Haley, brian

Dear All:

Thank you all for your quick help. 

My C program is a local search algorithm for solving SAT (Satisfiability problem). The
following is a brief description of this program. 

This program uses random integers to generate an initial assignment to a SAT instance.
Then, it chooses a variable by using a heuristic and then flips this variable (flip
means to change the value of a variable from 0 to 1 or from 1 to 0) in each search
step. After many search steps, if the assignment satisfies the instance, this program
stops. If the assignment still does not satisfy the instance after many search steps,
this program stops after a predefined number of search steps. The number of search
steps is what I call performance in my previous e-mail. In addition, this program uses
both static and dynamic allocations. 

When I ran the two executables with different options on some SAT instances, they have
different flip numbers (the parameters for these two executables are the same. For
example, I use the same seed for them to generate initial assignments).  I ran the
executable generated by using “gcc -m32 –O3 –lm” on a wide range of instance on
different servers for more than 1 year but I never got any errors (such as core dump).


If possible, please tell me what reinterpret_cast or similar operation is so that I can
look for bugs from such operations in my program. 

Thank you very much for your time and help. 

Wanxia






Quoting John Fine <johnsfine@verizon.net>:

> If your meaning for the word "performance" is the usual meaning, the 
> earlier response by Andrew Haley answers the whole question.
> 
> But the way you phrased the question makes me think you meant "behavior" 
> when you wrote "performance".
> 
> -fno-strict-aliasing can give you correct behavior from a program that 
> incorrectly uses a reinterpret_cast or similar operation. That should be 
> considered a bug, and if there are few of those in your code, you should 
> find and correct them.
> 
> Some old code has enough incorrect reinterpret_cast operations that 
> correcting them is impractical and you need the -fno-strict-aliasing
> 
> I'm not sure what -DNDEBUG or -static might change in the behavior or 
> performance of your code. I'm just guessing that -fno-strict-aliasing is 
> the important difference.
> 
> Wei, Wanxia wrote:
> > gcc -m32 -O3 -DNDEBUG -fno-strict-aliasing -static –lm
> >
> > gcc -m32 –O3 –lm
> >
> >   
> ...
> >  the
> > different performance of the two executables of my C program means there are bugs
> in
> > this program?
> >
> >   
> 



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

* Re: Ask for help
  2009-03-17 15:36   ` Wei, Wanxia
@ 2009-03-17 15:42     ` Michael Wieher
  2009-03-17 16:05     ` Andrew Haley
  1 sibling, 0 replies; 13+ messages in thread
From: Michael Wieher @ 2009-03-17 15:42 UTC (permalink / raw)
  To: GCC-help

not to play devil's advocate, but couldn't you just stop optimizing
the code and let it run?
if you're not concerned (as much) with speed as accurate results and
getting (apparently) inaccurate results with an optimization ....
then don't optimize?





On Tue, Mar 17, 2009 at 10:36 AM, Wei, Wanxia <v592e@unb.ca> wrote:
> Dear All:
>
> Thank you all for your quick help.
>
> My C program is a local search algorithm for solving SAT (Satisfiability problem). The
> following is a brief description of this program.
>
> This program uses random integers to generate an initial assignment to a SAT instance.
> Then, it chooses a variable by using a heuristic and then flips this variable (flip
> means to change the value of a variable from 0 to 1 or from 1 to 0) in each search
> step. After many search steps, if the assignment satisfies the instance, this program
> stops. If the assignment still does not satisfy the instance after many search steps,
> this program stops after a predefined number of search steps. The number of search
> steps is what I call performance in my previous e-mail. In addition, this program uses
> both static and dynamic allocations.
>
> When I ran the two executables with different options on some SAT instances, they have
> different flip numbers (the parameters for these two executables are the same. For
> example, I use the same seed for them to generate initial assignments).  I ran the
> executable generated by using “gcc -m32 –O3 –lm” on a wide range of instance on
> different servers for more than 1 year but I never got any errors (such as core dump).
>
>
> If possible, please tell me what reinterpret_cast or similar operation is so that I can
> look for bugs from such operations in my program.
>
> Thank you very much for your time and help.
>
> Wanxia
>
>
>
>
>
>
> Quoting John Fine <johnsfine@verizon.net>:
>
>> If your meaning for the word "performance" is the usual meaning, the
>> earlier response by Andrew Haley answers the whole question.
>>
>> But the way you phrased the question makes me think you meant "behavior"
>> when you wrote "performance".
>>
>> -fno-strict-aliasing can give you correct behavior from a program that
>> incorrectly uses a reinterpret_cast or similar operation. That should be
>> considered a bug, and if there are few of those in your code, you should
>> find and correct them.
>>
>> Some old code has enough incorrect reinterpret_cast operations that
>> correcting them is impractical and you need the -fno-strict-aliasing
>>
>> I'm not sure what -DNDEBUG or -static might change in the behavior or
>> performance of your code. I'm just guessing that -fno-strict-aliasing is
>> the important difference.
>>
>> Wei, Wanxia wrote:
>> > gcc -m32 -O3 -DNDEBUG -fno-strict-aliasing -static –lm
>> >
>> > gcc -m32 –O3 –lm
>> >
>> >
>> ...
>> >  the
>> > different performance of the two executables of my C program means there are bugs
>> in
>> > this program?
>> >
>> >
>>
>
>
>
>



-- 
~ When the great Tao is forgotten, kindness and morality arise.

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

* Re: Ask for help
  2009-03-17 15:36   ` Wei, Wanxia
  2009-03-17 15:42     ` Michael Wieher
@ 2009-03-17 16:05     ` Andrew Haley
  2009-03-17 20:13       ` Wei, Wanxia
  1 sibling, 1 reply; 13+ messages in thread
From: Andrew Haley @ 2009-03-17 16:05 UTC (permalink / raw)
  To: wanxia.wei; +Cc: gcc-help

Wei, Wanxia wrote:

> My C program is a local search algorithm for solving SAT (Satisfiability problem). The
> following is a brief description of this program. 
> 
> This program uses random integers to generate an initial assignment to a SAT instance.
> Then, it chooses a variable by using a heuristic and then flips this variable (flip
> means to change the value of a variable from 0 to 1 or from 1 to 0) in each search
> step. After many search steps, if the assignment satisfies the instance, this program
> stops. If the assignment still does not satisfy the instance after many search steps,
> this program stops after a predefined number of search steps. The number of search
> steps is what I call performance in my previous e-mail. In addition, this program uses
> both static and dynamic allocations. 
> 
> When I ran the two executables with different options on some SAT instances, they have
> different flip numbers (the parameters for these two executables are the same. For
> example, I use the same seed for them to generate initial assignments).  I ran the
> executable generated by using “gcc -m32 –O3 –lm” on a wide range of instance on
> different servers for more than 1 year but I never got any errors (such as core dump).

Well, this is hard.  If your program behaves differently when
-fno-strict-aliasing is used then it's very likely that, yes, your
program has a bug.  But for me to explain what -fno-strict-aliasing
does requires you to have a fairly good understanding of the C
language. There's a fairly good explanation at
http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html

In summary,

"Dereferencing a cast of a variable from one type of pointer to a different type is
_usually_ in violation of the strict aliasing rule."

Andrew.

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

* Re: Ask for help
  2009-03-17 16:05     ` Andrew Haley
@ 2009-03-17 20:13       ` Wei, Wanxia
  0 siblings, 0 replies; 13+ messages in thread
From: Wei, Wanxia @ 2009-03-17 20:13 UTC (permalink / raw)
  To: Andrew Haley; +Cc: gcc-help

Dear Mr. Haley:

Thank you for your suggestions. 

I will read the materials at
http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html and
try to find the bugs in my program. 

Thank you for very much your time and help. 

Wanxia


Quoting Andrew Haley <aph@redhat.com>:

> Wei, Wanxia wrote:
> 
> > My C program is a local search algorithm for solving SAT (Satisfiability problem).
> The
> > following is a brief description of this program. 
> > 
> > This program uses random integers to generate an initial assignment to a SAT
> instance.
> > Then, it chooses a variable by using a heuristic and then flips this variable
> (flip
> > means to change the value of a variable from 0 to 1 or from 1 to 0) in each search
> > step. After many search steps, if the assignment satisfies the instance, this
> program
> > stops. If the assignment still does not satisfy the instance after many search
> steps,
> > this program stops after a predefined number of search steps. The number of search
> > steps is what I call performance in my previous e-mail. In addition, this program
> uses
> > both static and dynamic allocations. 
> > 
> > When I ran the two executables with different options on some SAT instances, they
> have
> > different flip numbers (the parameters for these two executables are the same. For
> > example, I use the same seed for them to generate initial assignments).  I ran the
> > executable generated by using “gcc -m32 –O3 –lm” on a wide range of
> instance on
> > different servers for more than 1 year but I never got any errors (such as core
> dump).
> 
> Well, this is hard.  If your program behaves differently when
> -fno-strict-aliasing is used then it's very likely that, yes, your
> program has a bug.  But for me to explain what -fno-strict-aliasing
> does requires you to have a fairly good understanding of the C
> language. There's a fairly good explanation at
> http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html
> 
> In summary,
> 
> "Dereferencing a cast of a variable from one type of pointer to a different type is
> _usually_ in violation of the strict aliasing rule."
> 
> Andrew.
> 



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

* Ask for help
  1999-09-26 17:36 Haifeng (Tommy) Shen
  1999-09-26 17:50 ` Alexandre Oliva
  1999-09-30 23:56 ` Haifeng (Tommy) Shen
@ 1999-10-01  0:00 ` Haifeng (Tommy) Shen
  2 siblings, 0 replies; 13+ messages in thread
From: Haifeng (Tommy) Shen @ 1999-10-01  0:00 UTC (permalink / raw)
  To: bug-gcc; +Cc: help-gcc

Hi there,


Can anybody tell me how to redirect compling results to a file? I cannot
find an option similar to "Xstdout" in javac by which compiling results 
can be redirected to a file.


Thanks,
Tommy


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

* Re: Ask for help
  1999-09-26 17:50 ` Alexandre Oliva
  1999-09-30 23:56   ` Alexandre Oliva
@ 1999-10-01  0:00   ` Alexandre Oliva
  1 sibling, 0 replies; 13+ messages in thread
From: Alexandre Oliva @ 1999-10-01  0:00 UTC (permalink / raw)
  To: Haifeng (Tommy) Shen; +Cc: bug-gcc, help-gcc

On Sep 26, 1999, "Haifeng (Tommy) Shen" <hfshen@cit.gu.edu.au> wrote:

> Can anybody tell me how to redirect compling results to a file? I
> cannot find an option similar to "Xstdout" in javac by which
> compiling results can be redirected to a file.

That's because such kind of redirection can be easily handled by the
shell from which you invoke gcc:

gcc ... > output.file 2>&1  # if you use sh, ksh, zsh or bash
gcc ... >& output.file      # if you use csh or tcsh

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{lsd.ic.unicamp.br,guarana.{org,com}} aoliva@{acm,computer}.org
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them

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

* Re: Ask for help
  1999-09-26 17:50 ` Alexandre Oliva
@ 1999-09-30 23:56   ` Alexandre Oliva
  1999-10-01  0:00   ` Alexandre Oliva
  1 sibling, 0 replies; 13+ messages in thread
From: Alexandre Oliva @ 1999-09-30 23:56 UTC (permalink / raw)
  To: Haifeng (Tommy) Shen; +Cc: bug-gcc, help-gcc

On Sep 26, 1999, "Haifeng (Tommy) Shen" <hfshen@cit.gu.edu.au> wrote:

> Can anybody tell me how to redirect compling results to a file? I
> cannot find an option similar to "Xstdout" in javac by which
> compiling results can be redirected to a file.

That's because such kind of redirection can be easily handled by the
shell from which you invoke gcc:

gcc ... > output.file 2>&1  # if you use sh, ksh, zsh or bash
gcc ... >& output.file      # if you use csh or tcsh

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{lsd.ic.unicamp.br,guarana.{org,com}} aoliva@{acm,computer}.org
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them

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

* Ask for help
  1999-09-26 17:36 Haifeng (Tommy) Shen
  1999-09-26 17:50 ` Alexandre Oliva
@ 1999-09-30 23:56 ` Haifeng (Tommy) Shen
  1999-10-01  0:00 ` Haifeng (Tommy) Shen
  2 siblings, 0 replies; 13+ messages in thread
From: Haifeng (Tommy) Shen @ 1999-09-30 23:56 UTC (permalink / raw)
  To: bug-gcc; +Cc: help-gcc

Hi there,


Can anybody tell me how to redirect compling results to a file? I cannot
find an option similar to "Xstdout" in javac by which compiling results 
can be redirected to a file.


Thanks,
Tommy


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

* Re: Ask for help
  1999-09-26 17:36 Haifeng (Tommy) Shen
@ 1999-09-26 17:50 ` Alexandre Oliva
  1999-09-30 23:56   ` Alexandre Oliva
  1999-10-01  0:00   ` Alexandre Oliva
  1999-09-30 23:56 ` Haifeng (Tommy) Shen
  1999-10-01  0:00 ` Haifeng (Tommy) Shen
  2 siblings, 2 replies; 13+ messages in thread
From: Alexandre Oliva @ 1999-09-26 17:50 UTC (permalink / raw)
  To: Haifeng (Tommy) Shen; +Cc: bug-gcc, help-gcc

On Sep 26, 1999, "Haifeng (Tommy) Shen" <hfshen@cit.gu.edu.au> wrote:

> Can anybody tell me how to redirect compling results to a file? I
> cannot find an option similar to "Xstdout" in javac by which
> compiling results can be redirected to a file.

That's because such kind of redirection can be easily handled by the
shell from which you invoke gcc:

gcc ... > output.file 2>&1  # if you use sh, ksh, zsh or bash
gcc ... >& output.file      # if you use csh or tcsh

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{lsd.ic.unicamp.br,guarana.{org,com}} aoliva@{acm,computer}.org
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them

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

* Ask for help
@ 1999-09-26 17:36 Haifeng (Tommy) Shen
  1999-09-26 17:50 ` Alexandre Oliva
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Haifeng (Tommy) Shen @ 1999-09-26 17:36 UTC (permalink / raw)
  To: bug-gcc; +Cc: help-gcc

Hi there,


Can anybody tell me how to redirect compling results to a file? I cannot
find an option similar to "Xstdout" in javac by which compiling results 
can be redirected to a file.


Thanks,
Tommy


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

end of thread, other threads:[~2009-03-17 20:13 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-17 14:45 Ask for help Wei, Wanxia
2009-03-17 14:51 ` Andrew Haley
2009-03-17 15:02 ` John Fine
2009-03-17 15:36   ` Wei, Wanxia
2009-03-17 15:42     ` Michael Wieher
2009-03-17 16:05     ` Andrew Haley
2009-03-17 20:13       ` Wei, Wanxia
  -- strict thread matches above, loose matches on Subject: below --
1999-09-26 17:36 Haifeng (Tommy) Shen
1999-09-26 17:50 ` Alexandre Oliva
1999-09-30 23:56   ` Alexandre Oliva
1999-10-01  0:00   ` Alexandre Oliva
1999-09-30 23:56 ` Haifeng (Tommy) Shen
1999-10-01  0:00 ` Haifeng (Tommy) Shen

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