Bug #3563

Fix spare matrix flushing issue

Added by Knödlseder Jürgen almost 4 years ago. Updated almost 4 years ago.

Status:ClosedStart date:03/11/2021
Priority:ImmediateDue date:
Assigned To:Knödlseder Jürgen% Done:

100%

Category:-
Target version:2.0.0
Duration:

Description

While running a model fit I encountered a crash that occurred in the GMatrixSparse::stack_flush() method. Enabling debugging of the method I recognised that the number of added elements did not correspond to the expected number of elements. An example output is shown below:

GMatrixSparse::stack_flush
 Number of stack entries .: 416
 Number of stack elements : 3744
 Number of matrix elements: 1262
 New elements ............: 0
 Added elements ..........: 1772 (should be 1262)
 - Matrix only ...........: 1691
 - Stack only ............: 0
 - Matrix & Stack ........: 72
This looks like a quite serious issue, not clear why it has not shown up earlier.


Recurrence

No recurrence.

History

#1 Updated by Knödlseder Jürgen almost 4 years ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 90

The issues was due to an incompatibility between the methods GMatrixSparse::mix_column_prepare() and GMatrixSparse::mix_column().

The first method is used in GMatrixSparse::stack_flush() to estimate the number of elements that should be added to the matrix in case that a column should be mixed with the stack. This estimate is the used to allocate memory, and GMatrixSparse::mix_column() is then used to perform the actual mix.

In case that there is only a single element in the stack or the matrix and if that single element was in the same row, GMatrixSparse::mix_column_prepare() underestimated the number of elements to mix. This probably not always led to a problem since some margin is added when allocating the memory. However when this margin is exceeded, a segmentation fault will occur.

I corrected GMatrixSparse::mix_column_prepare() so that this special case does not occur, and the algorithm is identical to the one used in GMatrixSparse::mix_column().

Tests now show always:

GMatrixSparse::stack_flush
 Number of columns on stack : 404
 Number of elements on stack: 3636
 Number of matrix elements .: 1600
 Col.start at end of matrix : 1600
 Valid columns on stack ....: 9
 Valid elements on stack ...: 0
 Added elements ............: 1600 (should be 1600)
 - Matrix only .............: 1519
 - Stack only ..............: 0
 - Matrix & Stack ..........: 81

#2 Updated by Knödlseder Jürgen almost 4 years ago

  • Status changed from In Progress to Closed
  • % Done changed from 90 to 100

Merged into devel.

Also available in: Atom PDF