]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Improve error message for out-of-bound access in parallel vector 275/head
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Wed, 26 Nov 2014 17:54:27 +0000 (18:54 +0100)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Wed, 26 Nov 2014 17:54:27 +0000 (18:54 +0100)
include/deal.II/lac/parallel_vector.h

index 06c64f01ece4dc6b2594812729911c163f26a14b..8c4ab5c581be6ade515ca6fae6bd2ffe4e61ff61 100644 (file)
@@ -981,6 +981,18 @@ namespace parallel
                       << std::setprecision(16) << arg2
                       << " on the owner processor " << arg3);
 
+      /**
+       * Exception
+       */
+      DeclException4 (ExcAccessToNonLocalElement,
+                      size_type, size_type, size_type, size_type,
+                      << "You tried to access element " << arg1
+                      << " of a distributed vector, but this element is not "
+                      << "stored on the current processor. Note: The range of "
+                      << "locally owned elements is " << arg2 << " to "
+                      << arg3 << ", and there are " << arg4 << " ghost elements "
+                      << "that this vector can access.");
+
     private:
       /**
        * Local part of all_zero().
@@ -1820,6 +1832,11 @@ namespace parallel
     Number
     Vector<Number>::operator() (const size_type global_index) const
     {
+      Assert (in_local_range (global_index) ||
+              partitioner->ghost_indices().is_element(global_index),
+              ExcAccessToNonLocalElement(global_index, local_range().first,
+                                         local_range().second,
+                                         partitioner->ghost_indices().n_elements()));
       // do not allow reading a vector which is not in ghost mode
       Assert (in_local_range (global_index) || vector_is_ghosted == true,
               ExcMessage("You tried to read a ghost element of this vector, "
@@ -1834,6 +1851,11 @@ namespace parallel
     Number &
     Vector<Number>::operator() (const size_type global_index)
     {
+      Assert (in_local_range (global_index) ||
+              partitioner->ghost_indices().is_element(global_index),
+              ExcAccessToNonLocalElement(global_index, local_range().first,
+                                         local_range().second,
+                                         partitioner->ghost_indices().n_elements()));
       // we would like to prevent reading ghosts from a vector that does not
       // have them imported, but this is not possible because we might be in a
       // part of the code where the vector has enabled ghosts but is non-const

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.