]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add new gla directory for parallel unit tests for parallel LA, first test
authorTimo Heister <timo.heister@gmail.com>
Fri, 1 Mar 2013 20:15:02 +0000 (20:15 +0000)
committerTimo Heister <timo.heister@gmail.com>
Fri, 1 Mar 2013 20:15:02 +0000 (20:15 +0000)
git-svn-id: https://svn.dealii.org/branches/branch_unify_linear_algebra@28704 0785d39b-7218-0410-832d-ea1e28bc413d

tests/Makefile
tests/gla/Makefile [new file with mode: 0644]
tests/gla/gla.h [new file with mode: 0644]
tests/gla/vec_01.cc [new file with mode: 0644]
tests/gla/vec_01/ncpu_10/cmp/generic [new file with mode: 0644]
tests/gla/vec_01/ncpu_4/cmp/generic [new file with mode: 0644]

index f5d0503d22381110f5e2be17141264431802153d..5227c57b11bf7ab28bd35b922fcb8748e50c1af0 100644 (file)
@@ -21,6 +21,7 @@ nofail-dirs = a-framework       \
               serialization     \
              mesh_converter    \
              $(if $(DEAL_II_USE_MPI:no=),      $(if $(USE_CONTRIB_P4EST:no=),mpi,),) \
+             $(if $(DEAL_II_USE_MPI:no=),      $(if $(USE_CONTRIB_P4EST:no=),gla,),) \
              $(if $(USE_CONTRIB_P4EST:no=),    distributed_grids,) \
              $(if $(USE_CONTRIB_PETSC:no=),    petsc,) \
              $(if $(USE_CONTRIB_SLEPC:no=),    slepc,) \
