Recent

Author Topic: External: SIGSEGV  (Read 8150 times)

KeesTUD

  • New Member
  • *
  • Posts: 16
External: SIGSEGV
« on: July 15, 2015, 07:30:34 pm »
Hi,

I now get a SIGSEGV error. Although there are some discussions on this forum, it is extremely difficult to understand the meaning of it. Could it be that I have too many big arrays with int64?

Thanks, Kees

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: External: SIGSEGV
« Reply #1 on: July 15, 2015, 07:59:29 pm »
First, check the bounds of the array are not being exceeded. to read all elements try:
Code: [Select]
For I := 1 to length(myarray) - 1 do
begin
   my code...
end;

rvk

  • Hero Member
  • *****
  • Posts: 6922
Re: External: SIGSEGV
« Reply #2 on: July 15, 2015, 08:23:33 pm »
I now get a SIGSEGV error. Although there are some discussions on this forum, it is extremely difficult to understand the meaning of it.
Well, the meaning is this:
SIGSEGV = invalid memory access (segmentation fault)

Most common causes are:
  • Miscalculating array ranges in your loops
  • Accessing objects which are not created (yet)
  • Accessing other memory which wasn't allocated for use.

So... maybe it's not due to the size of your big arrays with int64 but more the fact that you're trying to access some elements which are "out of range".

There is no way for us to tell you exactly what's wrong unless you show some code where the error occurs (but maybe this explanation might point you in the right direction).

Josh

  • Hero Member
  • *****
  • Posts: 1447
Re: External: SIGSEGV
« Reply #3 on: July 15, 2015, 11:39:41 pm »
Hi
If you have configured your project for different build modes, release,normal and debug.
When you set to debug mode; hopefully you will get a better indication of where the problem is happening.
Good Luck
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

KeesTUD

  • New Member
  • *
  • Posts: 16
Re: External: SIGSEGV
« Reply #4 on: July 16, 2015, 10:34:53 am »
Thanks. The strange thing is that the word "Begin" (see red arrow) is highlighted as the place of the error. See my code.
On top of this: the code has worked, however, since I run it with other data and changed the data types of variables, it gives the error message.

By the way, do you know where I can get a simple overview on debugging?

Code: [Select]
[size=8pt]Procedure NearestClustering;
(* Add to each destination, the distances to the nearest services s
  The NearestMixddsum clusters are added to the nearest distance from the
  origin, so we can identify the optimum of the shortest distance to the
  most compact clusters *)
Var i, j, temp : integer;
    NearestCluster  : array[1..origins] of int64;
    DistmixWeighted : array[1..origins, 1..destinations] of int64;
