I have written the following function for partially doing stable sort over vector of arrays. When the size of vector is small like 1G it always work, when the size of vector is large (5 or 6 Gig) sometimes it works, sometimes it throws segmentation fault, could someone help me figure out the resean for this.
template <typename T, size_t SIZE>
void sort(std::vector<std::array<T, SIZE>>& vec, size_t depth = SIZE) {
std::sort(vec.begin(), vec.end(),
[&](const auto& t1, const auto& t2)->bool {
for(size_t s = 0; s < depth; s++) {
if(t1[s] == t2[s]) {
continue;
}
return t1[s] < t2[s];
}
return true;
});
}
I use g++ 10.2 and these are the switches, I compile the code with -DNDEBUG -march=native -msse3 -ftree-vectorize -O3
.