PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

Break a program after looping

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Debugging and Profiling
View previous topic :: View next topic  
Author Message
mmartin



Joined: 11 May 2006
Posts: 4

PostPosted: Fri May 26, 2006 11:06 am    Post subject: Break a program after looping Reply with quote

Is there a way to set a program to break after executing a statement a user defined number of times? I have a statment that calls a function from inside a for loop that goes through many iterations. It works fine until a floating point exception occurs during one of the iterations. I'm trying to discover why the floation point exception occurs, and so far all I have been able to find is where it occurs. I can find out how many iterations before the fpe occurs by other means, but I would then like to break the program during the iteration where the exception occurs and watch the variables to see what is being passed to the function and what is being returned. After searching through the manual and looking in the debugger I can't find how to do this or if it is supported by this debugger.
Back to top
View user's profile
mmartin



Joined: 11 May 2006
Posts: 4

PostPosted: Fri May 26, 2006 11:08 am    Post subject: Reply with quote

Also I forgot to mention that this floating point exception only occurs when I compile the program with pgcc, it runs fine for gcc and MS Visual Studio. Not sure why this happens.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6211
Location: The Portland Group Inc.

PostPosted: Tue May 30, 2006 9:42 am    Post subject: Reply with quote

Hi mmartin,

In PGDBG, you can set conditional breakpoints. First set a breakpoint at the beginning of the function. Once in scope (i.e. you ran the "-g" compiled program to this first breakpoint), add an additional breakpoint using an if statement as decribed in section 1.5.8 of the PGI tools guide. For example
Code:
% cat tmp.c
#include <stdio.h>
int main() {
  int i = 0;
  int a[10000];

  for (i = 0; i < 10000; ++i) {
    a[i] = 0;
  }

}
% pgcc -g tmp.c
% pgdbg -text a.out
PGDBG Rel Dev x86 (Cluster, 4096 CPU)
Copyright 1989-2000, The Portland Group, Inc. All Rights Reserved.
Copyright 2000-2006, STMicroelectronics, Inc. All Rights Reserved.
***Reading DWARFv2 Information.
Loaded: a.out

pgdbg> break 3
(1)breakpoint set at: main line: "tmp.c"@3 address: 0x8048616
1
pgdbg> run
libpgc.so loaded by ld-linux.so.2.
libm.so.6 loaded by ld-linux.so.2.
libc.so.6 loaded by ld-linux.so.2.
Breakpoint at 0x8048616, function main, file tmp.c, line 3
 #3:       int i = 0;

pgdbg> break 7 if (i > 25)
(2)breakpoint set at: main line: "tmp.c"@7 address: 0x804862a
2
pgdbg> cont
Breakpoint at 0x804862a, function main, file tmp.c, line 7
 #7:         a[i] = 0;

pgdbg> print i
26


As for your particular error, if it occurs at "-O0 -g", then it might be a portability problem such as a header file variable which is guarded by a "__GNU__" or "_MSC_VER", a GNU extension, or a bug in the program, such as an off-by-one error or other memory issue. Different compilers lay out memory differently so these types of errors can "work" in some environments but fail on others. Note that if it is a bug where memory is being overwritten, the actual bug may be in a completely unrelated part of your code.

Hope this helps,
Mat
Back to top
View user's profile
Catherine Moroney



Joined: 05 Jun 2006
Posts: 22

PostPosted: Tue Jun 13, 2006 5:44 pm    Post subject: Reply with quote

Another hint which I've found very useful at times is to
modify the source code to add a statement like:

if (error_happens) {
int xjunk = 0.0;
}

and then set a breakpoint on the "xjunk = 0.0" line. Conditional
breakpoints can sometimes make the debugger run very slowly,
making the compiler do the work for the condition tends to be
faster.

Catherine
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Debugging and Profiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group