Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to fix Segmentation fault in fortran ?!

Status
Not open for further replies.

B4M

Member level 2
Joined
Aug 3, 2016
Messages
47
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
318
Hello, I have this error
Code:
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
I believe it is due to the use of allocate to define the variables
Code:
REAL, ALLOCATABLE :: M(:,:)
REAL, ALLOCATABLE :: N(:,:)
How to turn around this error?!
thanks a lot!
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
50,810
Helped
14,603
Reputation
29,481
Reaction score
13,688
Trophy points
1,393
Location
Bochum, Germany
Activity points
290,937
As before with your FORTRAN problems, you should preferably post all statements related to the problem. The ALLOCATABLE statements does nothing with respective ALLOCATE, and the segment fault probably occurs when you are using a memory range that wasn't properly allocated.

What I wonder is this: As you are apparently not very familiar with advanced FORTRAN features, won't it be better to restrict your coding to more basic FORTRAN constructs? Doesn't your PC have sufficient memory space to define the variable arrays statically? Focus on the actual calculation problem instead of practicing new FORTRAN language elements?
 

B4M

Member level 2
Joined
Aug 3, 2016
Messages
47
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
318
well the code is suppose to extract the matrix M and N
Code:
INTEGER ::ROWS, COLUMNS, I, J
REAL, ALLOCATABLE :: M (:,:)
REAL, ALLOCATABLE :: N(:,:)
OPEN (19, FILE="OnSp.mat", FORM='UNFORMATTED')
READ (19) ROWS
READ (19) COLUMNS
DO J=1, COLUMNS
READ (19) (M (I,J), I=1, ROWS)
READ (19) (N(I,J), I=1, ROWS)
END DO
CLOSE (19)
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
50,810
Helped
14,603
Reputation
29,481
Reaction score
13,688
Trophy points
1,393
Location
Bochum, Germany
Activity points
290,937
As guessed before: No memory space allocated, missing ALLOCATE statement. Better use static arrays.
 

B4M

Member level 2
Joined
Aug 3, 2016
Messages
47
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
318
The idea of the code is to be applicable to any file with the same structure, knowing that the size of the matrices is not fixed. Any further suggestions are very welcome!
Thank you!
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
50,810
Helped
14,603
Reputation
29,481
Reaction score
13,688
Trophy points
1,393
Location
Bochum, Germany
Activity points
290,937
The solution seems quite obvious,in the present case, you would perform an allocate after reading the rows and columns info.
 

B4M

Member level 2
Joined
Aug 3, 2016
Messages
47
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
318
Thank you very much ! unfortunately it generates this error:
Code:
Error: Unexpected data declaration statement at (1)
looking around I have found that the cause of this error is placing a data declaration statement after a normal statement.:bang:
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top