473,396 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.
Jul 19 '05 #1
3 4009
Andrew Bonello wrote:
Hi

I have written a C++ program (Redhat Linux 7.2, gcc v2.96). The

[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
Jul 19 '05 #2
Andrew Bonello wrote:
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?


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
Jul 19 '05 #3
Jim Fischer wrote:
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.).


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
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: takashi | last post by:
Hi, I am having trouble, using 'gnu profiler'. The problem is when I type: gprof executable_name I don't get any accumulated time for the execution of the program. The detail of what I have done...
0
by: Gumby | last post by:
Is gprof on Solaris 9 X86 not as supported as Solaris 9 Sparc? At work when we try to compile a program with -pg to use gprof to performance profile our software, the compiled app just dies...
0
by: Dave | last post by:
Hello, I would like to profile a Python program using gprof. I already rebuilt Python with CC="gcc -pg" ../configure. So, I should be able to use gprof. How do I do that? Should I first run...
2
by: AlvaroMako | last post by:
Hello: I am using g++, on linux, and i am trying profile out my program but I have problems with the calls to the symbols that are in shared library, does not leave anything these symbols. ...
1
by: Yan Yang | last post by:
Hi, I have a program and I want to test its execution time. When I run the program, I can feel it runs about 4 mins, but the gprof only says the accumlated time is 7.2 secs. Then I use the...
1
by: Pasacco | last post by:
dear I need to know the execution time of the program. Below is just an example. I used to use gprof. But in this case, the error messsage says "gprof : gmon.out file is missing call-graph...
2
by: =?iso-8859-1?q?Nicolas_Herv=E9?= | last post by:
I am using gprof, and as explain in http://www.gnu.org/software/binutils/manual/gprof-2.9.1/html_node/gprof_18.html#SEC18 I could use the "-g -pg -a" options of gcc and then use the "-l -A"...
1
by: Congcong | last post by:
When I use gprof to profile a program, it seems never show me the profile info on c lib routines such as malloc. But sometimes, profile info on such c lib routines are also important. I use 'gcc -g...
15
by: Rich Fife | last post by:
Quick rand() question: I know you're not supposed to use "rand() % 1024" for instance, because it focuses on the lower bits. However, it seems to me that given that the argument is not a power...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.