]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
A few updates for parallel run. At least square matrices seem to work in parallel...
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 9 Sep 2008 16:32:30 +0000 (16:32 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 9 Sep 2008 16:32:30 +0000 (16:32 +0000)
git-svn-id: https://svn.dealii.org/trunk@16771 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/trilinos_vector.h
deal.II/lac/source/trilinos_sparse_matrix.cc
deal.II/lac/source/trilinos_vector.cc

index de66fabbaa10634330a4b001d4ebc4daf5d437d6..94275380cfeafa6bfdc0a0c90f76930c84587437 100755 (executable)
@@ -341,10 +341,14 @@ namespace TrilinosWrappers
       typedef const internal::VectorReference const_reference;
 
                                        /**
-                                        * Default constructor. It
-                                        * doesn't do anything, derived
-                                        * classes will have to
-                                        * initialize the data.
+                                        * Default constructor that
+                                        * generates an empty (zero
+                                        * size) vector. The function
+                                        * <tt>reinit()</tt> will have
+                                        * to give the vector the
+                                        * correct size and
+                                        * distribution among processes
+                                        * in case of an MPI run.
                                         */
       Vector ();
 
@@ -353,9 +357,9 @@ namespace TrilinosWrappers
                                        * Epetra_Map that already
                                        * knows how to distribute the
                                        * individual components among
-                                       * the MPI processors,
-                                       * including the size of the
-                                       * vector.
+                                       * the MPI processors.  It also
+                                       * includes information about
+                                       * the size of the vector.
                                         */
       Vector (const Epetra_Map &InputMap);
 
@@ -379,7 +383,7 @@ namespace TrilinosWrappers
                                         */
       virtual ~Vector ();
 
-                                      /** 
+                                      /**
                                        * Reinit functionality. This function
                                        * destroys the old vector content 
                                        * and generates a new one based on
@@ -387,7 +391,7 @@ namespace TrilinosWrappers
                                        */
       void reinit (const Epetra_Map &input_map);
 
-                                      /** 
+                                      /**
                                        * Reinit functionality. This function
                                        * copies the vector v to the current
                                        * one.
index 1f9af2c7ddea5916c18c1306b7317a5786a7799b..0d00c4fb091bea3696f20830d1e521c70f103578 100755 (executable)
@@ -186,25 +186,20 @@ namespace TrilinosWrappers
 //             ExcDimensionMismatch (matrix->NumGlobalCols(),
 //                                   sparsity_pattern.n_cols()));
 
-       std::vector<int> n_entries_per_row(n_rows);
-    
-       for (unsigned int row=0; row<n_rows; ++row)
-         n_entries_per_row[(int)row] = sparsity_pattern.row_length(row);
-    
        std::vector<double> values;
        std::vector<int>    row_indices;
     
        for (unsigned int row=0; row<n_rows; ++row)
          {
            const int row_length = sparsity_pattern.row_length(row);
-           row_indices.resize (row_length, 0);
+           row_indices.resize (row_length, -1);
            values.resize (row_length, 0.);
            
-           for (int col=0; col< row_length; ++col)
+           for (int col=0; col < row_length; ++col)
              row_indices[col] = sparsity_pattern.column_number (row, col);
            
-           matrix->InsertGlobalValues(row, row_length,
-                                      &values[0], &row_indices[0]);
+           matrix->InsertGlobalValues (row, row_length,
+                                       &values[0], &row_indices[0]);
          }
       }
     
@@ -222,40 +217,7 @@ namespace TrilinosWrappers
   SparseMatrix::reinit (const Epetra_Map       &input_map,
                        const SparsityPattern  &sparsity_pattern)
   {
-                                 // TODO: There seems to be problem
-                                 // in Epetra when a quadratic matrix
-                                 // is initialized with both row and
-                                 // column map. Maybe find something
-                                 // more out about this...
     reinit (input_map, input_map, sparsity_pattern);
-    
-    /*    matrix.reset();   
-
-    unsigned int n_rows = sparsity_pattern.n_rows();
-
-    if (row_map.Comm().MyPID() == 0)
-      {
-       Assert (input_map.NumGlobalElements() == (int)sparsity_pattern.n_rows(),
-               ExcDimensionMismatch (input_map.NumGlobalElements(),
-                                     sparsity_pattern.n_rows()));
-       Assert (input_map.NumGlobalElements() == (int)sparsity_pattern.n_cols(),
-               ExcDimensionMismatch (input_map.NumGlobalElements(),
-                                     sparsity_pattern.n_cols()));
-      }
-
-    row_map = input_map;
-    col_map = row_map;
-
-    std::vector<int> n_entries_per_row(n_rows);
-
-    for (unsigned int row=0; row<n_rows; ++row)
-      n_entries_per_row[(int)row] = sparsity_pattern.row_length(row);
-
-    matrix = std::auto_ptr<Epetra_FECrsMatrix>
-             (new Epetra_FECrsMatrix(Copy, row_map, &n_entries_per_row[0], 
-                                     false));
-
-                                     reinit (sparsity_pattern);*/
   }
 
 
