Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 19th, 2005, 06:26 PM
Andrew Bonello
Guest
 
Posts: n/a
Default gprof, -pg and rand() problem

Hi

I have written a C++ program (Redhat Linux 7.2, gcc v2.96). The
program makes a sequence of calls to rand() after having seeded the
random number generator using srand( 0 ). Under normal circumstances,
for a given input state, the sequence of random numbers generated is
exactly reproduced each time the program is run. So, if I run the tool
3 times in succession, the path of execution is completely identical
each time as far as the sequence of random numbers is concerned.

I also want to profile the performance of this program, and so
recompiled and linked using the -pg option to allow gprof to be run
after execution.

However, I now find that the sequence of random numbers generated at
each subsequent run of the program is NOT reproducible. It looks like
linking with -pg is what caused the problem. Obviously, since the path
of execution is now different each time, the profiling results are
rather less meaningful.

Has anyone observed this behaviour? If so, can you recommend any ways
to get reproducible random number sequences WITH the -pg linking
option?

Thanks


Andrew.
  #2  
Old July 19th, 2005, 06:27 PM
White Wolf
Guest
 
Posts: n/a
Default Re: gprof, -pg and rand() problem

Andrew Bonello wrote:[color=blue]
> Hi
>
> I have written a C++ program (Redhat Linux 7.2, gcc v2.96). The[/color]
[SNIP]

Could you please post again the part of your question which was about the
Standard C++ programming language? I could not find it.

http://www.slack.net/~shiva/welcome.txt

http://www.slack.net/~shiva/offtopic.txt

--
WW aka Attila


  #3  
Old July 19th, 2005, 06:27 PM
Jim Fischer
Guest
 
Posts: n/a
Default Re: gprof, -pg and rand() problem

Andrew Bonello wrote:[color=blue]
> Hi
>
> I have written a C++ program (Redhat Linux 7.2, gcc v2.96). The
> program makes a sequence of calls to rand() after having seeded the
> random number generator using srand( 0 ). Under normal circumstances,
> for a given input state, the sequence of random numbers generated is
> exactly reproduced each time the program is run. So, if I run the tool
> 3 times in succession, the path of execution is completely identical
> each time as far as the sequence of random numbers is concerned.
>
> I also want to profile the performance of this program, and so
> recompiled and linked using the -pg option to allow gprof to be run
> after execution.
>
> However, I now find that the sequence of random numbers generated at
> each subsequent run of the program is NOT reproducible. It looks like
> linking with -pg is what caused the problem. Obviously, since the path
> of execution is now different each time, the profiling results are
> rather less meaningful.
>
> Has anyone observed this behaviour? If so, can you recommend any ways
> to get reproducible random number sequences WITH the -pg linking
> option?[/color]

Since this problem statement is specific to GNU G++ (and the GNU
profiling tools), the GNU G++ newsgroups / mailing lists are probably
the best/right places to ask for assistance. On Usenet, the GNU G++
"help" group is,

gnu.g++.help

For mailing list info, visit the GCC web site at

http://gcc.gnu.org

FWIW, you should also post a short, complete, compilable C++ program
sample that exactly demonstrates the problem you're describing. Without
some actual code to look at, the g++ folks can only make guesses as to
the "real" problem (e.g., compiler bug, code bug, linker bug, programmer
error ;-), etc.).

--
Jim

To reply by email, remove "link" and change "now.here" to "yahoo"
jfischer_link5809{at}now.here.com


  #4  
Old July 19th, 2005, 06:27 PM
Jim Fischer
Guest
 
Posts: n/a
Default Re: gprof, -pg and rand() problem

Jim Fischer wrote:[color=blue]
> FWIW, you should also post a short, complete, compilable C++ program
> sample that exactly demonstrates the problem you're describing. Without
> some actual code to look at, the g++ folks can only make guesses as to
> the "real" problem (e.g., compiler bug, code bug, linker bug, programmer
> error ;-), etc.).[/color]

FWIW2, when I use a "stock" (non-redhat) GNU G++ 3.3.1 compiler to build
the following C++ code sample on a Red Hat 9 Linux box (with an Intel
Pentium-III/Celeron CPU), the program output is always the same - with
or without profiling support enabled:

// main.cpp

#include <cstdlib>
#include <iostream>
using namespace std;

int main()
{
srand( 0 );
for ( int i = 0; i < 10; ++i) {
cout << rand() << '\n';
}
}

$ g++ -Wall -Werror -O3 -pg -o try main.cpp


FWIW3: IIRC, the GCC 2.96.x releases are Red Hat specific beasts. So the
GNU G++ folks might redirect you to the Red Hat Linux groups / mailing
lists for help with this problem. IOW, the problem might be a "feature"
of Red Hat's GCC 2.96 builds...

--
Jim

To reply by email, remove "link" and change "now.here" to "yahoo"
jfischer_link5809{at}now.here.com


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.