]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix source/lac
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 6 Jan 2019 23:34:24 +0000 (00:34 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Fri, 18 Jan 2019 10:27:09 +0000 (11:27 +0100)
source/lac/dynamic_sparsity_pattern.cc
source/lac/petsc_parallel_sparse_matrix.cc
source/lac/scalapack.cc
source/lac/sparsity_tools.cc
source/lac/trilinos_epetra_vector.cc
source/lac/trilinos_sparse_matrix.cc

index ac203a5c3630a128286280debbccedec924412c5..dcf53e1bbcef60a9194ea5a725c3289562fa5ed6 100644 (file)
@@ -342,9 +342,9 @@ DynamicSparsityPattern::max_entries_per_row() const
     return 0;
 
   size_type m = 0;
-  for (size_type i = 0; i < lines.size(); ++i)
+  for (const auto &line : lines)
     {
-      m = std::max(m, static_cast<size_type>(lines[i].entries.size()));
+      m = std::max(m, static_cast<size_type>(line.entries.size()));
     }
 
   return m;
@@ -484,11 +484,8 @@ DynamicSparsityPattern::print(std::ostream &out) const
     {
       out << '[' << (rowset.size() == 0 ? row : rowset.nth_index_in_set(row));
 
-      for (std::vector<size_type>::const_iterator j =
-             lines[row].entries.begin();
-           j != lines[row].entries.end();
-           ++j)
-        out << ',' << *j;
+      for (const auto entry : lines[row].entries)
+        out << ',' << entry;
 
       out << ']' << std::endl;
     }
@@ -506,16 +503,13 @@ DynamicSparsityPattern::print_gnuplot(std::ostream &out) const
       const size_type rowindex =
         rowset.size() == 0 ? row : rowset.nth_index_in_set(row);
 
-      for (std::vector<size_type>::const_iterator j =
-             lines[row].entries.begin();
-           j != lines[row].entries.end();
-           ++j)
+      for (const auto entry : lines[row].entries)
         // while matrix entries are usually
         // written (i,j), with i vertical and
         // j horizontal, gnuplot output is
         // x-y, that is we have to exchange
         // the order of output
-        out << *j << " " << -static_cast<signed int>(rowindex) << std::endl;
+        out << entry << " " << -static_cast<signed int>(rowindex) << std::endl;
     }
 
 
@@ -533,13 +527,10 @@ DynamicSparsityPattern::bandwidth() const
       const size_type rowindex =
         rowset.size() == 0 ? row : rowset.nth_index_in_set(row);
 
-      for (std::vector<size_type>::const_iterator j =
-             lines[row].entries.begin();
-           j != lines[row].entries.end();
-           ++j)
-        if (static_cast<size_type>(std::abs(static_cast<int>(rowindex - *j))) >
-            b)
-          b = std::abs(static_cast<signed int>(rowindex - *j));
+      for (const auto entry : lines[row].entries)
+        if (static_cast<size_type>(
+              std::abs(static_cast<int>(rowindex - entry))) > b)
+          b = std::abs(static_cast<signed int>(rowindex - entry));
     }
 
   return b;
@@ -554,9 +545,9 @@ DynamicSparsityPattern::n_nonzero_elements() const
     return 0;
 
   size_type n = 0;
-  for (size_type i = 0; i < lines.size(); ++i)
+  for (const auto &line : lines)
     {
-      n += lines[i].entries.size();
+      n += line.entries.size();
     }
 
   return n;
@@ -570,8 +561,8 @@ DynamicSparsityPattern::memory_consumption() const
                   MemoryConsumption::memory_consumption(rowset) -
                   sizeof(rowset);
 
-  for (size_type i = 0; i < lines.size(); ++i)
-    mem += MemoryConsumption::memory_consumption(lines[i]);
+  for (const auto &line : lines)
+    mem += MemoryConsumption::memory_consumption(line);
 
   return mem;
 }
index 88178237dd3deabb7b6a158d843805db120b5235..4b528a1cd00e6ca5ac0ec7f2ded90ddff9969bb4 100644 (file)
@@ -291,15 +291,15 @@ namespace PETScWrappers
       Assert(row_lengths.size() == m,
              ExcDimensionMismatch(row_lengths.size(), m));
 
-      // For the case that
-      // local_columns is smaller
-      // than one of the row lengths
-      // MatCreateMPIAIJ throws an
-      // error. In this case use a
+      // For the case that local_columns is smaller than one of the row lengths
+      // MatCreateMPIAIJ throws an error. In this case use a
       // PETScWrappers::SparseMatrix
-      for (size_type i = 0; i < row_lengths.size(); ++i)
-        Assert(row_lengths[i] <= local_columns,
-               ExcIndexRange(row_lengths[i], 1, local_columns + 1));
+      for (const size_type row_length : row_lengths)
+        {
+          (void)row_length;
+          Assert(row_length <= local_columns,
+                 ExcIndexRange(row_length, 1, local_columns + 1));
+        }
 
       // use the call sequence indicating a
       // maximal number of elements for each
