]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make Trilinos vector non_negative function work in parallel.
authorJustin O'Connor <juleoc@colostate.edu>
Thu, 2 Dec 2021 20:35:02 +0000 (13:35 -0700)
committerJustin O'Connor <juleoc@colostate.edu>
Thu, 2 Dec 2021 20:35:02 +0000 (13:35 -0700)
source/lac/trilinos_vector.cc

index 3e37356bebd192f7e4c35c12013b6da2ad1587ad..7581f764fe425af880ba8f1bcabc0f34107d80fa 100644 (file)
@@ -757,36 +757,25 @@ namespace TrilinosWrappers
     bool
     Vector::is_non_negative() const
     {
-      // if this vector is a parallel one, then
-      // we need to communicate to determine
-      // the answer to the current
-      // function. this still has to be
-      // implemented
-      AssertThrow(local_size() == size(), ExcNotImplemented());
       // get a representation of the vector and
       // loop over all the elements
-      TrilinosScalar *start_ptr;
-      int             leading_dimension;
-      int ierr = vector->ExtractView(&start_ptr, &leading_dimension);
-      AssertThrow(ierr == 0, ExcTrilinosError(ierr));
-
-      // TODO: This
-      // won't work in parallel like
-      // this. Find out a better way to
-      // this in that case.
-      const TrilinosScalar *ptr = start_ptr, *eptr = start_ptr + size();
-      bool                  flag = true;
+      TrilinosScalar *      start_ptr = (*vector)[0];
+      const TrilinosScalar *ptr = start_ptr, *eptr = start_ptr + local_size();
+      unsigned int          flag = 0;
       while (ptr != eptr)
         {
           if (*ptr < 0.0)
             {
-              flag = false;
+              flag = 1;
               break;
             }
           ++ptr;
         }
 
-      return flag;
+      // in parallel, check that the vector
+      // is zero on _all_ processors.
+      const auto max_n_negative = Utilities::MPI::max(flag, get_mpi_communicator());
+      return max_n_negative == 0;
     }
 
 

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.