]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add test for all_zero
authorTimo Heister <timo.heister@gmail.com>
Fri, 17 Jan 2014 22:49:20 +0000 (22:49 +0000)
committerTimo Heister <timo.heister@gmail.com>
Fri, 17 Jan 2014 22:49:20 +0000 (22:49 +0000)
git-svn-id: https://svn.dealii.org/trunk@32243 0785d39b-7218-0410-832d-ea1e28bc413d

tests/gla/gla.h
tests/gla/vec_all_zero_01.cc [new file with mode: 0644]
tests/gla/vec_all_zero_01.mpirun=3.output [new file with mode: 0644]

index 9f48457f40bb72e83a52ac6b1e8aa8e77053b4e7..b7a9ece8e5591edd47376a0dbdb24a60f1f48c4b 100644 (file)
@@ -55,6 +55,11 @@ public:
       void compress(VectorOperation::values op)
       {}
 
+       bool all_zero()
+         {
+           return false;
+         }     
+       
       bool has_ghost_elements()
       {
         return false;
diff --git a/tests/gla/vec_all_zero_01.cc b/tests/gla/vec_all_zero_01.cc
new file mode 100644 (file)
index 0000000..00d4bcb
--- /dev/null
@@ -0,0 +1,86 @@
+// ---------------------------------------------------------------------
+// $Id: vec_00.cc 31681 2013-11-16 08:04:28Z maier $
+//
+// Copyright (C) 2004 - 2013 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check that all_zero is working correctly (as a collective operation)
+
+#include "../tests.h"
+#include <deal.II/lac/generic_linear_algebra.h>
+#include <deal.II/base/index_set.h>
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+#include <vector>
+
+#include "gla.h"
+
+template <class LA>
+void test ()
+{
+  unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+  unsigned int numproc = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD);
+
+  if (myid==0)
+    deallog << "numproc=" << numproc << std::endl;
+
+  // each processor owns 2 indices and all
+  // are ghosting Element 1 (the second)
+
+  IndexSet local_active(numproc*2);
+  local_active.add_range(myid*2,myid*2+2);
+  IndexSet local_relevant(numproc*2);
+  local_relevant.add_range(1,2);
+
+
+  typename LA::MPI::Vector x;  
+  x.reinit(local_active, MPI_COMM_WORLD);
+  x=0;
+  typename LA::MPI::Vector g(local_active, local_relevant, MPI_COMM_WORLD);
+  g=x;
+  deallog << "all_zero? " << g.all_zero() << " (should be true)" << std::endl;
+  if (myid==0)
+    x(0)=1.0;
+  x.compress(VectorOperation::insert);
+  g=x;
+  deallog << "all_zero? " << g.all_zero() << " (should be false)" << std::endl;
+  
+  // done
+  if (myid==0)
+    deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv);
+  MPILogInitAll log;
+  unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+
+  {
+    deallog.push("PETSc");
+    test<LA_PETSc>();
+    deallog.pop();
+    deallog.push("Trilinos");
+    test<LA_Trilinos>();
+    deallog.pop();
+  }
+
+  if (myid==9999)
+    test<LA_Dummy>(); // don't execute
+
+}
diff --git a/tests/gla/vec_all_zero_01.mpirun=3.output b/tests/gla/vec_all_zero_01.mpirun=3.output
new file mode 100644 (file)
index 0000000..437293a
--- /dev/null
@@ -0,0 +1,21 @@
+
+DEAL:0:PETSc::numproc=3
+DEAL:0:PETSc::all_zero? 1 (should be true)
+DEAL:0:PETSc::all_zero? 0 (should be false)
+DEAL:0:PETSc::OK
+DEAL:0:Trilinos::numproc=3
+DEAL:0:Trilinos::all_zero? 1 (should be true)
+DEAL:0:Trilinos::all_zero? 0 (should be false)
+DEAL:0:Trilinos::OK
+
+DEAL:1:PETSc::all_zero? 1 (should be true)
+DEAL:1:PETSc::all_zero? 0 (should be false)
+DEAL:1:Trilinos::all_zero? 1 (should be true)
+DEAL:1:Trilinos::all_zero? 0 (should be false)
+
+
+DEAL:2:PETSc::all_zero? 1 (should be true)
+DEAL:2:PETSc::all_zero? 0 (should be false)
+DEAL:2:Trilinos::all_zero? 1 (should be true)
+DEAL:2:Trilinos::all_zero? 0 (should be false)
+

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.