index 4e1e038ffc73c45e76b0c1f461bdabdb13509ed6..b6bbfbb7d8e24c41e8252d1286003c12ea3e4cc0 100644 (file)
@@ -278,8 +278,7 @@ ScaLAPACKMatrix<NumberType>::reinit(
       // set process-local variables to something telling:
       n_local_rows    = -1;
       n_local_columns = -1;
-      for (unsigned int i = 0; i < 9; ++i)
-        descriptor[i] = -1;
+      std::fill(std::begin(descriptor), std::end(descriptor), -1);
     }
 }
 
index 0d36b69f9d8fb872fa89a73a306f8cb3c2642e7b..164231fc5922d795040333e4cab942fcaa4467ce 100644 (file)
@@ -592,11 +592,14 @@ namespace SparsityTools
              sparsity.row_index_set().size() == sparsity.n_rows(),
            ExcMessage(
              "Only valid for sparsity patterns which store all rows."));
-    for (SparsityPattern::size_type i = 0; i < starting_indices.size(); ++i)
-      Assert(starting_indices[i] < sparsity.n_rows(),
-             ExcMessage("Invalid starting index: All starting indices need "
-                        "to be between zero and the number of rows in the "
-                        "sparsity pattern."));
+    for (const auto starting_index : starting_indices)
+      {
+        (void)starting_index;
+        Assert(starting_index < sparsity.n_rows(),
+               ExcMessage("Invalid starting index: All starting indices need "
+                          "to be between zero and the number of rows in the "
+                          "sparsity pattern."));
+      }
 
     // store the indices of the dofs renumbered in the last round. Default to
     // starting points
@@ -629,12 +632,9 @@ namespace SparsityTools
         std::vector<DynamicSparsityPattern::size_type> next_round_dofs;
 
         // find all neighbors of the dofs numbered in the last round
