From 1ef517bbf3c62bfd973cdefe2eeb93cc6e2d2cf5 Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Tue, 7 Jul 2009 10:46:05 +0000
Subject: [PATCH] Work on pdd.

---
 AMDiS/bin/Makefile.am              |   2 +-
 AMDiS/bin/Makefile.in              |   2 +-
 AMDiS/libtool                      |  66 +++++++++---------
 AMDiS/src/Operator.cc              |   9 ++-
 AMDiS/src/ParallelDomainProblem.cc | 103 +++++++++++++++++------------
 AMDiS/src/ParallelDomainProblem.h  |   4 ++
 6 files changed, 104 insertions(+), 82 deletions(-)

diff --git a/AMDiS/bin/Makefile.am b/AMDiS/bin/Makefile.am
index f9714d71..b29383cb 100644
--- a/AMDiS/bin/Makefile.am
+++ b/AMDiS/bin/Makefile.am
@@ -31,7 +31,7 @@ if USE_PARALLEL_DOMAIN_AMDIS
   PARALLEL_AMDIS_SOURCES += \
   $(PARALLEL_DIR)/ParallelDomainProblem.h $(PARALLEL_DIR)/ParallelDomainProblem.cc
   libamdis_la_CXXFLAGS += -DHAVE_PARALLEL_DOMAIN_AMDIS=1
-  AMDIS_INCLUDES += -I/work/home7/witkowsk/local/include
+  AMDIS_INCLUDES += -I/u/witkowski/local/petsc-3.0.0-p4/include -I/u/witkowski/local/petsc-3.0.0-p4/linux-gnu-c-debug/include
 endif
 
 if ENABLE_UMFPACK
diff --git a/AMDiS/bin/Makefile.in b/AMDiS/bin/Makefile.in
index 1a484684..32db5b10 100644
--- a/AMDiS/bin/Makefile.in
+++ b/AMDiS/bin/Makefile.in
@@ -41,7 +41,7 @@ host_triplet = @host@
 @USE_PARALLEL_DOMAIN_AMDIS_TRUE@  $(PARALLEL_DIR)/ParallelDomainProblem.h $(PARALLEL_DIR)/ParallelDomainProblem.cc
 
 @USE_PARALLEL_DOMAIN_AMDIS_TRUE@am__append_3 = -DHAVE_PARALLEL_DOMAIN_AMDIS=1
-@USE_PARALLEL_DOMAIN_AMDIS_TRUE@am__append_4 = -I/work/home7/witkowsk/local/include
+@USE_PARALLEL_DOMAIN_AMDIS_TRUE@am__append_4 = -I/u/witkowski/local/petsc-3.0.0-p4/include -I/u/witkowski/local/petsc-3.0.0-p4/linux-gnu-c-debug/include
 @ENABLE_UMFPACK_TRUE@am__append_5 = -DHAVE_UMFPACK=1 -DMTL_HAS_UMFPACK
 @ENABLE_UMFPACK_TRUE@am__append_6 = -I$(LIB_DIR)/UFconfig \
 @ENABLE_UMFPACK_TRUE@	            -I$(LIB_DIR)/AMD/Include \
diff --git a/AMDiS/libtool b/AMDiS/libtool
index aeddb890..10b5aa1c 100755
--- a/AMDiS/libtool
+++ b/AMDiS/libtool
@@ -30,10 +30,10 @@
 # the same distribution terms that you use for the rest of that program.
 
 # A sed program that does not truncate output.
-SED="/usr/bin/sed"
+SED="/bin/sed"
 
 # Sed that helps us avoid accidentally triggering echo(1) options like -n.
-Xsed="/usr/bin/sed -e 1s/^X//"
+Xsed="/bin/sed -e 1s/^X//"
 
 # The HP-UX ksh and POSIX shell print the target directory to stdout
 # if CDPATH is set.
@@ -44,7 +44,7 @@ available_tags=" CXX F77"
 
 # ### BEGIN LIBTOOL CONFIG
 
-# Libtool was configured on host p2d072:
+# Libtool was configured on host NWRW15:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -66,12 +66,12 @@ fast_install=yes
 
 # The host system.
 host_alias=
