From: Daniel Arndt Date: Sun, 6 Jan 2019 23:34:24 +0000 (+0100) Subject: Fix source/lac X-Git-Tag: v9.1.0-rc1~425^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d09710af7a8a8c48095d809cb156b0ac03782818;p=dealii.git Fix source/lac --- diff --git a/source/lac/dynamic_sparsity_pattern.cc b/source/lac/dynamic_sparsity_pattern.cc index ac203a5c36..dcf53e1bbc 100644 --- a/source/lac/dynamic_sparsity_pattern.cc +++ b/source/lac/dynamic_sparsity_pattern.cc @@ -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(lines[i].entries.size())); + m = std::max(m, static_cast(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::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::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(rowindex) << std::endl; + out << entry << " " << -static_cast(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::const_iterator j = - lines[row].entries.begin(); - j != lines[row].entries.end(); - ++j) - if (static_cast(std::abs(static_cast(rowindex - *j))) > - b) - b = std::abs(static_cast(rowindex - *j)); + for (const auto entry : lines[row].entries) + if (static_cast( + std::abs(static_cast(rowindex - entry))) > b) + b = std::abs(static_cast(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; } diff --git a/source/lac/petsc_parallel_sparse_matrix.cc b/source/lac/petsc_parallel_sparse_matrix.cc index 88178237dd..4b528a1cd0 100644 --- a/source/lac/petsc_parallel_sparse_matrix.cc +++ b/source/lac/petsc_parallel_sparse_matrix.cc @@ -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 diff --git a/source/lac/scalapack.cc b/source/lac/scalapack.cc index 4e1e038ffc..b6bbfbb7d8 100644 --- a/source/lac/scalapack.cc +++ b/source/lac/scalapack.cc @@ -278,8 +278,7 @@ ScaLAPACKMatrix::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); } } diff --git a/source/lac/sparsity_tools.cc b/source/lac/sparsity_tools.cc index 0d36b69f9d..164231fc59 100644 --- a/source/lac/sparsity_tools.cc +++ b/source/lac/sparsity_tools.cc @@ -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 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::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 - 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::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::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 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 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); } } diff --git a/source/lac/trilinos_epetra_vector.cc b/source/lac/trilinos_epetra_vector.cc index 52264d727d..cc1857686f 100644 --- a/source/lac/trilinos_epetra_vector.cc +++ b/source/lac/trilinos_epetra_vector.cc @@ -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(vector->Map().MyGlobalElements()); # else size_type *vector_indices = reinterpret_cast(vector->Map().MyGlobalElements64()); diff --git a/source/lac/trilinos_sparse_matrix.cc b/source/lac/trilinos_sparse_matrix.cc index 62b73b1c75..d9787fc126 100644 --- a/source/lac/trilinos_sparse_matrix.cc +++ b/source/lac/trilinos_sparse_matrix.cc @@ -1266,8 +1266,8 @@ namespace TrilinosWrappers SparseMatrix::clear_rows(const std::vector &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); }