Begin  [color=red]<==[/color]
  //Weight Distmix with NearestMixddsum
  WriteLn('Weigted distmix');
  WriteLn(Flog,'Weigted distmix');
  For i:=1 to imax do
  Begin
    For j:=1 to jmax do
    Begin
      DistmixWeighted[i,j] := Distmix[i,j] + NearestMixddsum[j];
      //Write(Flog, DistmixWeighted[i,j]:10);
    End;
    //Writeln(Flog);
  End;
  Writeln(Flog);

  //Look for the nearest weighted cluster
  Begin
    Writeln(Flog, 'Nearest clusters per origin');
    //Initialisation NearestMix i.e. fill with mostdistant
    For i:=1 to imax do
    Begin
      NearestCluster[i] := 0;
      {identify highest value of all j's}
      For j:=1 to jmax do
        if DistmixWeighted[i,j] > NearestCluster[i] then NearestCluster[i] := DistmixWeighted[i,j];
    End;

    //Find each nearest cluster for each i
    For i:=1 to imax do
      For j:=1 to jmax do
       if DistmixWeighted[i,j] <= NearestCluster[i] then
       NearestCluster[i] := DistmixWeighted[i,j];

    temp:=0;
    For i:=1 to imax do
    begin
     ResultArray[i].nearestcluster:=NearestCluster[i];
     temp:=temp + NearestCluster[i];
     Writeln(Flog, temp/j:10:2); //gemiddelde ter controle
    end;
  End;
End;[/size]
                                                     
« Last Edit: July 16, 2015, 11:35:57 am by KeesTUD »

rvk

  • Hero Member
  • *****
  • Posts: 6922
Re: External: SIGSEGV
« Reply #5 on: July 16, 2015, 10:48:39 am »
First of all:
It might be easier if you put code between code tags as explained on this page... Code will be more readable that way. You can still edit your post to put the code-tags in.

Could you give us an indication of the value of origins and destinations. You mentioned big arrays but from this code we can't determine how big.

You're mixing a log of "global" variables with local ones. For instance we can't "see" Distmix and NearestMixddsum.

Then I see a line like this: NearestCluster := 0;
But in the procedure you have NearestCluster  : array[1..origins] of int64;
Does this compile for you ?????

So my next question would be.... Is this the exact code you have in your running program?
If it's not... please always give your exact code.

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: External: SIGSEGV
« Reply #6 on: July 16, 2015, 12:10:05 pm »
Check that imax<=origins and jmax<=destinations.
Plus, put {$R+}{$Q+} after the implementation to track overflow errors (turn them off {$R-}{$Q-} after program is debugged and ready, because they slow down the preformance a little).
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

KeesTUD

  • New Member
  • *
  • Posts: 16
Re: External: SIGSEGV
« Reply #7 on: July 16, 2015, 12:12:59 pm »
@rvk: How can I give my complete code, can I attach the files?
The dimensions of arrays with i = 536, and with j = 10861. The arrays have number such as 93987 and 463287.

KeesTUD

  • New Member
  • *
  • Posts: 16
Re: External: SIGSEGV
« Reply #8 on: July 16, 2015, 12:21:56 pm »
@Eugene Loza: yes, they are.

rvk

  • Hero Member
  • *****
  • Posts: 6922
Re: External: SIGSEGV
« Reply #9 on: July 16, 2015, 12:42:18 pm »
@rvk: How can I give my complete code, can I attach the files?
The dimensions of arrays with i = 536, and with j = 10861. The arrays have number such as 93987 and 463287.
Uuuh, if you mean that origin is 93987 and destinations is 463287 then....
your local array DistmixWeighted is ....uuuh... 43.542.955.269 elements of int64 (is 8 bytes) in size.
That's 324.420.297.657 bytes. About 324GB on the stack entering your procedure.
Do you have that much memory :D


O, wait... you mean the arrays contain values of 93987 and 463287?
What is the largest value an element can contain?
For 463287 you don't need a int64.

And if origin is 536 and destinations is 10861 you resulting array will be
536 * 10861 * 8 bytes = 46.571.968 bytes. About 44MB.

What happens if you make the int64 an Integer or LongWord (if the values are always positive)?

I still think this will make FPC choke because it will require the local array to be put on the stack-space (which is limited). Try making the array DistmixWeighted  a global variable. That should solve it but I think you need to rethink the complete design if you're working with such large arrays.


You can publish your project via Project/Publish Project. Choose a directory and zip that directory. The can attach the resulting zip to a post.
« Last Edit: July 16, 2015, 12:52:26 pm by rvk »

KeesTUD

  • New Member
  • *
  • Posts: 16
Re: External: SIGSEGV
« Reply #10 on: July 16, 2015, 01:32:59 pm »
Yes! Making the DistmixWeighted  array global, solved it. Actually I don't understand this as I assumed that making an array local, gives the space free after the procudere has closed.

But still, I may have this problem again with even larger matrices, so, it may be useful to rethink the design for the large j*j matrices....

One last, maybe silly question. The program completes now until the end ... except that it really closes. It says that it is debugging (I was trying some functions, but do not know how it works). So, to close I have to click the red, square stop button.

rvk

  • Hero Member
  • *****
  • Posts: 6922
Re: External: SIGSEGV
« Reply #11 on: July 16, 2015, 01:46:56 pm »
Actually I don't understand this as I assumed that making an array local, gives the space free after the procudere has closed.
Yes, this is correct. Your global array DistmixWeighted will still exist (and take space) after ending the procedure. Local variables use stack-space and are temporary until the procedure ends. But that stack-space is limited (at least it used to be in my DOS-days :)) but definitely not designed for such large arrays. With using DistmixWeighted globally it exists in the data-segment. You could create a array dynamically (which might be better). You could use New and Dispose to create and destroy the complete array which would reside in heap memory. But maybe it's better to create (and destroy) the array dynamically with SetLength. This could also be done with multidimensional arrays. (Look here for an example)

(reading material)

But still, I may have this problem again with even larger matrices, so, it may be useful to rethink the design for the large j*j matrices....
Yes. That's why I suggested the rethinking of the design. You can use the SetLength method explained in the link above.

One last, maybe silly question. The program completes now until the end ... except that it really closes. It says that it is debugging (I was trying some functions, but do not know how it works). So, to close I have to click the red, square stop button.
(there are no silly questions, only silly answers :))
In that case your program didn't end yet. It might hang in some cleanup it's doing. Maybe you wrote outside the arrays boundaries and the program-code is screwed up (corrupt). Did you try the  {$R+}{$Q+} Eugene suggested?
« Last Edit: July 16, 2015, 01:48:27 pm by rvk »

KeesTUD

  • New Member
  • *
  • Posts: 16
Re: External: SIGSEGV
« Reply #12 on: July 16, 2015, 02:07:59 pm »
Thanks a lot for the useful suggestions. I am going to try them.

About the ending issue: I did include {$R+}{$Q+} but do not really understand their function.

rvk

  • Hero Member
  • *****
  • Posts: 6922
Re: External: SIGSEGV
« Reply #13 on: July 16, 2015, 02:37:14 pm »
About the ending issue: I did include {$R+}{$Q+} but do not really understand their function.
$Q or $OVERFLOWCHECKS: Overflow checking
Basically it adds some checking during the run of your program that if you want to put a value in a variable which it can't hold it will give a runtime error. Otherwise it might store a number which you don't expect and you're program might give unexpected results.

$R or $RANGECHECKS : Range checking
This adds some checking during the run of your program that if you want to access some elements outside the range of your arrays the program will alert you.

Like Eugene said, these settings have a small performance penalty so you might want to remove the lines when you're done debugging.

KeesTUD

  • New Member
  • *
  • Posts: 16
Re: External: SIGSEGV
« Reply #14 on: July 16, 2015, 03:08:31 pm »
Clear!

 

TinyPortal © 2005-2018