Segmentation Fault with Large Matrix Dimensions
Hello everyone,
I encountered a segmentation fault when using the provided example code with large matrix dimensions.
Description
When initializing a sparse matrix with non-trivial dimensions (e.g., the size of the com-Orkut dataset), the program crashes with a segmentation fault during matrix construction.
Example Code
#include <iostream>
#include "IVSparse/SparseMatrix"
int main() {
std::vector<std::tuple<uint32_t, uint32_t, double>> cooData = {
{0, 0, 1},
{1, 1, 2},
{2, 2, 3},
{3, 3, 4}
};
int rows = 3072441; // com-Orkut dataset size
int cols = 3072441; // Causes segmentation fault
// int rows = 46985; // Web of Science dataset size
// int cols = 124836; // Works correctly
int nnz = 4;
IVSparse::SparseMatrix<double> matrix(cooData, rows, cols, nnz);
std::cout << "Everything ok!\n";
return 0;
}
Observed Behavior
- The program runs correctly with smaller matrix sizes.
- With large dimensions (e.g., ~3 million × 3 million), it crashes with a segmentation fault during construction.
Suspected Cause
I suspect that the issue may be caused by large stack allocations using Variable Length Arrays (VLAs), such as:
std::map<T2, std::vector<indexT2>> maps[outerDim];
Located in: IVSparse/src/IVCSC/IVCSC_Constructors.hpp (around line 309)
Proposed Solution
Replace stack-allocated VLAs with heap-allocated containers.
Suggested Change
// Original
std::map<T2, std::vector<indexT2>> maps[outerDim];
// Modified
std::vector<std::map<T2, std::vector<indexT2>>> maps(outerDim);
This shifts the allocation to the heap and avoids stack overflow.
Steps to Reproduce
-
Clone the repository.
-
Create a file named new_test_ft.cpp in the root directory and paste the example code above.
-
Compile using:
g++ -std=c++17 -fopenmp -O2 new_test_ft.cpp -I. -I/usr/include/eigen3 -o test
-
Run:
Environment
-
OS
Distributor ID: Ubuntu
Description: Ubuntu 24.04.3 LTS
Release: 24.04
Codename: noble
-
Compiler
g++ --version -> g++ (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
-
Arch
uname -m -> x86_64
-
Stack size
ulimit -s -> 8192
-
Available RAM
total used free shared buff/cache available
Mem: 7.6Gi 1.7Gi 625Mi 28Mi 5.6Gi 5.9Gi
Swap: 8.0Gi 12Mi 8.0Gi
Please let me know if additional details or tests would be helpful. I’d be happy to assist further in debugging this issue.
Segmentation Fault with Large Matrix Dimensions
Hello everyone,
I encountered a segmentation fault when using the provided example code with large matrix dimensions.
Description
When initializing a sparse matrix with non-trivial dimensions (e.g., the size of the com-Orkut dataset), the program crashes with a segmentation fault during matrix construction.
Example Code
Observed Behavior
Suspected Cause
I suspect that the issue may be caused by large stack allocations using Variable Length Arrays (VLAs), such as:
Located in: IVSparse/src/IVCSC/IVCSC_Constructors.hpp (around line 309)
Proposed Solution
Replace stack-allocated VLAs with heap-allocated containers.
Suggested Change
This shifts the allocation to the heap and avoids stack overflow.
Steps to Reproduce
Clone the repository.
Create a file named
new_test_ft.cppin the root directory and paste the example code above.Compile using:
g++ -std=c++17 -fopenmp -O2 new_test_ft.cpp -I. -I/usr/include/eigen3 -o testRun:
Environment
OS
Distributor ID: Ubuntu
Description: Ubuntu 24.04.3 LTS
Release: 24.04
Codename: noble
Compiler
g++ --version -> g++ (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Arch
uname -m -> x86_64
Stack size
ulimit -s -> 8192
Available RAM
total used free shared buff/cache available
Mem: 7.6Gi 1.7Gi 625Mi 28Mi 5.6Gi 5.9Gi
Swap: 8.0Gi 12Mi 8.0Gi
Please let me know if additional details or tests would be helpful. I’d be happy to assist further in debugging this issue.