How to debug "segmentation fault" in a parallel code?

This is a discussion on How to debug "segmentation fault" in a parallel code? within the C Programming forums, part of the General Programming Boards category; I have a serial code that works with no problems. But when I was trying to make it parallel (I ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    12

    How to debug "segmentation fault" in a parallel code?

    I have a serial code that works with no problems.

    But when I was trying to make it parallel (I have the MPI_init and MPI_Comm_rank in the beginning and the MPI_Finalize at the back of the parallel part and I have a if statement of "myid==0", so actually there is only one node is doing the work) there is a segmentation fault.

    Is there any common reason that make this kind of thing happen?

    If not, is there anyway I can find the specific line that the problem is like the gdb command used in serial code?

  2. #2
    Registered User
    Join Date
    Apr 2011
    Posts
    12
    anyone have any idea?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    > I have a serial code that works with no problems.
    Based on what - it doesn't crash?

    Always remember that "working" != "bug free".

    For a start, have you
    - compiled the code with maximum warnings, and got zero warnings?
    - compiled the code both unoptimised and optimised (at various levels), and got identical results
    - run the code under valgrind, and got zero warnings/issues

    You should be able to run the parallel code in gdb, at least it will tell you where the segfault is.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault when using fopen("filename","w+")
    By Marslakoo in forum C Programming
    Replies: 6
    Last Post: 11-21-2011, 08:15 AM
  2. Replies: 2
    Last Post: 10-31-2011, 12:57 PM
  3. struct, string, strcmp(), and "segmentation fault"
    By Roger in forum C Programming
    Replies: 10
    Last Post: 11-07-2009, 10:45 PM
  4. [Segmentation Fault] fopen("filename","w")
    By gibbofresco in forum C Programming
    Replies: 7
    Last Post: 07-04-2009, 05:32 AM
  5. Problem with a function ("Segmentation fault")
    By kinghajj in forum C Programming
    Replies: 6
    Last Post: 02-21-2004, 01:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21