@@ -287,9 +249,19 @@ namespace TrilinosWrappers
     for (unsigned int row=0; row<n_rows; ++row)
       n_entries_per_row[(int)row] = sparsity_pattern.row_length(row);
 
-    matrix = std::auto_ptr<Epetra_FECrsMatrix>
-             (new Epetra_FECrsMatrix(Copy, row_map, col_map,
-                                     &n_entries_per_row[0], false));
+                                 // TODO: There seems to be problem
+                                 // in Epetra when a quadratic matrix
+                                 // is initialized with both row and
+                                 // column map. Maybe find something
+                                 // more out about this...
+    if (row_map.SameAs(col_map) == true)
+      matrix = std::auto_ptr<Epetra_FECrsMatrix>
+               (new Epetra_FECrsMatrix(Copy, row_map,
+                                       &n_entries_per_row[0], false));
+    else
+      matrix = std::auto_ptr<Epetra_FECrsMatrix>
+               (new Epetra_FECrsMatrix(Copy, row_map, col_map,
+                                       &n_entries_per_row[0], false));
 
     reinit (sparsity_pattern);
   }
@@ -403,9 +375,9 @@ namespace TrilinosWrappers
   {
                                  // flush buffers
     int ierr;
-    //if (row_map.SameAs(col_map))
-      //ierr = matrix->GlobalAssemble ();
-    //else
+    if (row_map.SameAs(col_map))
+      ierr = matrix->GlobalAssemble ();
+    else
       ierr = matrix->GlobalAssemble (col_map, row_map);
     
     AssertThrow (ierr == 0, ExcTrilinosError(ierr));
@@ -569,11 +541,15 @@ namespace TrilinosWrappers
 
                                      // If the data is not on the
                                      // present processor, we can't
-                                     // continue.
+                                     // continue. Just print out
+                                     // zero.
+
+                                     // TODO: Is this reasonable?
     if ((trilinos_i == -1 ) || (trilinos_j == -1))
       {
-       Assert (false, ExcAccessToNonLocalElement(i, j, local_range().first,
-                                                 local_range().second));
+       return 0.;
+       //Assert (false, ExcAccessToNonLocalElement(i, j, local_range().first,
+       //                                local_range().second));
       }
     else
     {
@@ -639,7 +615,7 @@ namespace TrilinosWrappers
   unsigned int
   SparseMatrix::m () const
   {
-    int n_rows = matrix->NumGlobalRows();
+    int n_rows = matrix -> NumGlobalRows();
 
     return n_rows;
   }
@@ -669,8 +645,8 @@ namespace TrilinosWrappers
   SparseMatrix::local_range () const
   {
     int begin, end;
-    begin = matrix->RowMap().MinMyGID();
-    end = matrix->RowMap().MaxMyGID()+1;
+    begin = matrix -> RowMap().MinMyGID();
+    end = matrix -> RowMap().MaxMyGID()+1;
     
     return std::make_pair (begin, end);
   }
index c10a0a7f8e1d98042f19d9e6045d5ddea624fdd7..623788c09aa25e85137f327caa679ca4ec7eac3e 100755 (executable)
@@ -220,10 +220,18 @@ namespace TrilinosWrappers
                                         // the vector.
     int trilinos_i = vector->Map().LID(index);
     TrilinosScalar value = 0.;
+
+                                       // If the element is not
+                                       // present on the current
+                                       // processor, we can't
+                                       // continue. Just print out 0.
+
+                                       // TODO: Is this reasonable?
     if (trilinos_i == -1 )
       {
-        Assert (false, ExcAccessToNonlocalElement(index, local_range().first,
-                                                 local_range().second));
+       return 0.;
+        //Assert (false, ExcAccessToNonlocalElement(index, local_range().first,
+       //                                local_range().second));
       }
     else
       value = (*vector)[0][trilinos_i];

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.