diff --git a/tests/gla/Makefile b/tests/gla/Makefile
new file mode 100644 (file)
index 0000000..b1be076
--- /dev/null
@@ -0,0 +1,67 @@
+############################################################
+# $Id: Makefile 17098 2008-10-03 19:27:13Z bangerth $
+# Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011 by the deal.II authors
+############################################################
+
+############################################################
+# Include general settings for including DEAL libraries
+############################################################
+
+include ../Makefile.paths
+include $D/common/Make.global_options
+
+default: run-tests
+
+############################################################
+
+# all .cc-files are tests by default.
+
+ifeq ($(USE_CONTRIB_TRILINOS),no)
+  tests_x_1 = $(shell for i in *.cc ; do \
+                       if grep -q TrilinosWrappers $$i ; then \
+                                : ; \
+                       else \
+                                echo $$i ; \
+                       fi ; done)
+else
+  tests_x_1 = $(wildcard *.cc)
+endif
+
+tests   = $(shell echo $(addsuffix /ncpu_*, $(basename $(tests_x_1))))
+
+
+############################################################
+
+
+OVERRIDE_OUTPUT_RULE = yes
+include ../Makefile.rules
+include Makefile.depend
+
+
+Makefile.mpi.tests: Makefile $(shell echo *.cc) $(shell echo */*/cmp/generic)
+       @echo =====Targets======= $@
+       @(for i in $(basename $(wildcard *.cc)) ; do \
+               echo "$$i/exe : $$i/obj.g.\$$(OBJEXT) \$$(libraries)"; \
+        done ; \
+        for i in $(basename $(wildcard *.cc)) ; do \
+               for j in $$i/ncpu_*; do \
+                       echo "$$j/output : $$i/exe" ; \
+               done ; \
+        done) \
+               > $@
+
+include Makefile.mpi.tests
+
+# override the rule from ../Makefile.rules by running things with
+# mpirun -np X
+get_ncpus = $(shell echo $(1) | $(PERL) -pi -e 's/.*ncpu_(\d+).*/\1/g;')
+get_exe = $(shell echo $(1) | $(PERL) -pi -e 's/ncpu_.*/exe/g;')
+
+%/output:
+       @echo =====Running==MPI== $@
+       @echo Running > $(dir $@)/status
+       @$(ULIMIT) -t 2400 ; \
+               mpirun -np $(call get_ncpus, $@) ./$(call get_exe, $@) ; \
+               if test ! $$? = 0 ; then rm $@ ; false ; fi
+       @perl -pi $(normalize)  $@
+
diff --git a/tests/gla/gla.h b/tests/gla/gla.h
new file mode 100644 (file)
index 0000000..dd511d9
--- /dev/null
@@ -0,0 +1,79 @@
+
+#include <deal.II/lac/abstract_linear_algebra.h>
+
+class LA_PETSc
+{
+  public:
+    class MPI
+    {
+      public:
+       typedef LinearAlgebraPETSc::MPI::Vector Vector;
+    };
+};
+
+class LA_Trilinos
+{
+  public:
+    class MPI
+    {
+      public:
+       typedef LinearAlgebraPETSc::MPI::Vector Vector;
+    };
+};
+
+class LA_Dummy
+{
+  public:
+    class MPI
+    {
+      public:
+       class Vector
+       {
+         public:
+           
+           Vector(const IndexSet local, const MPI_Comm &comm=MPI_COMM_WORLD)
+             {}
+           
+           Vector(const IndexSet &local, const IndexSet &ghost, const MPI_Comm &comm=MPI_COMM_WORLD) 
+             {}
+           
+           Vector(const MPI_Comm &comm, const IndexSet local) 
+             {}
+           
+           Vector(const MPI_Comm &commm, const IndexSet &local, const IndexSet &ghost)
+             {}
+           
+           void compress(VectorOperation::values op)
+             {}
+           
+           bool has_ghost_elements()
+             {
+               return false;}
+
+           unsigned int size()
+             {return 0;}
+           
+           
+           const Vector & operator*=(const double factor)
+             {
+               return *this;
+             }
+           
+           double & operator()(unsigned int)
+             {
+               static double d;
+               return d;
+             }
+           
+           const double & operator()(unsigned int) const
+             {
+               static double d;
+               return d;
+             }
+           
+           
+       };
+       
+       
+    };
+};
diff --git a/tests/gla/vec_01.cc b/tests/gla/vec_01.cc
new file mode 100644 (file)
index 0000000..a97f7d7
--- /dev/null
@@ -0,0 +1,122 @@
+//---------------------------------------------------------------------------
+//    $Id: ghost_01.cc 28440 2013-02-17 14:35:08Z heister $
+//    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.
+//
+//---------------------------------------------------------------------------
+
+
+
+#include "../tests.h"
+#include <deal.II/lac/abstract_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 vb(MPI_COMM_WORLD, local_active);
+  typename LA::MPI::Vector v(MPI_COMM_WORLD, local_active, local_relevant);
+
+                                  // 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;
+
+  Assert(vb.size() == numproc*2, ExcInternalError());
+  Assert(v.size() == numproc*2, ExcInternalError());
+
+  Assert(!vb.has_ghost_elements(), ExcInternalError());
+  Assert(v.has_ghost_elements(), ExcInternalError());
+  
+                                  // 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());
+
+                                  // done
+  if (myid==0)
+    deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv);
+  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_01").c_str());
+      deallog.attach(logfile);
+      deallog << std::setprecision(4);
+      deallog.depth_console(0);
+      deallog.threshold_double(1.e-10);
+
+      {        
+       deallog.push("PETSc");
+       test<LA_PETSc>();
+       deallog.pop();  
+       deallog.push("Trilinos");
+       test<LA_Trilinos>();
+       deallog.pop();  
+      }
+      
+    }
+  else
+      {        
+       deallog.push("PETSc");
+       test<LA_PETSc>();
+       deallog.pop();  
+       deallog.push("Trilinos");
+       test<LA_Trilinos>();
+       deallog.pop();  
+      }
+
+  if (myid==9999)
+    test<LA_Dummy>();
+  
+
+}
diff --git a/tests/gla/vec_01/ncpu_10/cmp/generic b/tests/gla/vec_01/ncpu_10/cmp/generic
new file mode 100644 (file)
index 0000000..eb8100b
--- /dev/null
@@ -0,0 +1,11 @@
+
+DEAL:0:PETSc::numproc=10
+DEAL:0:PETSc::0:0.000
+DEAL:0:PETSc::1:2.000
+DEAL:0:PETSc::ghost: 2.000
+DEAL:0:PETSc::OK
+DEAL:0:Trilinos::numproc=10
+DEAL:0:Trilinos::0:0.000
+DEAL:0:Trilinos::1:2.000
+DEAL:0:Trilinos::ghost: 2.000
+DEAL:0:Trilinos::OK
diff --git a/tests/gla/vec_01/ncpu_4/cmp/generic b/tests/gla/vec_01/ncpu_4/cmp/generic
new file mode 100644 (file)
index 0000000..391c391
--- /dev/null
@@ -0,0 +1,11 @@
+
+DEAL:0:PETSc::numproc=4
+DEAL:0:PETSc::0:0.000
+DEAL:0:PETSc::1:2.000
+DEAL:0:PETSc::ghost: 2.000
+DEAL:0:PETSc::OK
+DEAL:0:Trilinos::numproc=4
+DEAL:0:Trilinos::0:0.000
+DEAL:0:Trilinos::1:2.000
+DEAL:0:Trilinos::ghost: 2.000
+DEAL:0:Trilinos::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.