Solved – program received signal sigsegv: segmentation fault
Posted on: March 08, 2021 by Deven
In this article, you will learn how to solve program received signal sigsegv: segmentation fault – invalid memory reference.
Let’s look at a code example that produces the same error.
CnewV = CnewV + alpha2 * r
Segmentation error happens because of memory conflicts. and in our case error is due to wrong allocation of variables. Consider the code snippet below to correctly allocate the variables.
CnewV(0:IG,0:JG) = CnewV(0:IG,0:JG) + alpha2 * r(0:IG,0:JG)
If an array index is being outside the declared range It can also cause segmentation fault error.
There are few other reasons which can produce the above error:
- Your integers with
INTEGER*8
might be too long, maybeINTEGER*4
or simplyINTEGER
would be better - You call
SGESV
on double arguments instead ofDGESV
- Your
LDA
argument is missing, so your code should perhaps look likeCALL DGESV(N,N,DMA2,N,pivot,FU,N,inf)
but you need to check whether this is what you want.
To solve this issue you should use iostat=<some integer var>
to check for the return value of the open
operation.
Share on social media
//