-host=x86_64-unknown-linux-gnu
+host=i686-pc-linux-gnu
 host_os=linux-gnu
 
 # The build system.
 build_alias=
-build=x86_64-unknown-linux-gnu
+build=i686-pc-linux-gnu
 build_os=linux-gnu
 
 # An echo program that does not interpret backslashes.
@@ -82,25 +82,25 @@ AR="ar"
 AR_FLAGS="cru"
 
 # A C compiler.
-LTCC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpicc"
+LTCC="/usr/lib/openmpi/1.2.7-gcc//bin/mpicc"
 
 # LTCC compiler flags.
 LTCFLAGS="-g -O2"
 
 # A language-specific compiler.
-CC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpicc"
+CC="/usr/lib/openmpi/1.2.7-gcc//bin/mpicc"
 
 # Is the compiler the GNU C compiler?
 with_gcc=yes
 
-gcc_dir=`gcc -print-file-name=. | /usr/bin/sed 's,/\.$,,'`
+gcc_dir=`gcc -print-file-name=. | /bin/sed 's,/\.$,,'`
 gcc_ver=`gcc -dumpversion`
 
 # An ERE matcher.
 EGREP="grep -E"
 
 # The linker used to build libraries.
-LD="/usr/x86_64-suse-linux/bin/ld -m elf_x86_64"
+LD="/usr/bin/ld"
 
 # Whether we need hard or soft links.
 LN_S="ln -s"
@@ -328,10 +328,10 @@ variables_saved_for_relink="PATH LD_LIBRARY_PATH LD_RUN_PATH GCC_EXEC_PREFIX COM
 link_all_deplibs=unknown
 
 # Compile-time system search path for libraries
-sys_lib_search_path_spec=`echo "/lib64 /usr/lib64 /usr/local/lib64" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
+sys_lib_search_path_spec=`echo " /usr/lib/gcc/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/lib/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/lib/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../ /lib/i386-redhat-linux/4.1.2/ /lib/ /usr/lib/i386-redhat-linux/4.1.2/ /usr/lib/" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
 
 # Run-time system search path for libraries
-sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /usr/X11R6/lib64/Xaw3d /usr/X11R6/lib64 /usr/X11R6/lib/Xaw3d /usr/X11R6/lib /usr/x86_64-suse-linux/lib /usr/local/lib64 /usr/local/lib /opt/kde3/lib64 /opt/kde3/lib /opt/gnome/lib64 /opt/gnome/lib /lib64 /lib /usr/lib64 /usr/lib /opt/cluster/intel/cce/9.1.042/lib /opt/cluster/intel/fce/9.1.036/lib /opt/cluster/Pathscale3.0/lib/2.9.99 /opt/cluster/Pathscale3.0/lib/2.9.99/32 /work/licsoft/compilers/pgi/linux86-64/6.2/lib /work/licsoft/compilers/pgi/linux86-64/6.2/libso "
+sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/lib/octave-2.9.9 /usr/lib/qt-3.3/lib "
 
 # Fix the shell variable $srcfile for the compiler.
 fix_srcfile_path=""
@@ -6763,7 +6763,7 @@ build_old_libs=`case $build_libtool_libs in yes) $echo no;; *) $echo yes;; esac`
 # End:
 # ### BEGIN LIBTOOL TAG CONFIG: CXX
 
-# Libtool was configured on host p2d072:
+# Libtool was configured on host NWRW15:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -6785,12 +6785,12 @@ fast_install=yes
 
 # The host system.
 host_alias=
-host=x86_64-unknown-linux-gnu
+host=i686-pc-linux-gnu
 host_os=linux-gnu
 
 # The build system.
 build_alias=
-build=x86_64-unknown-linux-gnu
+build=i686-pc-linux-gnu
 build_os=linux-gnu
 
 # An echo program that does not interpret backslashes.
@@ -6801,25 +6801,25 @@ AR="ar"
 AR_FLAGS="cru"
 
 # A C compiler.
-LTCC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpicc"
+LTCC="/usr/lib/openmpi/1.2.7-gcc//bin/mpicc"
 
 # LTCC compiler flags.
 LTCFLAGS="-g -O2"
 
 # A language-specific compiler.
