diff --git a/src/TNL/Matrices/EllpackSymmetricGraph_impl.h b/src/TNL/Matrices/EllpackSymmetricGraph_impl.h
index 1abb1e98bc2538d144ea03ad4ec363c3f21c6cde..9b12ab1f70f5315c87008d090eab0a3190d1df71 100644
--- a/src/TNL/Matrices/EllpackSymmetricGraph_impl.h
+++ b/src/TNL/Matrices/EllpackSymmetricGraph_impl.h
@@ -813,6 +813,11 @@ template< typename Real,
           typename Index >
 void EllpackSymmetricGraph< Real, Device, Index >::allocateElements()
 {
+   IndexType numberOfMatrixElements = this->alignedRows * this->rowLengths;
+   
+   TNL_ASSERT_TRUE( this->alignedRows != 0 && numberOfMatrixElements / this->alignedRows == this->rowLengths, 
+           "Ellpack cannot store this matrix. The number of matrix elements has overflown the value that IndexType is capable of storing" );
+   
    Sparse< Real, Device, Index >::allocateMatrixElements( this->alignedRows * this->rowLengths );
 }