1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Fortran90 SIGSEGV: Segmentation fault

  1. May 2, 2016 #1
    I have a project for a class in numerics, where I have to write a program with FORTRAN 90 that calculates the determinant of a matrix using Laplace.
    The program itself works now, but I have added a function that finds the row/column with most zeroes and reorganizes the matrix, so that they are in the first column. When I try it with small matrices, it works just fine. However (starting at 4x4) I get the following error:

    SIGSEGV:Segmentation fault-invalid memory reference.
    Backtrace for this error:
    #0 6f6117be
    #1 6f695deb
    #2 004010f8

    I have read pretty much every discussion about this I could find, but either the solutions did not apply to my code or the explanation was too complicated for me to unterstand...This is the first program ever that I wrote, so I am not an expert.

    This is the function (whithout this function it works fine, so I gues the problem is somewhere in the function):

    Code (Fortran):
          function sortieren_Matrix(A,n) result(A_getauscht)

          implicit none

           !Festlegen der Variablen
             real                     A(n,n)                    !Matrix A
             real                     A_getauscht(n,n)        !Matrix mit vertauschten Zeilen und Spalten
             real                    merk                     !Hilfsvariablen
             integer                    n                         !Größe der Matrix
             integer                    zaehl                    !Zählt die Nullen
             integer                    merk1,merk2                !Hilfsvariablen
             integer                    zaehl_max1,zaehl_max2    !Anzahl Nullen (1-Zeile,2-Spalte)
             integer                    minus                    !negatives Vorzeichen
             integer                 i,j                        !Laufindices
        !Durchsuchen nach Zeile mit den meisten Nullen
             do i=1,n
                   do j=1,n
                       if(A(i,j) .eq. 0.0) then
                      end if
                   end do
                  if(zaehl .gt. zaehl_max1) then
                   merk1=i                                     !Merken, in welcher Zeile die meisten Nullen sind
                  end if
            end do
        !Durchsuchen nach Spalte mit den meisten Nullen
             do i=1,n
                    do j=1,n
                        if(A(j,i) .eq. 0.0) then
                        end if
                    end do
                if(zaehl .gt. zaehl_max2) then
                    merk2=i                                     !Merken, in welcher Spalte die meisten Nullen sind
                end if      
             end do
        !neu Ordnen der Matrix, sodass die erste Spalte, die mit den meisten Nullen ist
             if(zaehl_max1 .gt. zaehl_max2) then        !sehen ob in Spalte oder Zeile die meisten Nullen sind
                do i=1,n                                !Zeilen und Spalten vertauschen/transponieren
                    do j=1,n
                    end do
                end do
             end if
        !Vorzeichen der Determinante positiv oder negativ?
             if(merk2 .ne. 1) then            !Wenn bei einer Matrix Spalten oder Zeilen getauscht werden, ändert sich ihr Vrozeichen
             end if
        !Ordnen, sodass Nullen in erster Spalte
             do i=1,n
             end do
          end function sortieren_Matrix
    I would really apprecaite it if someone had ideas what else I could be doing wrong!
    Thank you!!
  2. jcsd
  3. May 2, 2016 #2


    Staff: Mentor

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted