]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add test to check assignment between ghosted vectors
authorTimo Heister <timo.heister@gmail.com>
Fri, 15 Feb 2013 05:17:47 +0000 (05:17 +0000)
committerTimo Heister <timo.heister@gmail.com>
Fri, 15 Feb 2013 05:17:47 +0000 (05:17 +0000)
git-svn-id: https://svn.dealii.org/trunk@28401 0785d39b-7218-0410-832d-ea1e28bc413d

tests/mpi/ghost_02.cc [new file with mode: 0644]
tests/mpi/ghost_02/ncpu_10/cmp/generic [new file with mode: 0644]
tests/mpi/ghost_02/ncpu_4/cmp/generic [new file with mode: 0644]

diff --git a/tests/mpi/ghost_02.cc b/tests/mpi/ghost_02.cc
new file mode 100644 (file)
index 0000000..f4bf72c
--- /dev/null
@@ -0,0 +1,115 @@
+//---------------------------------------------------------------------------
+//    $Id: ghost_01.cc 24418 2011-09-26 12:52:19Z bangerth $
+//    Version: $Name$ 
+//
+//    Copyright (C) 2004, 2005, 2010 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//---------------------------------------------------------------------------
+
+
+// Test correct copying  of ghosted vectors in PETScWrappers::mpi::vectors
+
+#include "../tests.h"
+#include <deal.II/lac/petsc_parallel_vector.h>
+#include <deal.II/base/index_set.h>
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+#include <vector>
+
+
+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);
+
+  PETScWrappers::MPI::Vector vb(MPI_COMM_WORLD, local_active);
+  PETScWrappers::MPI::Vector v(MPI_COMM_WORLD, local_active, local_relevant);
+  PETScWrappers::MPI::Vector v2(MPI_COMM_WORLD, local_active, local_relevant);
+
+  vb = 1.5;
+  v2 = vb;
+  if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
+    deallog << "ghost: " << v2(1) << std::endl;
+  Assert(v2(1) == 1.5, ExcInternalError());
+  Assert(v2(myid*2) == 1.5, ExcInternalError());
+  Assert(v2(myid*2+1) == 1.5, ExcInternalError());
+  
+                                  // set local values
+  vb(myid*2)=myid*2.0;
+  vb(myid*2+1)=myid*2.0+1.0;
+
+  vb.compress(VectorOperation::insert);
+  vb*=2.0;
+  v=vb;
+  
+  
+                                  // check local values
+  if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
+    {
+      deallog << myid*2 << ":" << v(myid*2) << std::endl;
+      deallog << myid*2+1 << ":" << v(myid*2+1) << std::endl;
+    }
+  
+  Assert(v(myid*2) == myid*4.0, ExcInternalError());
+  Assert(v(myid*2+1) == myid*4.0+2.0, ExcInternalError());
+  
+
+                                  // check ghost values
+  if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
+    deallog << "ghost: " << v(1) << std::endl;
+  Assert(v(1) == 2.0, ExcInternalError());
+
+                                  //assignment from ghosted to ghosted
+  v2 = v;
+  Assert(v2(1) == 2.0, ExcInternalError());
+  Assert(v2(myid*2) == myid*4.0, ExcInternalError());
+  Assert(v2(myid*2+1) == myid*4.0+2.0, ExcInternalError());
+  if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
+    deallog << "ghost: " << v2(1) << std::endl;
+  
+                                  // done
+  if (myid==0)
+    deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  PetscInitialize(&argc,&argv,0,0);
+  unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+
+  deallog.push(Utilities::int_to_string(myid));
+
+  if (myid == 0)
+    {
+      std::ofstream logfile(output_file_for_mpi("ghost_02").c_str());
+      deallog.attach(logfile);
+      deallog << std::setprecision(4);
+      deallog.depth_console(0);
+      deallog.threshold_double(1.e-10);
+
+      test();
+    }
+  else
+    test();
+  
+  PetscFinalize();
+}
diff --git a/tests/mpi/ghost_02/ncpu_10/cmp/generic b/tests/mpi/ghost_02/ncpu_10/cmp/generic
new file mode 100644 (file)
index 0000000..1d58fd3
--- /dev/null
@@ -0,0 +1,6 @@
+
+DEAL:0::numproc=10
+DEAL:0::0:0.000
+DEAL:0::1:2.000
+DEAL:0::ghost: 2.000
+DEAL:0::OK
diff --git a/tests/mpi/ghost_02/ncpu_4/cmp/generic b/tests/mpi/ghost_02/ncpu_4/cmp/generic
new file mode 100644 (file)
index 0000000..e9df559
--- /dev/null
@@ -0,0 +1,8 @@
+
+DEAL:0::numproc=4
+DEAL:0::ghost: 1.500
+DEAL:0::0:0.000
+DEAL:0::1:2.000
+DEAL:0::ghost: 2.000
+DEAL:0::ghost: 2.000
+DEAL:0::OK

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.