-CC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpiCC"
+CC="/usr/lib/openmpi/1.2.7-gcc//bin/mpiCC"
 
 # Is the compiler the GNU C compiler?
 with_gcc=yes
 
-gcc_dir=`gcc -print-file-name=. | /usr/bin/sed 's,/\.$,,'`
+gcc_dir=`gcc -print-file-name=. | /bin/sed 's,/\.$,,'`
 gcc_ver=`gcc -dumpversion`
 
 # An ERE matcher.
 EGREP="grep -E"
 
 # The linker used to build libraries.
-LD="/usr/x86_64-suse-linux/bin/ld -m elf_x86_64"
+LD="/usr/bin/ld"
 
 # Whether we need hard or soft links.
 LN_S="ln -s"
@@ -6948,11 +6948,11 @@ striplib="strip --strip-unneeded"
 
 # Dependencies to place before the objects being linked to create a
 # shared library.
-predep_objects=`echo "/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtbeginS.o" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
+predep_objects=`echo "/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crti.o /usr/lib/gcc/i386-redhat-linux/4.1.2/crtbeginS.o" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
 
 # Dependencies to place after the objects being linked to create a
 # shared library.
-postdep_objects=`echo "/usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtendS.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crtn.o" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
+postdep_objects=`echo "/usr/lib/gcc/i386-redhat-linux/4.1.2/crtendS.o /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crtn.o" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
 
 # Dependencies to place before the objects being linked to create a
 # shared library.
@@ -6960,11 +6960,11 @@ predeps=""
 
 # Dependencies to place after the objects being linked to create a
 # shared library.
-postdeps="-lmpi_cxx -lmpi -lopen-rte -lopen-pal -libverbs -lrt -lnuma -ldl -lnsl -lutil -ldl -lstdc++ -lm -lgcc_s -lpthread -lc -lgcc_s"
+postdeps="-lmpi_cxx -lmpi -lopen-rte -lopen-pal -ldl -lnsl -lutil -ldl -lstdc++ -lm -lgcc_s -lpthread -lc -lgcc_s"
 
 # The library search path used internally by the compiler when linking
 # a shared library.
-compiler_lib_search_path=`echo "-L/usr/lib64 -L/licsoft/libraries/openmpi/1.2.6/64bit/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../.." | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
+compiler_lib_search_path=`echo "-L/usr/lib/openmpi/1.2.7-gcc/lib -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2/../../.." | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
 
 # Method to check whether dependent libraries are shared objects.
 deplibs_check_method="pass_all"
@@ -7044,10 +7044,10 @@ variables_saved_for_relink="PATH LD_LIBRARY_PATH LD_RUN_PATH GCC_EXEC_PREFIX COM
 link_all_deplibs=unknown
 
 # Compile-time system search path for libraries
-sys_lib_search_path_spec=`echo "/lib64 /usr/lib64 /usr/local/lib64" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
+sys_lib_search_path_spec=`echo " /usr/lib/gcc/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/lib/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/lib/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../ /lib/i386-redhat-linux/4.1.2/ /lib/ /usr/lib/i386-redhat-linux/4.1.2/ /usr/lib/" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
 
 # Run-time system search path for libraries
-sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /usr/X11R6/lib64/Xaw3d /usr/X11R6/lib64 /usr/X11R6/lib/Xaw3d /usr/X11R6/lib /usr/x86_64-suse-linux/lib /usr/local/lib64 /usr/local/lib /opt/kde3/lib64 /opt/kde3/lib /opt/gnome/lib64 /opt/gnome/lib /lib64 /lib /usr/lib64 /usr/lib /opt/cluster/intel/cce/9.1.042/lib /opt/cluster/intel/fce/9.1.036/lib /opt/cluster/Pathscale3.0/lib/2.9.99 /opt/cluster/Pathscale3.0/lib/2.9.99/32 /work/licsoft/compilers/pgi/linux86-64/6.2/lib /work/licsoft/compilers/pgi/linux86-64/6.2/libso "
+sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/lib/octave-2.9.9 /usr/lib/qt-3.3/lib "
 
 # Fix the shell variable $srcfile for the compiler.
 fix_srcfile_path=""