-        for (DynamicSparsityPattern::size_type i = 0;
-             i < last_round_dofs.size();
-             ++i)
-          for (DynamicSparsityPattern::iterator j =
-                 sparsity.begin(last_round_dofs[i]);
-               j < sparsity.end(last_round_dofs[i]);
+        for (const auto dof : last_round_dofs)
+          for (DynamicSparsityPattern::iterator j = sparsity.begin(dof);
+               j < sparsity.end(dof);
                ++j)
             next_round_dofs.push_back(j->column());
 
@@ -689,17 +689,14 @@ namespace SparsityTools
           dofs_by_coordination;
 
         // find coordination number for each of these dofs
-        for (std::vector<DynamicSparsityPattern::size_type>::iterator s =
-               next_round_dofs.begin();
-             s != next_round_dofs.end();
-             ++s)
+        for (const types::global_dof_index next_round_dof : next_round_dofs)
           {
             const DynamicSparsityPattern::size_type coordination =
-              sparsity.row_length(*s);
+              sparsity.row_length(next_round_dof);
 
             // insert this dof at its coordination number
             const std::pair<const DynamicSparsityPattern::size_type, int>
-              new_entry(coordination, *s);
+              new_entry(coordination, next_round_dof);
             dofs_by_coordination.insert(new_entry);
           }
 
@@ -793,16 +790,16 @@ namespace SparsityTools
               // next set of possible neighbors
               min_neighbors = std::make_pair(numbers::invalid_dof_index,
                                              numbers::invalid_dof_index);
-              for (std::set<types::global_dof_index>::iterator it =
-                     current_neighbors.begin();
-                   it != current_neighbors.end();
-                   ++it)
+              for (const auto current_neighbor : current_neighbors)
                 {
-                  Assert(touched_nodes[*it] == numbers::invalid_dof_index,
+                  Assert(touched_nodes[current_neighbor] ==
+                           numbers::invalid_dof_index,
                          ExcInternalError());
-                  if (n_remaining_neighbors[*it] < min_neighbors.second)
+                  if (n_remaining_neighbors[current_neighbor] <
+                      min_neighbors.second)
                     min_neighbors =
-                      std::make_pair(*it, n_remaining_neighbors[*it]);
+                      std::make_pair(current_neighbor,
+                                     n_remaining_neighbors[current_neighbor]);
                 }
 
               // Among the set of nodes with the minimal number of neighbors,
@@ -810,13 +807,12 @@ namespace SparsityTools
               // i.e., the one with the largest row length
               const types::global_dof_index best_row_length =
                 min_neighbors.second;
-              for (std::set<types::global_dof_index>::iterator it =
-                     current_neighbors.begin();
-                   it != current_neighbors.end();
-                   ++it)
-                if (n_remaining_neighbors[*it] == best_row_length)
-                  if (row_lengths[*it] > min_neighbors.second)
-                    min_neighbors = std::make_pair(*it, row_lengths[*it]);
+              for (const auto current_neighbor : current_neighbors)
+                if (n_remaining_neighbors[current_neighbor] == best_row_length)
+                  if (row_lengths[current_neighbor] > min_neighbors.second)
+                    min_neighbors =
+                      std::make_pair(current_neighbor,
+                                     row_lengths[current_neighbor]);
 
               // Add the pivot and all direct neighbors of the pivot node not
               // yet touched to the list of new entries.
@@ -840,11 +836,11 @@ namespace SparsityTools
               // valid neighbor (here we assume symmetry of the
               // connectivity). Delete the entries of the current list from
               // the set of possible next pivots.
-              for (unsigned int i = 0; i < next_group.size(); ++i)
+              for (const auto index : next_group)
                 {
                   for (DynamicSparsityPattern::iterator it =
-                         connectivity.begin(next_group[i]);
-                       it != connectivity.end(next_group[i]);
+                         connectivity.begin(index);
+                       it != connectivity.end(index);
                        ++it)
                     {
                       if (touched_nodes[it->column()] ==
@@ -852,7 +848,7 @@ namespace SparsityTools
                         current_neighbors.insert(it->column());
                       n_remaining_neighbors[it->column()]--;
                     }
-                  current_neighbors.erase(next_group[i]);
+                  current_neighbors.erase(index);
                 }
             }
         }
@@ -982,9 +978,8 @@ namespace SparsityTools
     {
       std::vector<unsigned int> send_to;
       send_to.reserve(send_data.size());
-      for (map_vec_t::iterator it = send_data.begin(); it != send_data.end();
-           ++it)
-        send_to.push_back(it->first);
+      for (const auto &sparsity_line : send_data)
+        send_to.push_back(sparsity_line.first);
 
       num_receive =
         Utilities::MPI::compute_n_point_to_point_communications(mpi_comm,
@@ -997,16 +992,15 @@ namespace SparsityTools
     // send data
     {
       unsigned int idx = 0;
-      for (map_vec_t::iterator it = send_data.begin(); it != send_data.end();
-           ++it, ++idx)
+      for (const auto &sparsity_line : send_data)
         {
-          const int ierr = MPI_Isend(&(it->second[0]),
-                                     it->second.size(),
+          const int ierr = MPI_Isend(&(sparsity_line.second[0]),
+                                     sparsity_line.second.size(),
                                      DEAL_II_DOF_INDEX_MPI_TYPE,
-                                     it->first,
+                                     sparsity_line.first,
                                      124,
                                      mpi_comm,
-                                     &requests[idx]);
+                                     &requests[idx++]);
           AssertThrowMPI(ierr);
         }
     }
@@ -1128,9 +1122,8 @@ namespace SparsityTools
     {
       std::vector<unsigned int> send_to;
       send_to.reserve(send_data.size());
-      for (map_vec_t::iterator it = send_data.begin(); it != send_data.end();
-           ++it)
-        send_to.push_back(it->first);
+      for (const auto &sparsity_line : send_data)
+        send_to.push_back(sparsity_line.first);
 
       num_receive =
         Utilities::MPI::compute_n_point_to_point_communications(mpi_comm,
@@ -1143,16 +1136,15 @@ namespace SparsityTools
     // send data
     {
       unsigned int idx = 0;
-      for (map_vec_t::iterator it = send_data.begin(); it != send_data.end();
-           ++it, ++idx)
+      for (const auto &sparsity_line : send_data)
         {
-          const int ierr = MPI_Isend(&(it->second[0]),
-                                     it->second.size(),
+          const int ierr = MPI_Isend(&(sparsity_line.second[0]),
+                                     sparsity_line.second.size(),
                                      DEAL_II_DOF_INDEX_MPI_TYPE,
-                                     it->first,
+                                     sparsity_line.first,
                                      124,
                                      mpi_comm,
-                                     &requests[idx]);
+                                     &requests[idx++]);
           AssertThrowMPI(ierr);
         }
     }
index 52264d727d3afd45e6cbd0c1ea3f75258ddb58fa..cc1857686f9bec48550910d6b447ed588c0f348e 100644 (file)
@@ -572,7 +572,7 @@ namespace LinearAlgebra
           const size_type n_indices = vector->Map().NumMyElements();
 #    ifndef DEAL_II_WITH_64BIT_INDICES
           unsigned int *vector_indices =
-            (unsigned int *)vector->Map().MyGlobalElements();
+            reinterpret_cast<unsigned int *>(vector->Map().MyGlobalElements());
 #    else
           size_type *vector_indices =
             reinterpret_cast<size_type *>(vector->Map().MyGlobalElements64());
index 62b73b1c75078bd686dc282f0db39c005d57b08a..d9787fc12676bf5f8aa444d6ab2382bff2ce6a36 100644 (file)
@@ -1266,8 +1266,8 @@ namespace TrilinosWrappers
   SparseMatrix::clear_rows(const std::vector<size_type> &rows,
                            const TrilinosScalar          new_diag_value)
   {
-    for (size_type row = 0; row < rows.size(); ++row)
-      clear_row(rows[row], new_diag_value);
+    for (const auto row : rows)
+      clear_row(row, new_diag_value);
   }
 
 

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.