@@ -7071,7 +7071,7 @@ include_expsyms=""
 
 # ### BEGIN LIBTOOL TAG CONFIG: F77
 
-# Libtool was configured on host p2d072:
+# Libtool was configured on host NWRW15:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -7093,12 +7093,12 @@ fast_install=yes
 
 # The host system.
 host_alias=
-host=x86_64-unknown-linux-gnu
+host=i686-pc-linux-gnu
 host_os=linux-gnu
 
 # The build system.
 build_alias=
-build=x86_64-unknown-linux-gnu
+build=i686-pc-linux-gnu
 build_os=linux-gnu
 
 # An echo program that does not interpret backslashes.
@@ -7109,7 +7109,7 @@ AR="ar"
 AR_FLAGS="cru"
 
 # A C compiler.
-LTCC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpicc"
+LTCC="/usr/lib/openmpi/1.2.7-gcc//bin/mpicc"
 
 # LTCC compiler flags.
 LTCFLAGS="-g -O2"
@@ -7118,16 +7118,16 @@ LTCFLAGS="-g -O2"
 CC="g77"
 
 # Is the compiler the GNU C compiler?
-with_gcc=
+with_gcc=yes
 
-gcc_dir=`gcc -print-file-name=. | /usr/bin/sed 's,/\.$,,'`
+gcc_dir=`gcc -print-file-name=. | /bin/sed 's,/\.$,,'`
 gcc_ver=`gcc -dumpversion`
 
 # An ERE matcher.
 EGREP="grep -E"
 
 # The linker used to build libraries.
-LD="/usr/x86_64-suse-linux/bin/ld -m elf_x86_64"
+LD="/usr/bin/ld"
 
 # Whether we need hard or soft links.
 LN_S="ln -s"
@@ -7355,10 +7355,10 @@ variables_saved_for_relink="PATH LD_LIBRARY_PATH LD_RUN_PATH GCC_EXEC_PREFIX COM
 link_all_deplibs=unknown
 
 # Compile-time system search path for libraries
-sys_lib_search_path_spec=`echo "/lib64 /usr/lib64 /usr/local/lib64" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
+sys_lib_search_path_spec=`echo " /usr/lib/gcc/i386-redhat-linux/3.4.6/ /usr/lib/gcc/i386-redhat-linux/3.4.6/ /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../i386-redhat-linux/lib/i386-redhat-linux/3.4.6/ /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../i386-redhat-linux/lib/ /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../i386-redhat-linux/3.4.6/ /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../ /lib/i386-redhat-linux/3.4.6/ /lib/ /usr/lib/i386-redhat-linux/3.4.6/ /usr/lib/" | $SED -e "s@${gcc_dir}@\${gcc_dir}@g;s@${gcc_ver}@\${gcc_ver}@g"`
 
 # Run-time system search path for libraries
-sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /usr/X11R6/lib64/Xaw3d /usr/X11R6/lib64 /usr/X11R6/lib/Xaw3d /usr/X11R6/lib /usr/x86_64-suse-linux/lib /usr/local/lib64 /usr/local/lib /opt/kde3/lib64 /opt/kde3/lib /opt/gnome/lib64 /opt/gnome/lib /lib64 /lib /usr/lib64 /usr/lib /opt/cluster/intel/cce/9.1.042/lib /opt/cluster/intel/fce/9.1.036/lib /opt/cluster/Pathscale3.0/lib/2.9.99 /opt/cluster/Pathscale3.0/lib/2.9.99/32 /work/licsoft/compilers/pgi/linux86-64/6.2/lib /work/licsoft/compilers/pgi/linux86-64/6.2/libso "
+sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/lib/octave-2.9.9 /usr/lib/qt-3.3/lib "
 
 # Fix the shell variable $srcfile for the compiler.
 fix_srcfile_path=""
diff --git a/AMDiS/src/Operator.cc b/AMDiS/src/Operator.cc
index 537664e0..f5110457 100644
--- a/AMDiS/src/Operator.cc
+++ b/AMDiS/src/Operator.cc
@@ -257,8 +257,7 @@ namespace AMDiS {
       double val = 0.0;
       for (int j = 0; j < dimOfWorld; j++)
 	val += Lambda[i][j] * b[j];
-      val *= factor;
-      Lb[i] += val;
+      Lb[i] += val * factor;
     }    
   }
 
@@ -862,9 +861,9 @@ namespace AMDiS {
     const DimVec<WorldVector<double> > &Lambda = elInfo->getGrdLambda();
     for (int iq = 0; iq < nPoints; iq++) {
       if (b)
-	lb(Lambda, *b, Lb[iq], (vec1AtQPs[iq])*(vec2AtQPs[iq]));
+	lb(Lambda, *b, Lb[iq], vec1AtQPs[iq] * vec2AtQPs[iq]);
       else
-	l1(Lambda, Lb[iq], (vec1AtQPs[iq])*(vec2AtQPs[iq]));
+	l1(Lambda, Lb[iq], vec1AtQPs[iq] * vec2AtQPs[iq]);
     }
   }
   
@@ -877,7 +876,7 @@ namespace AMDiS {
   {
     if (grdUhAtQP)
       for (int iq = 0; iq < nPoints; iq++) 
-	result[iq] += fac * (vec1AtQPs[iq]) * (vec2AtQPs[iq]) * ((*b) * grdUhAtQP[iq]);
+	result[iq] += fac * vec1AtQPs[iq] * vec2AtQPs[iq] * ((*b) * grdUhAtQP[iq]);
   }
 
   Vec3FctAtQP_FOT::Vec3FctAtQP_FOT(DOFVectorBase<double> *dv1, DOFVectorBase<double> *dv2,DOFVectorBase<double> *dv3,
diff --git a/AMDiS/src/ParallelDomainProblem.cc b/AMDiS/src/ParallelDomainProblem.cc
index 5acdb25f..773b72d1 100644
--- a/AMDiS/src/ParallelDomainProblem.cc
+++ b/AMDiS/src/ParallelDomainProblem.cc
@@ -1,3 +1,6 @@
+#include <boost/lambda/lambda.hpp>
+#include <algorithm>
+
 #include "ParallelDomainProblem.h"
 #include "ProblemScal.h"
 #include "ProblemInstat.h"
@@ -16,6 +19,8 @@
 #include "petscksp.h"
 
 namespace AMDiS {
+  
+  using namespace boost::lambda;
 
   PetscErrorCode myKSPMonitor(KSP ksp, PetscInt iter, PetscReal rnorm, void *)
   {
@@ -79,7 +84,7 @@ namespace AMDiS {
     // Set of all DOFs of the rank.
     std::vector<const DegreeOfFreedom*> rankDOFs;
     // Number of DOFs in ranks partition that are owned by the rank.
-    int nRankDOFs = 0;
+    nRankDOFs = 0;
     // Number of all DOFs in the macro mesh.
     int nOverallDOFs = 0;
 
@@ -114,7 +119,6 @@ namespace AMDiS {
       admin.setFirstHole(mapLocalGlobalDOFs.size());
     }
 
-
     // === Global refinements. ===
 
     int globalRefinement = 0;
@@ -193,8 +197,8 @@ namespace AMDiS {
       for (icursor_type icursor = begin<nz>(cursor), 
 	     icend = end<nz>(cursor); icursor != icend; ++icursor)
 	if (value(*icursor) != 0.0) {
-	  int r = mapLocalGlobalDOFs[row(*icursor)];
-	  int c = mapLocalGlobalDOFs[col(*icursor)];  
+ 	  int r = mapLocalGlobalDOFs[row(*icursor)];
+ 	  int c = mapLocalGlobalDOFs[col(*icursor)];  
 	  double v = value(*icursor);
 
 	  MatSetValues(petscMatrix, 1, &r, 1, &c, &v, ADD_VALUES);
@@ -217,31 +221,37 @@ namespace AMDiS {
 
   void ParallelDomainBase::solvePetscMatrix(DOFVector<double> *vec)
   {
+    FUNCNAME("ParallelDomainBase::solvePetscMatrix()");
+
     KSP ksp;
     PC pc;
 
     KSPCreate(PETSC_COMM_WORLD, &ksp);
     KSPSetOperators(ksp, petscMatrix, petscMatrix, DIFFERENT_NONZERO_PATTERN);
     KSPGetPC(ksp, &pc);
-    PCSetType(pc, PCJACOBI);
+    PCSetType(pc, PCNONE);
     KSPSetTolerances(ksp, 1.e-7, PETSC_DEFAULT, PETSC_DEFAULT, PETSC_DEFAULT);
-    KSPSetType(ksp, KSPBCGS);
+    //    KSPSetType(ksp, KSPBCGS);
+    KSPSetType(ksp, KSPCG);
     KSPMonitorSet(ksp, myKSPMonitor, PETSC_NULL, 0);
     KSPSolve(ksp, petscRhsVec, petscSolVec);
 
+#if (DEBUG != 0)
+    int size = 0;
+    VecGetLocalSize(petscSolVec, &size);
+    TEST_EXIT(size == nRankDOFs)("Vector and rank DOFs does not fit together!\n");
+#endif
+
     PetscScalar *vecPointer;
     VecGetArray(petscSolVec, &vecPointer);
+    vec->set(1.0);
 
-    DOFVector<double>::Iterator dofIt(vec, USED_DOFS);
-    int counter = 0;
-    for (dofIt.reset(); !dofIt.end(); ++dofIt) {
-      *dofIt = vecPointer[mapGlobalLocalDOFs[rstart + counter]];
-      counter++;
-    }
+    for (int i = 0; i < nRankDOFs; i++)
+      (*vec)[mapGlobalLocalDOFs[i]] = vecPointer[i];
 
     VecRestoreArray(petscSolVec, &vecPointer);
 
-#if 0
+#if 1
     std::vector<double*> sendBuffers(sendDofs.size());
     std::vector<double*> recvBuffers(recvDofs.size());
 
@@ -256,7 +266,7 @@ namespace AMDiS {
       sendBuffers[i] = new double[nSendDOFs];
 
       for (int j = 0; j < nSendDOFs; j++)
-	sendBuffers[i][j] = (*vec)[(sendIt->second)[j][0]];
+	sendBuffers[i][j] = (*vec)[*((sendIt->second)[j])];
 
       request[requestCounter++] =
 	mpiComm.Isend(sendBuffers[i], nSendDOFs, MPI_DOUBLE, sendIt->first, 0);
@@ -281,9 +291,8 @@ namespace AMDiS {
     for (RankToDofContainer::iterator recvIt = recvDofs.begin();
 	 recvIt != recvDofs.end();
 	 ++recvIt, i++) {
-      for (int j = 0; j < static_cast<int>(recvIt->second.size()); j++) {
+      for (int j = 0; j < static_cast<int>(recvIt->second.size()); j++)
 	(*vec)[*(recvIt->second)[j]] = recvBuffers[i][j];
-      }
 
       delete [] recvBuffers[i];
     }
@@ -531,8 +540,9 @@ namespace AMDiS {
     rstart -= nRankDOFs;
 
 
-    typedef std::map<const DegreeOfFreedom*, DegreeOfFreedom> DofIndexMap;
-    DofIndexMap rankDofsNewLocalIndex, rankDofsNewGlobalIndex;
+    rankDofsNewLocalIndex.clear();
+    rankDofsNewGlobalIndex.clear();
+
     int i = 0;
     for (DofContainer::iterator dofIt = rankAllDofs.begin();
 	 dofIt != rankAllDofs.end(); ++dofIt) {
@@ -547,20 +557,7 @@ namespace AMDiS {
       i++;
     }
 
-    if (mpiRank == 0) {
-      for (DofContainer::iterator dofIt = rankAllDofs.begin();
-	   dofIt != rankAllDofs.end(); ++dofIt) {
-	std::cout << "OLD DOF = " << **dofIt << "   NEW L DOF = " << rankDofsNewLocalIndex[*dofIt];
-	if (rankDofsNewGlobalIndex.find(*dofIt) != rankDofsNewGlobalIndex.end())
-	  std::cout << "    NEW G DOF = " << rankDofsNewGlobalIndex[*dofIt];
-	std::cout << std::endl;
-      }
-    }
-
-    exit(0);
-
-
-  
+ 
     // === Create information which dof indices must be send and which must  ===
     // === be received.                                                      ===
 
@@ -573,8 +570,7 @@ namespace AMDiS {
     // another rank.
     std::map<int, int> recvNewDofs;
 
-    for (DofToRank::iterator it = boundaryDOFs.begin();
-	 it != boundaryDOFs.end(); ++it) {
+    for (DofToRank::iterator it = boundaryDOFs.begin(); it != boundaryDOFs.end(); ++it) {
 
       if (it->second == mpiRank) {
 	// If the boundary dof is a rank dof, it must be send to other ranks.
@@ -591,8 +587,8 @@ namespace AMDiS {
 	  }
 	}
       } else {
-	// If the boundary dof is not a rank dof, its new dof index, and later
-	// also the dof values, must be received from another rank.
+	// If the boundary dof is not a rank dof, its new dof index (and later
+	// also the dof values) must be received from another rank.
 	if (recvNewDofs.find(it->second) == recvNewDofs.end()) 
 	  recvNewDofs[it->second] = 1;
 	else
@@ -651,12 +647,8 @@ namespace AMDiS {
     
     // === Delete send buffers. ===
 
-    i = 0;
-    for (std::map<int, std::map<const DegreeOfFreedom*, DegreeOfFreedom> >::iterator 
-	   sendIt = sendNewDofs.begin();
-	 sendIt != sendNewDofs.end();
-	 ++sendIt, i++) 
-      delete [] sendBuffers[i];
+    for (int j = 0; j < static_cast<int>(sendBuffers.size()); j++)
+      delete [] sendBuffers[j];
 
 
     // === Change dof indices for rank partition. ===
@@ -723,6 +715,33 @@ namespace AMDiS {
       mapLocalGlobalDOFs[localDof] = globalDof;
       mapGlobalLocalDOFs[globalDof] = localDof;
     }
+
+#if 0
+    if (mpiRank == 0) {
+      for (DofContainer::iterator dofIt = recvDofs[1].begin();
+	   dofIt != recvDofs[1].end(); ++dofIt) {
+	std::cout << "RECV " << **dofIt << std::endl;
+      }
+    }
+
+    exit(0);
+#endif
+
+#if 0
+    if (mpiRank == 0) {
+      for (DofContainer::iterator dofIt = rankAllDofs.begin();
+	   dofIt != rankAllDofs.end(); ++dofIt) {
+	std::cout << "DOF = " << **dofIt << " GLOBAL index = " 
+		  << rankDofsNewGlobalIndex[*dofIt] << " FROM MAP = " 
+		  << mapLocalGlobalDOFs[**dofIt]
+		  << "  AND BACK "
+		  << mapGlobalLocalDOFs[mapLocalGlobalDOFs[**dofIt]] 
+		  << std::endl;
+      }
+    }
+
+    exit(0);
+#endif
   }
 
 
diff --git a/AMDiS/src/ParallelDomainProblem.h b/AMDiS/src/ParallelDomainProblem.h
index 152865ee..32a46349 100644
--- a/AMDiS/src/ParallelDomainProblem.h
+++ b/AMDiS/src/ParallelDomainProblem.h
@@ -72,6 +72,8 @@ namespace AMDiS {
 
     typedef std::map<int, DofContainer> ElementIdxToDofs;
 
+    typedef std::map<const DegreeOfFreedom*, DegreeOfFreedom> DofIndexMap;
+
   public:
     ParallelDomainBase(const std::string& name,
 		       ProblemIterationInterface *iterationIF,
@@ -361,6 +363,8 @@ namespace AMDiS {
     DofToBool isRankDof;
 
     int rstart;
+
+    DofIndexMap rankDofsNewLocalIndex, rankDofsNewGlobalIndex;
   };
 
   bool cmpDofsByValue(const DegreeOfFreedom* dof1, const DegreeOfFreedom* dof2)
-- 
GitLab