From: David Wells Date: Sun, 20 Jan 2019 18:33:10 +0000 (-0500) Subject: Replace &vec[0] with vec.data() or vec.get(). X-Git-Tag: v9.1.0-rc1~418^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F7618%2Fhead;p=dealii.git Replace &vec[0] with vec.data() or vec.get(). This is more explicit and also works correctly when the array is nullptr. --- diff --git a/include/deal.II/base/mpi.h b/include/deal.II/base/mpi.h index 386118ff55..4688b3c17f 100644 --- a/include/deal.II/base/mpi.h +++ b/include/deal.II/base/mpi.h @@ -822,7 +822,7 @@ namespace Utilities // Exchanging the size of each buffer MPI_Allgather( - &n_local_data, 1, MPI_INT, &(size_all_data[0]), 1, MPI_INT, comm); + &n_local_data, 1, MPI_INT, size_all_data.data(), 1, MPI_INT, comm); // Now computing the displacement, relative to recvbuf, // at which to store the incoming buffer diff --git a/include/deal.II/base/mpi.templates.h b/include/deal.II/base/mpi.templates.h index d6628482d1..0887fa8515 100644 --- a/include/deal.II/base/mpi.templates.h +++ b/include/deal.II/base/mpi.templates.h @@ -319,9 +319,9 @@ namespace Utilities #ifdef DEAL_II_WITH_MPI // makes use of the fact that the matrix stores its data in a // contiguous array. - sum(ArrayView(&local.val[0], local.n_nonzero_elements()), + sum(ArrayView(local.val.get(), local.n_nonzero_elements()), mpi_communicator, - ArrayView(&global.val[0], global.n_nonzero_elements())); + ArrayView(global.val.get(), global.n_nonzero_elements())); #else (void)mpi_communicator; if (!PointerComparison::equal(&local, &global)) diff --git a/include/deal.II/differentiation/ad/ad_drivers.h b/include/deal.II/differentiation/ad/ad_drivers.h index 2e0a8a9dc8..05ec558406 100644 --- a/include/deal.II/differentiation/ad/ad_drivers.h +++ b/include/deal.II/differentiation/ad/ad_drivers.h @@ -1064,7 +1064,7 @@ namespace Differentiation ::gradient(active_tape_index, independent_variables.size(), const_cast(independent_variables.data()), - &gradient[0]); + gradient.data()); } static void @@ -1086,7 +1086,7 @@ namespace Differentiation independent_variables.size(); std::vector H(n_independent_variables); for (unsigned int i = 0; i < n_independent_variables; ++i) - H[i] = &(hessian[i][0]); + H[i] = &hessian[i][0]; ::hessian(active_tape_index, n_independent_variables, @@ -1119,7 +1119,7 @@ namespace Differentiation n_dependent_variables, independent_variables.size(), const_cast(independent_variables.data()), - &values[0]); + values.data()); } static void @@ -1141,7 +1141,7 @@ namespace Differentiation std::vector J(n_dependent_variables); for (unsigned int i = 0; i < n_dependent_variables; ++i) - J[i] = &(jacobian[i][0]); + J[i] = &jacobian[i][0]; ::jacobian(active_tape_index, n_dependent_variables, diff --git a/include/deal.II/fe/fe_tools_extrapolate.templates.h b/include/deal.II/fe/fe_tools_extrapolate.templates.h index 6c1f3bd857..f2acc692d7 100644 --- a/include/deal.II/fe/fe_tools_extrapolate.templates.h +++ b/include/deal.II/fe/fe_tools_extrapolate.templates.h @@ -1158,7 +1158,7 @@ namespace FETools destinations.push_back(it->receiver); it->pack_data(*buffer); - const int ierr = MPI_Isend(&(*buffer)[0], + const int ierr = MPI_Isend(buffer->data(), buffer->size(), MPI_BYTE, it->receiver, diff --git a/include/deal.II/grid/grid_tools.h b/include/deal.II/grid/grid_tools.h index c6642584b5..3a89f434b7 100644 --- a/include/deal.II/grid/grid_tools.h +++ b/include/deal.II/grid/grid_tools.h @@ -3367,8 +3367,7 @@ namespace GridTools -> Point { return object->get_manifold().get_new_point( make_array_view(vertices.begin(), vertices.end()), - make_array_view(&weights[0], - &weights[n_vertices_per_cell - 1] + 1)); + make_array_view(weights.begin_raw(), weights.end_raw())); }; // pick the initial weights as (normalized) inverse distances from diff --git a/include/deal.II/lac/affine_constraints.templates.h b/include/deal.II/lac/affine_constraints.templates.h index 631ab78720..19599515f9 100644 --- a/include/deal.II/lac/affine_constraints.templates.h +++ b/include/deal.II/lac/affine_constraints.templates.h @@ -3662,10 +3662,10 @@ AffineConstraints::distribute_local_to_global( // calculate all the data that will be written into the matrix row. if (use_dealii_matrix == false) { - size_type *col_ptr = &cols[0]; + size_type *col_ptr = cols.data(); // cast is uncritical here and only used to avoid compiler // warnings. We never access a non-double array - number *val_ptr = &vals[0]; + number *val_ptr = vals.data(); internals::resolve_matrix_row(global_rows, global_rows, i, @@ -3674,9 +3674,10 @@ AffineConstraints::distribute_local_to_global( local_matrix, col_ptr, val_ptr); - const size_type n_values = col_ptr - &cols[0]; + const size_type n_values = col_ptr - cols.data(); if (n_values > 0) - global_matrix.add(row, n_values, &cols[0], &vals[0], false, true); + global_matrix.add( + row, n_values, cols.data(), vals.data(), false, true); } else internals::resolve_matrix_row( @@ -3816,8 +3817,8 @@ AffineConstraints::distribute_local_to_global( end_block = block_starts[block_col + 1]; if (use_dealii_matrix == false) { - size_type *col_ptr = &cols[0]; - number * val_ptr = &vals[0]; + size_type *col_ptr = cols.data(); + number * val_ptr = vals.data(); internals::resolve_matrix_row(global_rows, global_rows, i, @@ -3826,10 +3827,11 @@ AffineConstraints::distribute_local_to_global( local_matrix, col_ptr, val_ptr); - const size_type n_values = col_ptr - &cols[0]; + const size_type n_values = col_ptr - cols.data(); if (n_values > 0) global_matrix.block(block, block_col) - .add(row, n_values, &cols[0], &vals[0], false, true); + .add( + row, n_values, cols.data(), vals.data(), false, true); } else { @@ -3928,8 +3930,8 @@ AffineConstraints::distribute_local_to_global( const size_type row = global_rows.global_row(i); // calculate all the data that will be written into the matrix row. - size_type *col_ptr = &cols[0]; - number * val_ptr = &vals[0]; + size_type *col_ptr = cols.data(); + number * val_ptr = vals.data(); internals::resolve_matrix_row(global_rows, global_cols, i, @@ -3938,9 +3940,9 @@ AffineConstraints::distribute_local_to_global( local_matrix, col_ptr, val_ptr); - const size_type n_values = col_ptr - &cols[0]; + const size_type n_values = col_ptr - cols.data(); if (n_values > 0) - global_matrix.add(row, n_values, &cols[0], &vals[0], false, true); + global_matrix.add(row, n_values, cols.data(), vals.data(), false, true); } } diff --git a/include/deal.II/lac/block_matrix_base.h b/include/deal.II/lac/block_matrix_base.h index 13c9b4a335..1449657e6b 100644 --- a/include/deal.II/lac/block_matrix_base.h +++ b/include/deal.II/lac/block_matrix_base.h @@ -1809,8 +1809,8 @@ BlockMatrixBase::set(const size_type row, block(row_index.first, block_col) .set(row_index.second, temporary_data.counter_within_block[block_col], - &temporary_data.column_indices[block_col][0], - &temporary_data.column_values[block_col][0], + temporary_data.column_indices[block_col].data(), + temporary_data.column_values[block_col].data(), false); } } @@ -2065,8 +2065,8 @@ BlockMatrixBase::add(const size_type row, block(row_index.first, block_col) .add(row_index.second, temporary_data.counter_within_block[block_col], - &temporary_data.column_indices[block_col][0], - &temporary_data.column_values[block_col][0], + temporary_data.column_indices[block_col].data(), + temporary_data.column_values[block_col].data(), false, col_indices_are_sorted); } diff --git a/include/deal.II/lac/chunk_sparse_matrix.templates.h b/include/deal.II/lac/chunk_sparse_matrix.templates.h index 7ba9fb7815..82acba049c 100644 --- a/include/deal.II/lac/chunk_sparse_matrix.templates.h +++ b/include/deal.II/lac/chunk_sparse_matrix.templates.h @@ -578,7 +578,7 @@ ChunkSparseMatrix::add(const number factor, // add everything, including padding elements const size_type chunk_size = cols->get_chunk_size(); number * val_ptr = val.get(); - const somenumber * matrix_ptr = &matrix.val[0]; + const somenumber * matrix_ptr = matrix.val.get(); const number *const end_ptr = val.get() + cols->sparsity_pattern.n_nonzero_elements() * chunk_size * chunk_size; diff --git a/include/deal.II/lac/full_matrix.templates.h b/include/deal.II/lac/full_matrix.templates.h index 210213f69d..d05222e9b8 100644 --- a/include/deal.II/lac/full_matrix.templates.h +++ b/include/deal.II/lac/full_matrix.templates.h @@ -121,8 +121,8 @@ FullMatrix::all_zero() const { Assert(!this->empty(), ExcEmptyMatrix()); - const number * p = &this->values[0]; - const number *const e = &this->values[0] + this->n_elements(); + const number * p = this->values.data(); + const number *const e = this->values.data() + this->n_elements(); while (p != e) if (*p++ != number(0.0)) return false; @@ -183,7 +183,7 @@ FullMatrix::vmult(Vector & dst, Assert(&src != &dst, ExcSourceEqualsDestination()); - const number *e = &this->values[0]; + const number *e = this->values.data(); // get access to the data in order to // avoid copying it when using the () // operator @@ -214,7 +214,7 @@ FullMatrix::Tvmult(Vector & dst, Assert(&src != &dst, ExcSourceEqualsDestination()); - const number * e = &this->values[0]; + const number * e = this->values.data(); number2 * dst_ptr = &dst(0); const size_type size_m = m(), size_n = n(); @@ -567,7 +567,7 @@ FullMatrix::mmult(FullMatrix & dst, &alpha, &src(0, 0), &m, - &this->values[0], + this->values.data(), &k, &beta, &dst(0, 0), @@ -652,7 +652,7 @@ FullMatrix::Tmmult(FullMatrix & dst, &alpha, &src(0, 0), &m, - &this->values[0], + this->values.data(), &n, &beta, &dst(0, 0), @@ -757,7 +757,7 @@ FullMatrix::mTmult(FullMatrix & dst, &alpha, &src(0, 0), &k, - &this->values[0], + this->values.data(), &k, &beta, &dst(0, 0), @@ -859,7 +859,7 @@ FullMatrix::TmTmult(FullMatrix & dst, &alpha, &src(0, 0), &k, - &this->values[0], + this->values.data(), &n, &beta, &dst(0, 0), @@ -957,7 +957,7 @@ FullMatrix::matrix_norm_square(const Vector &v) const number2 sum = 0.; const size_type n_rows = m(); - const number * val_ptr = &this->values[0]; + const number * val_ptr = this->values.data(); for (size_type row = 0; row < n_rows; ++row) { @@ -988,7 +988,7 @@ FullMatrix::matrix_scalar_product(const Vector &u, number2 sum = 0.; const size_type n_rows = m(); const size_type n_cols = n(); - const number * val_ptr = &this->values[0]; + const number * val_ptr = this->values.data(); for (size_type row = 0; row < n_rows; ++row) { @@ -1859,7 +1859,7 @@ FullMatrix::gauss_jordan() // Use the LAPACK function getrf for // calculating the LU factorization. - getrf(&nn, &nn, &this->values[0], &nn, ipiv.data(), &info); + getrf(&nn, &nn, this->values.data(), &nn, ipiv.data(), &info); Assert(info >= 0, ExcInternalError()); Assert(info == 0, LACExceptions::ExcSingular()); @@ -1870,8 +1870,13 @@ FullMatrix::gauss_jordan() // Use the LAPACK function getri for // calculating the actual inverse using // the LU factorization. - getri( - &nn, &this->values[0], &nn, ipiv.data(), inv_work.data(), &nn, &info); + getri(&nn, + this->values.data(), + &nn, + ipiv.data(), + inv_work.data(), + &nn, + &info); Assert(info >= 0, ExcInternalError()); Assert(info == 0, LACExceptions::ExcSingular()); diff --git a/include/deal.II/lac/petsc_vector_base.h b/include/deal.II/lac/petsc_vector_base.h index 09ad999ca9..39bf477732 100644 --- a/include/deal.II/lac/petsc_vector_base.h +++ b/include/deal.II/lac/petsc_vector_base.h @@ -1132,9 +1132,9 @@ namespace PETScWrappers VectorBase::extract_subvector_to(const std::vector &indices, std::vector & values) const { - extract_subvector_to(&(indices[0]), - &(indices[0]) + indices.size(), - &(values[0])); + Assert(indices.size() <= values.size(), + ExcDimensionMismatch(indices.size(), values.size())); + extract_subvector_to(indices.begin(), indices.end(), values.begin()); } template diff --git a/include/deal.II/lac/sparse_matrix.templates.h b/include/deal.II/lac/sparse_matrix.templates.h index b7414ff150..d4ae0455fb 100644 --- a/include/deal.II/lac/sparse_matrix.templates.h +++ b/include/deal.II/lac/sparse_matrix.templates.h @@ -438,9 +438,9 @@ SparseMatrix::copy_from(const TrilinosWrappers::SparseMatrix &matrix) row, matrix.row_length(row), ncols, - &(value_cache[0]), + value_cache.data(), reinterpret_cast( - &(colnum_cache[0]))); + colnum_cache.data())); (void)ierr; Assert(ierr == 0, ExcTrilinosError(ierr)); @@ -1407,7 +1407,7 @@ SparseMatrix::precondition_Jacobi(Vector & dst, const size_type n = src.size(); somenumber * dst_ptr = dst.begin(); const somenumber * src_ptr = src.begin(); - const std::size_t *rowstart_ptr = &cols->rowstart[0]; + const std::size_t *rowstart_ptr = cols->rowstart.get(); // optimize the following loop for // the case that the relaxation @@ -1452,7 +1452,7 @@ SparseMatrix::precondition_SSOR( internal::SparseMatrixImplementation::AssertNoZerosOnDiagonal(*this); const size_type n = src.size(); - const std::size_t *rowstart_ptr = &cols->rowstart[0]; + const std::size_t *rowstart_ptr = cols->rowstart.get(); somenumber * dst_ptr = &dst(0); // case when we have stored the position @@ -1482,7 +1482,7 @@ SparseMatrix::precondition_SSOR( *dst_ptr /= val[*rowstart_ptr]; } - rowstart_ptr = &cols->rowstart[0]; + rowstart_ptr = cols->rowstart.get(); dst_ptr = &dst(0); for (; rowstart_ptr != &cols->rowstart[n]; ++rowstart_ptr, ++dst_ptr) *dst_ptr *= @@ -1521,10 +1521,10 @@ SparseMatrix::precondition_SSOR( // line denotes the diagonal element, // which we need not check. const size_type first_right_of_diagonal_index = - (Utilities::lower_bound(&cols->colnums[*rowstart_ptr + 1], - &cols->colnums[*(rowstart_ptr + 1)], + (Utilities::lower_bound(cols->colnums.get() + *rowstart_ptr + 1, + cols->colnums.get() + *(rowstart_ptr + 1), row) - - &cols->colnums[0]); + cols->colnums.get()); number s = 0; for (size_type j = (*rowstart_ptr) + 1; j < first_right_of_diagonal_index; @@ -1537,7 +1537,7 @@ SparseMatrix::precondition_SSOR( *dst_ptr /= val[*rowstart_ptr]; }; - rowstart_ptr = &cols->rowstart[0]; + rowstart_ptr = cols->rowstart.get(); dst_ptr = &dst(0); for (size_type row = 0; row < n; ++row, ++rowstart_ptr, ++dst_ptr) *dst_ptr *= somenumber((number(2.) - om)) * somenumber(val[*rowstart_ptr]); @@ -1552,7 +1552,7 @@ SparseMatrix::precondition_SSOR( (Utilities::lower_bound(&cols->colnums[*rowstart_ptr + 1], &cols->colnums[end_row], static_cast(row)) - - &cols->colnums[0]); + cols->colnums.get()); number s = 0; for (size_type j = first_right_of_diagonal_index; j < end_row; ++j) s += val[j] * number(dst(cols->colnums[j])); diff --git a/include/deal.II/lac/tensor_product_matrix.h b/include/deal.II/lac/tensor_product_matrix.h index 53fcb039f1..6b5d94274c 100644 --- a/include/deal.II/lac/tensor_product_matrix.h +++ b/include/deal.II/lac/tensor_product_matrix.h @@ -494,7 +494,7 @@ TensorProductMatrixSymmetricSumBase::vmult( mass_matrix[0].n_rows()); Number * t = tmp_array.begin(); const Number *src = src_view.begin(); - Number * dst = &(dst_view[0]); + Number * dst = dst_view.data(); if (dim == 1) { @@ -561,7 +561,7 @@ TensorProductMatrixSymmetricSumBase::apply_inverse( mass_matrix[0].n_rows()); Number * t = tmp_array.begin(); const Number *src = src_view.data(); - Number * dst = &(dst_view[0]); + Number * dst = dst_view.data(); // NOTE: dof_to_quad has to be interpreted as 'dof to eigenvalue index' // --> apply<.,true,.> (S,src,dst) calculates dst = S^T * src, diff --git a/include/deal.II/matrix_free/cuda_matrix_free.templates.h b/include/deal.II/matrix_free/cuda_matrix_free.templates.h index ae7f7666a7..86da100138 100644 --- a/include/deal.II/matrix_free/cuda_matrix_free.templates.h +++ b/include/deal.II/matrix_free/cuda_matrix_free.templates.h @@ -839,7 +839,7 @@ namespace CUDAWrappers unsigned int size_shape_values = n_dofs_1d * n_q_points_1d * sizeof(Number); cudaError_t cuda_error = cudaMemcpyToSymbol(internal::global_shape_values, - &shape_info.shape_values[0], + shape_info.shape_values.data(), size_shape_values, 0, cudaMemcpyHostToDevice); @@ -848,7 +848,7 @@ namespace CUDAWrappers if (update_flags & update_gradients) { cuda_error = cudaMemcpyToSymbol(internal::global_shape_gradients, - &shape_info.shape_gradients[0], + shape_info.shape_gradients.data(), size_shape_values, 0, cudaMemcpyHostToDevice); diff --git a/include/deal.II/matrix_free/matrix_free.templates.h b/include/deal.II/matrix_free/matrix_free.templates.h index d790a74b8c..0aedc2af2d 100644 --- a/include/deal.II/matrix_free/matrix_free.templates.h +++ b/include/deal.II/matrix_free/matrix_free.templates.h @@ -95,15 +95,15 @@ MatrixFree::create_cell_subrange_hp_by_index( AssertIndexRange(range.second, fe_indices.size() + 1); #endif std::pair return_range; - return_range.first = std::lower_bound(&fe_indices[0] + range.first, - &fe_indices[0] + range.second, + return_range.first = std::lower_bound(fe_indices.begin() + range.first, + fe_indices.begin() + range.second, fe_index) - - &fe_indices[0]; + fe_indices.begin(); return_range.second = - std::lower_bound(&fe_indices[0] + return_range.first, - &fe_indices[0] + range.second, + std::lower_bound(fe_indices.begin() + return_range.first, + fe_indices.begin() + range.second, fe_index + 1) - - &fe_indices[0]; + fe_indices.begin(); Assert(return_range.first >= range.first && return_range.second <= range.second, ExcInternalError()); diff --git a/include/deal.II/matrix_free/operators.h b/include/deal.II/matrix_free/operators.h index eb35e1ebe9..3d5e13ef9f 100644 --- a/include/deal.II/matrix_free/operators.h +++ b/include/deal.II/matrix_free/operators.h @@ -998,8 +998,9 @@ namespace MatrixFreeOperators const unsigned int shift_coefficient = inverse_coefficients.size() > dofs_per_component ? dofs_per_component : 0; - const VectorizedArray *inv_coefficient = &inverse_coefficients[0]; - VectorizedArray temp_data_field[dofs_per_component]; + const VectorizedArray *inv_coefficient = + inverse_coefficients.data(); + VectorizedArray temp_data_field[dofs_per_component]; for (unsigned int d = 0; d < n_actual_components; ++d) { const VectorizedArray *in = in_array + d * dofs_per_component; diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 0f102ac265..9983825260 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -556,7 +556,7 @@ namespace DataOutBase const double * DataOutFilter::get_data_set(const unsigned int set_num) const { - return &data_sets[set_num][0]; + return data_sets[set_num].data(); } @@ -5110,11 +5110,11 @@ namespace DataOutBase int total = (vars_per_node * num_nodes); - ierr = TECDAT(&total, &tm.nodalData[0], &is_double); + ierr = TECDAT(&total, tm.nodalData.data(), &is_double); Assert(ierr == 0, ExcTecplotAPIError()); - ierr = TECNOD(&tm.connData[0]); + ierr = TECNOD(tm.connData.data()); Assert(ierr == 0, ExcTecplotAPIError()); diff --git a/source/base/mpi.cc b/source/base/mpi.cc index d3b1746352..c9833733b1 100644 --- a/source/base/mpi.cc +++ b/source/base/mpi.cc @@ -209,7 +209,7 @@ namespace Utilities // results over all processes unsigned int n_recv_from; const int ierr = MPI_Reduce_scatter_block( - &dest_vector[0], &n_recv_from, 1, MPI_UNSIGNED, MPI_SUM, mpi_comm); + dest_vector.data(), &n_recv_from, 1, MPI_UNSIGNED, MPI_SUM, mpi_comm); AssertThrowMPI(ierr); @@ -222,7 +222,7 @@ namespace Utilities el, 32766, mpi_comm, - &send_requests[&el - &destinations[0]]); + send_requests.data() + (&el - destinations.data())); // if no one to receive from, return an empty vector if (n_recv_from == 0) @@ -322,7 +322,7 @@ namespace Utilities unsigned int n_recv_from = 0; const int ierr = MPI_Reduce_scatter_block( - &dest_vector[0], &n_recv_from, 1, MPI_UNSIGNED, MPI_SUM, mpi_comm); + dest_vector.data(), &n_recv_from, 1, MPI_UNSIGNED, MPI_SUM, mpi_comm); AssertThrowMPI(ierr); @@ -334,14 +334,14 @@ namespace Utilities std::vector buffer(dest_vector.size()); unsigned int n_recv_from = 0; - MPI_Reduce(&dest_vector[0], - &buffer[0], + MPI_Reduce(dest_vector.data(), + buffer.data(), dest_vector.size(), MPI_UNSIGNED, MPI_SUM, 0, mpi_comm); - MPI_Scatter(&buffer[0], + MPI_Scatter(buffer.data(), 1, MPI_UNSIGNED, &n_recv_from, diff --git a/source/base/tensor_product_polynomials.cc b/source/base/tensor_product_polynomials.cc index edeccc3078..26fdd11ab3 100644 --- a/source/base/tensor_product_polynomials.cc +++ b/source/base/tensor_product_polynomials.cc @@ -301,7 +301,7 @@ TensorProductPolynomials::compute( for (unsigned d = 0; d < dim; ++d) polynomials[i].value(p(d), n_values_and_derivatives, - &values_1d[i][d][0]); + values_1d[i][d].data()); unsigned int indices[3]; unsigned int ind = 0; diff --git a/source/distributed/tria.cc b/source/distributed/tria.cc index 2a15c791dd..99068c23da 100644 --- a/source/distributed/tria.cc +++ b/source/distributed/tria.cc @@ -4242,7 +4242,7 @@ namespace parallel // that the packet has been // received it->second.pack_data(*buffer); - const int ierr = MPI_Isend(&(*buffer)[0], + const int ierr = MPI_Isend(buffer->data(), buffer->size(), MPI_BYTE, it->first, diff --git a/source/dofs/dof_handler_policy.cc b/source/dofs/dof_handler_policy.cc index ab9a3f2336..bdb9b68d53 100644 --- a/source/dofs/dof_handler_policy.cc +++ b/source/dofs/dof_handler_policy.cc @@ -4655,7 +4655,7 @@ namespace internal // send reply reply_buffers[idx] = cell_data_transfer_buffer.pack_data(); - ierr = MPI_Isend(&(reply_buffers[idx])[0], + ierr = MPI_Isend(reply_buffers[idx].data(), reply_buffers[idx].size(), MPI_BYTE, status.MPI_SOURCE, @@ -5381,7 +5381,7 @@ namespace internal &level_number_cache.n_locally_owned_dofs, 1, DEAL_II_DOF_INDEX_MPI_TYPE, - &level_number_cache.n_locally_owned_dofs_per_processor[0], + level_number_cache.n_locally_owned_dofs_per_processor.data(), 1, DEAL_II_DOF_INDEX_MPI_TYPE, triangulation->get_communicator()); diff --git a/source/fe/mapping_q_generic.cc b/source/fe/mapping_q_generic.cc index 2e54c13746..44400569dd 100644 --- a/source/fe/mapping_q_generic.cc +++ b/source/fe/mapping_q_generic.cc @@ -1737,7 +1737,7 @@ namespace internal Assert(data.n_shape_functions > 0, ExcInternalError()); const Tensor<1, spacedim> *supp_pts = - &data.mapping_support_points[0]; + data.mapping_support_points.data(); for (unsigned int point = 0; point < n_q_points; ++point) { diff --git a/source/grid/cell_id.cc b/source/grid/cell_id.cc index 7941bccaf9..7505dcd94a 100644 --- a/source/grid/cell_id.cc +++ b/source/grid/cell_id.cc @@ -53,7 +53,7 @@ CellId::CellId(const unsigned int coarse_cell_id, , n_child_indices(n_child_indices) { Assert(n_child_indices < child_indices.size(), ExcInternalError()); - memcpy(&(child_indices[0]), id, n_child_indices); + memcpy(child_indices.data(), id, n_child_indices); } diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index d5d2aefa24..c00da14881 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -2103,9 +2103,9 @@ GridIn<2>::read_netcdf(const std::string &filename) ExcIO()); std::vector> point_values( 3, std::vector(n_vertices)); - points_xc->get(&*point_values[0].begin(), n_vertices); - points_yc->get(&*point_values[1].begin(), n_vertices); - points_zc->get(&*point_values[2].begin(), n_vertices); + points_xc->get(point_values[0].data(), n_vertices); + points_yc->get(point_values[1].data(), n_vertices); + points_zc->get(point_values[2].data(), n_vertices); // and fill the vertices std::vector> vertices(n_vertices); @@ -2265,9 +2265,9 @@ GridIn<3>::read_netcdf(const std::string &filename) ExcIO()); std::vector> point_values( 3, std::vector(n_vertices)); - points_xc->get(&*point_values[0].begin(), n_vertices); - points_yc->get(&*point_values[1].begin(), n_vertices); - points_zc->get(&*point_values[2].begin(), n_vertices); + points_xc->get(point_values[0].data(), n_vertices); + points_yc->get(point_values[1].data(), n_vertices); + points_zc->get(point_values[2].data(), n_vertices); // and fill the vertices std::vector> vertices(n_vertices); diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index e5e354ee88..2b50ee5f40 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -2364,7 +2364,7 @@ namespace GridTools } // Send the message - ierr = MPI_Isend(&vertices_send_buffers[i][0], + ierr = MPI_Isend(vertices_send_buffers[i].data(), buffer_size, DEAL_II_VERTEX_INDEX_MPI_TYPE, destination, @@ -2389,7 +2389,7 @@ namespace GridTools vertices_recv_buffers[i].resize(buffer_size); // Receive the message - ierr = MPI_Recv(&vertices_recv_buffers[i][0], + ierr = MPI_Recv(vertices_recv_buffers[i].data(), buffer_size, DEAL_II_VERTEX_INDEX_MPI_TYPE, source, @@ -2430,7 +2430,7 @@ namespace GridTools } // Send the message - ierr = MPI_Isend(&cellids_send_buffers[i][0], + ierr = MPI_Isend(cellids_send_buffers[i].data(), buffer_size, MPI_CHAR, destination, @@ -2453,7 +2453,7 @@ namespace GridTools cellids_recv_buffers[i].resize(buffer_size); // Receive the message - ierr = MPI_Recv(&cellids_recv_buffers[i][0], + ierr = MPI_Recv(cellids_recv_buffers[i].data(), buffer_size, MPI_CHAR, source, @@ -5029,7 +5029,7 @@ namespace GridTools int ierr = MPI_Allgather(&n_local_data, 1, MPI_INT, - &(size_all_data[0]), + size_all_data.data(), 1, MPI_INT, mpi_communicator); @@ -5046,12 +5046,12 @@ namespace GridTools // Allocating a vector to contain all the received data std::vector data_array(rdispls.back() + size_all_data.back()); - ierr = MPI_Allgatherv(&(loc_data_array[0]), + ierr = MPI_Allgatherv(loc_data_array.data(), n_local_data, MPI_DOUBLE, - &(data_array[0]), - &(size_all_data[0]), - &(rdispls[0]), + data_array.data(), + size_all_data.data(), + rdispls.data(), MPI_DOUBLE, mpi_communicator); AssertThrowMPI(ierr); diff --git a/source/grid/tria_accessor.cc b/source/grid/tria_accessor.cc index a30c106eb1..4e62fde8de 100644 --- a/source/grid/tria_accessor.cc +++ b/source/grid/tria_accessor.cc @@ -2218,7 +2218,7 @@ CellAccessor::id() const Assert(ptr.level() == 0, ExcInternalError()); const unsigned int coarse_index = ptr.index(); - return CellId(coarse_index, n_child_indices, &(id[0])); + return CellId(coarse_index, n_child_indices, id.data()); } diff --git a/source/lac/cuda_sparse_matrix.cu b/source/lac/cuda_sparse_matrix.cu index 07b5cae625..6756e9d97d 100644 --- a/source/lac/cuda_sparse_matrix.cu +++ b/source/lac/cuda_sparse_matrix.cu @@ -298,7 +298,7 @@ namespace CUDAWrappers // Copy the elements to the gpu val_dev.reset(Utilities::CUDA::allocate_device_data(nnz)); cudaError_t error_code = cudaMemcpy(val_dev.get(), - &val[0], + val.data(), nnz * sizeof(Number), cudaMemcpyHostToDevice); AssertCuda(error_code); @@ -307,7 +307,7 @@ namespace CUDAWrappers column_index_dev.reset(Utilities::CUDA::allocate_device_data(nnz)); AssertCuda(error_code); error_code = cudaMemcpy(column_index_dev.get(), - &column_index[0], + column_index.data(), nnz * sizeof(int), cudaMemcpyHostToDevice); AssertCuda(error_code); @@ -316,7 +316,7 @@ namespace CUDAWrappers row_ptr_dev.reset(Utilities::CUDA::allocate_device_data(row_ptr_size)); AssertCuda(error_code); error_code = cudaMemcpy(row_ptr_dev.get(), - &row_ptr[0], + row_ptr.data(), row_ptr_size * sizeof(int), cudaMemcpyHostToDevice); AssertCuda(error_code); diff --git a/source/lac/lapack_full_matrix.cc b/source/lac/lapack_full_matrix.cc index 9058de9a87..80d53bcc7f 100644 --- a/source/lac/lapack_full_matrix.cc +++ b/source/lac/lapack_full_matrix.cc @@ -82,7 +82,7 @@ namespace internal geev(&vl, &vr, &n_rows, - &matrix[0], + matrix.data(), &n_rows, real_part_eigenvalues.data(), imag_part_eigenvalues.data(), @@ -134,7 +134,7 @@ namespace internal geev(&vl, &vr, &n_rows, - &matrix[0], + matrix.data(), &n_rows, eigenvalues.data(), left_eigenvectors.data(), @@ -178,12 +178,12 @@ namespace internal gesdd(&job, &n_rows, &n_cols, - &matrix[0], + matrix.data(), &n_rows, singular_values.data(), - &left_vectors[0], + left_vectors.data(), &n_rows, - &right_vectors[0], + right_vectors.data(), &n_cols, real_work.data(), &work_flag, @@ -224,12 +224,12 @@ namespace internal gesdd(&job, &n_rows, &n_cols, - &matrix[0], + matrix.data(), &n_rows, singular_values.data(), - &left_vectors[0], + left_vectors.data(), &n_rows, - &right_vectors[0], + right_vectors.data(), &n_cols, work.data(), &work_flag, @@ -436,7 +436,7 @@ LAPACKFullMatrix::operator*=(const number factor) types::blas_int info = 0; // kl and ku will not be referenced for type = G (dense matrices). const types::blas_int kl = 0; - number * values = &this->values[0]; + number * values = this->values.data(); lascl(&type, &kl, &kl, &cfrom, &factor, &m, &n, values, &lda, &info); @@ -466,7 +466,7 @@ LAPACKFullMatrix::operator/=(const number factor) types::blas_int info = 0; // kl and ku will not be referenced for type = G (dense matrices). const types::blas_int kl = 0; - number * values = &this->values[0]; + number * values = this->values.data(); lascl(&type, &kl, &kl, &factor, &cto, &m, &n, values, &lda, &info); @@ -496,8 +496,8 @@ LAPACKFullMatrix::add(const number a, const LAPACKFullMatrix &A) // ==> use BLAS 1 for adding vectors const types::blas_int n = this->m() * this->n(); const types::blas_int inc = 1; - number * values = &this->values[0]; - const number * values_A = &A.values[0]; + number * values = this->values.data(); + const number * values_A = A.values.data(); axpy(&n, &a, values_A, &inc, values, &inc); } @@ -677,7 +677,8 @@ LAPACKFullMatrix::vmult(Vector & w, const types::blas_int lda = N; const types::blas_int incx = 1; - trmv(&uplo, &trans, &diag, &N, &this->values[0], &lda, &w[0], &incx); + trmv( + &uplo, &trans, &diag, &N, this->values.data(), &lda, w.data(), &incx); return; } @@ -694,12 +695,12 @@ LAPACKFullMatrix::vmult(Vector & w, &mm, &nn, &alpha, - &this->values[0], + this->values.data(), &mm, - v.values.get(), + v.data(), &one, &beta, - w.values.get(), + w.data(), &one); break; } @@ -714,9 +715,9 @@ LAPACKFullMatrix::vmult(Vector & w, &nn, &nn, &alpha, - &svd_vt->values[0], + svd_vt->values.data(), &nn, - v.values.get(), + v.data(), &one, &null, work.data(), @@ -729,12 +730,12 @@ LAPACKFullMatrix::vmult(Vector & w, &mm, &mm, &alpha, - &svd_u->values[0], + svd_u->values.data(), &mm, work.data(), &one, &beta, - w.values.get(), + w.data(), &one); break; } @@ -749,9 +750,9 @@ LAPACKFullMatrix::vmult(Vector & w, &mm, &mm, &alpha, - &svd_u->values[0], + svd_u->values.data(), &mm, - v.values.get(), + v.data(), &one, &null, work.data(), @@ -764,12 +765,12 @@ LAPACKFullMatrix::vmult(Vector & w, &nn, &nn, &alpha, - &svd_vt->values[0], + svd_vt->values.data(), &nn, work.data(), &one, &beta, - w.values.get(), + w.data(), &one); break; } @@ -811,7 +812,8 @@ LAPACKFullMatrix::Tvmult(Vector & w, const types::blas_int lda = N; const types::blas_int incx = 1; - trmv(&uplo, &trans, &diag, &N, &this->values[0], &lda, &w[0], &incx); + trmv( + &uplo, &trans, &diag, &N, this->values.data(), &lda, w.data(), &incx); return; } @@ -829,12 +831,12 @@ LAPACKFullMatrix::Tvmult(Vector & w, &mm, &nn, &alpha, - &this->values[0], + this->values.data(), &mm, - v.values.get(), + v.data(), &one, &beta, - w.values.get(), + w.data(), &one); break; } @@ -850,9 +852,9 @@ LAPACKFullMatrix::Tvmult(Vector & w, &mm, &mm, &alpha, - &svd_u->values[0], + svd_u->values.data(), &mm, - v.values.get(), + v.data(), &one, &null, work.data(), @@ -865,12 +867,12 @@ LAPACKFullMatrix::Tvmult(Vector & w, &nn, &nn, &alpha, - &svd_vt->values[0], + svd_vt->values.data(), &nn, work.data(), &one, &beta, - w.values.get(), + w.data(), &one); break; } @@ -886,9 +888,9 @@ LAPACKFullMatrix::Tvmult(Vector & w, &nn, &nn, &alpha, - &svd_vt->values[0], + svd_vt->values.data(), &nn, - v.values.get(), + v.data(), &one, &null, work.data(), @@ -901,12 +903,12 @@ LAPACKFullMatrix::Tvmult(Vector & w, &mm, &mm, &alpha, - &svd_u->values[0], + svd_u->values.data(), &mm, work.data(), &one, &beta, - w.values.get(), + w.data(), &one); break; } @@ -958,12 +960,12 @@ LAPACKFullMatrix::mmult(LAPACKFullMatrix & C, &nn, &kk, &alpha, - &this->values[0], + this->values.data(), &mm, - &B.values[0], + B.values.data(), &kk, &beta, - &C.values[0], + C.values.data(), &mm); } @@ -993,9 +995,9 @@ LAPACKFullMatrix::mmult(FullMatrix & C, &mm, &kk, &alpha, - &B.values[0], + B.values.data(), &kk, - &this->values[0], + this->values.data(), &mm, &beta, &C(0, 0), @@ -1055,12 +1057,12 @@ LAPACKFullMatrix::Tmmult(LAPACKFullMatrix & C, &nn, &kk, &alpha, - &this->values[0], + this->values.data(), &kk, - &work[0], + work.data(), &kk, &beta, - &C.values[0], + C.values.data(), &mm); } @@ -1077,7 +1079,7 @@ LAPACKFullMatrix::transpose(LAPACKFullMatrix &B) const const types::blas_int n = B.n(); #ifdef DEAL_II_LAPACK_WITH_MKL const number one = 1.; - omatcopy('C', 'C', n, m, one, &A.values[0], n, &B.values[0], m); + omatcopy('C', 'C', n, m, one, A.values.data(), n, B.values.data(), m); #else for (types::blas_int i = 0; i < m; ++i) for (types::blas_int j = 0; j < n; ++j) @@ -1128,10 +1130,10 @@ LAPACKFullMatrix::Tmmult(LAPACKFullMatrix & C, &nn, &kk, &alpha, - &this->values[0], + this->values.data(), &kk, &beta, - &C.values[0], + C.values.data(), &nn); // fill-in lower triangular part @@ -1149,12 +1151,12 @@ LAPACKFullMatrix::Tmmult(LAPACKFullMatrix & C, &nn, &kk, &alpha, - &this->values[0], + this->values.data(), &kk, - &B.values[0], + B.values.data(), &kk, &beta, - &C.values[0], + C.values.data(), &mm); } } @@ -1185,9 +1187,9 @@ LAPACKFullMatrix::Tmmult(FullMatrix & C, &mm, &kk, &alpha, - &B.values[0], + B.values.data(), &kk, - &this->values[0], + this->values.data(), &kk, &beta, &C(0, 0), @@ -1220,10 +1222,10 @@ LAPACKFullMatrix::mTmult(LAPACKFullMatrix & C, &nn, &kk, &alpha, - &this->values[0], + this->values.data(), &nn, &beta, - &C.values[0], + C.values.data(), &nn); // fill-in lower triangular part @@ -1241,12 +1243,12 @@ LAPACKFullMatrix::mTmult(LAPACKFullMatrix & C, &nn, &kk, &alpha, - &this->values[0], + this->values.data(), &mm, - &B.values[0], + B.values.data(), &nn, &beta, - &C.values[0], + C.values.data(), &mm); } } @@ -1278,9 +1280,9 @@ LAPACKFullMatrix::mTmult(FullMatrix & C, &mm, &kk, &alpha, - &B.values[0], + B.values.data(), &nn, - &this->values[0], + this->values.data(), &mm, &beta, &C(0, 0), @@ -1312,12 +1314,12 @@ LAPACKFullMatrix::TmTmult(LAPACKFullMatrix & C, &nn, &kk, &alpha, - &this->values[0], + this->values.data(), &kk, - &B.values[0], + B.values.data(), &nn, &beta, - &C.values[0], + C.values.data(), &mm); } @@ -1347,9 +1349,9 @@ LAPACKFullMatrix::TmTmult(FullMatrix & C, &mm, &kk, &alpha, - &B.values[0], + B.values.data(), &nn, - &this->values[0], + this->values.data(), &kk, &beta, &C(0, 0), @@ -1366,7 +1368,7 @@ LAPACKFullMatrix::compute_lu_factorization() const types::blas_int mm = this->m(); const types::blas_int nn = this->n(); - number *const values = &this->values[0]; + number *const values = this->values.data(); ipiv.resize(mm); types::blas_int info = 0; getrf(&mm, &nn, values, &mm, ipiv.data(), &info); @@ -1432,7 +1434,7 @@ LAPACKFullMatrix::norm(const char type) const const types::blas_int N = this->n(); const types::blas_int M = this->m(); - const number *const values = &this->values[0]; + const number *const values = this->values.data(); if (property == symmetric) { const types::blas_int lda = std::max(1, N); @@ -1484,7 +1486,7 @@ LAPACKFullMatrix::compute_cholesky_factorization() (void)mm; Assert(mm == nn, ExcDimensionMismatch(mm, nn)); - number *const values = &this->values[0]; + number *const values = this->values.data(); types::blas_int info = 0; const types::blas_int lda = std::max(1, nn); potrf(&LAPACKSupport::L, &nn, values, &lda, &info); @@ -1507,7 +1509,7 @@ LAPACKFullMatrix::reciprocal_condition_number(const number a_norm) const number rcond = 0.; const types::blas_int N = this->m(); - const number * values = &this->values[0]; + const number * values = this->values.data(); types::blas_int info = 0; const types::blas_int lda = std::max(1, N); work.resize(3 * N); @@ -1541,7 +1543,7 @@ LAPACKFullMatrix::reciprocal_condition_number() const number rcond = 0.; const types::blas_int N = this->m(); - const number *const values = &this->values[0]; + const number *const values = this->values.data(); types::blas_int info = 0; const types::blas_int lda = std::max(1, N); work.resize(3 * N); @@ -1698,7 +1700,7 @@ LAPACKFullMatrix::invert() const types::blas_int nn = this->n(); Assert(nn == mm, ExcNotQuadratic()); - number *const values = &this->values[0]; + number *const values = this->values.data(); types::blas_int info = 0; if (property != symmetric) @@ -1740,7 +1742,7 @@ LAPACKFullMatrix::solve(Vector &v, const bool transposed) const AssertDimension(this->m(), v.size()); const char * trans = transposed ? &T : &N; const types::blas_int nn = this->n(); - const number *const values = &this->values[0]; + const number *const values = this->values.data(); const types::blas_int n_rhs = 1; types::blas_int info = 0; @@ -1786,19 +1788,32 @@ LAPACKFullMatrix::solve(LAPACKFullMatrix &B, AssertDimension(this->m(), B.m()); const char * trans = transposed ? &T : &N; const types::blas_int nn = this->n(); - const number *const values = &this->values[0]; + const number *const values = this->values.data(); const types::blas_int n_rhs = B.n(); types::blas_int info = 0; if (state == lu) { - getrs( - trans, &nn, &n_rhs, values, &nn, ipiv.data(), &B.values[0], &nn, &info); + getrs(trans, + &nn, + &n_rhs, + values, + &nn, + ipiv.data(), + B.values.data(), + &nn, + &info); } else if (state == cholesky) { - potrs( - &LAPACKSupport::L, &nn, &n_rhs, values, &nn, &B.values[0], &nn, &info); + potrs(&LAPACKSupport::L, + &nn, + &n_rhs, + values, + &nn, + B.values.data(), + &nn, + &info); } else if (property == upper_triangular || property == lower_triangular) { @@ -1814,7 +1829,7 @@ LAPACKFullMatrix::solve(LAPACKFullMatrix &B, &n_rhs, values, &lda, - &B.values[0], + B.values.data(), &ldb, &info); } @@ -1977,8 +1992,8 @@ LAPACKFullMatrix::compute_eigenvalues_symmetric( wr.resize(nn); LAPACKFullMatrix matrix_eigenvectors(nn, nn); - number *const values_A = &this->values[0]; - number *const values_eigenvectors = &matrix_eigenvectors.values[0]; + number *const values_A = this->values.data(); + number *const values_eigenvectors = matrix_eigenvectors.values.data(); types::blas_int info(0), lwork(-1), n_eigenpairs(0); const char *const jobz(&V); @@ -2092,9 +2107,9 @@ LAPACKFullMatrix::compute_generalized_eigenvalues_symmetric( wr.resize(nn); LAPACKFullMatrix matrix_eigenvectors(nn, nn); - number *const values_A = &this->values[0]; - number *const values_B = &B.values[0]; - number *const values_eigenvectors = &matrix_eigenvectors.values[0]; + number *const values_A = this->values.data(); + number *const values_B = B.values.data(); + number *const values_eigenvectors = matrix_eigenvectors.values.data(); types::blas_int info(0), lwork(-1), n_eigenpairs(0); const char *const jobz(&V); @@ -2216,8 +2231,8 @@ LAPACKFullMatrix::compute_generalized_eigenvalues_symmetric( wi.resize(nn); // This is set purely for consistency reasons with the // eigenvalues() function. - number *const values_A = &this->values[0]; - number *const values_B = &B.values[0]; + number *const values_A = this->values.data(); + number *const values_B = B.values.data(); types::blas_int info = 0; types::blas_int lwork = -1; diff --git a/source/lac/petsc_parallel_sparse_matrix.cc b/source/lac/petsc_parallel_sparse_matrix.cc index 4b528a1cd0..08db8963ac 100644 --- a/source/lac/petsc_parallel_sparse_matrix.cc +++ b/source/lac/petsc_parallel_sparse_matrix.cc @@ -456,7 +456,7 @@ namespace PETScWrappers // now copy over the information // from the sparsity pattern. { - PetscInt *ptr = &colnums_in_window[0]; + PetscInt *ptr = colnums_in_window.data(); for (PetscInt i = local_row_start; i < local_row_end; ++i) for (typename SparsityPatternType::iterator p = sparsity_pattern.begin(i); @@ -583,7 +583,7 @@ namespace PETScWrappers // now copy over the information // from the sparsity pattern. { - PetscInt *ptr = &colnums_in_window[0]; + PetscInt *ptr = colnums_in_window.data(); for (size_type i = local_row_start; i < local_row_end; ++i) for (typename SparsityPatternType::iterator p = sparsity_pattern.begin(i); diff --git a/source/lac/petsc_parallel_vector.cc b/source/lac/petsc_parallel_vector.cc index 2f33532dba..f0a12353b2 100644 --- a/source/lac/petsc_parallel_vector.cc +++ b/source/lac/petsc_parallel_vector.cc @@ -267,7 +267,7 @@ namespace PETScWrappers const PetscInt *ptr = (ghostindices.size() > 0 ? - reinterpret_cast(&(ghostindices[0])) : + reinterpret_cast(ghostindices.data()) : nullptr); PetscErrorCode ierr = VecCreateGhost(communicator, diff --git a/source/lac/scalapack.cc b/source/lac/scalapack.cc index b6bbfbb7d8..9a5f1bb157 100644 --- a/source/lac/scalapack.cc +++ b/source/lac/scalapack.cc @@ -457,7 +457,7 @@ ScaLAPACKMatrix::copy_from(const LAPACKFullMatrix &B, { const int ii = 1; NumberType *loc_vals_A = - this->values.size() > 0 ? &(this->values[0]) : nullptr; + this->values.size() > 0 ? this->values.data() : nullptr; const NumberType *loc_vals_B = mpi_process_is_active_B ? &(B(0, 0)) : nullptr; @@ -628,7 +628,7 @@ ScaLAPACKMatrix::copy_to(LAPACKFullMatrix &B, { const int ii = 1; const NumberType *loc_vals_A = - this->values.size() > 0 ? &(this->values[0]) : nullptr; + this->values.size() > 0 ? this->values.data() : nullptr; NumberType *loc_vals_B = mpi_process_is_active_B ? &(B(0, 0)) : nullptr; pgemr2d(&n_rows, @@ -801,7 +801,7 @@ ScaLAPACKMatrix::copy_to( if (in_context_A) { if (this->values.size() != 0) - loc_vals_A = &this->values[0]; + loc_vals_A = this->values.data(); for (unsigned int i = 0; i < desc_A.size(); ++i) desc_A[i] = this->descriptor[i]; @@ -812,7 +812,7 @@ ScaLAPACKMatrix::copy_to( if (in_context_B) { if (B.values.size() != 0) - loc_vals_B = &B.values[0]; + loc_vals_B = B.values.data(); for (unsigned int i = 0; i < desc_B.size(); ++i) desc_B[i] = B.descriptor[i]; @@ -922,7 +922,7 @@ ScaLAPACKMatrix::copy_to(ScaLAPACKMatrix &dest) const AssertThrow(this->values.size() > 0, dealii::ExcMessage( "source: process is active but local matrix empty")); - loc_vals_source = &this->values[0]; + loc_vals_source = this->values.data(); } if (dest.grid->mpi_process_is_active && (dest.values.size() > 0)) { @@ -930,7 +930,7 @@ ScaLAPACKMatrix::copy_to(ScaLAPACKMatrix &dest) const dest.values.size() > 0, dealii::ExcMessage( "destination: process is active but local matrix empty")); - loc_vals_dest = &dest.values[0]; + loc_vals_dest = dest.values.data(); } pgemr2d(&n_rows, &n_columns, @@ -1012,8 +1012,9 @@ ScaLAPACKMatrix::add(const ScaLAPACKMatrix &B, { char trans_b = transpose_B ? 'T' : 'N'; NumberType *A_loc = - (this->values.size() > 0) ? &this->values[0] : nullptr; - const NumberType *B_loc = (B.values.size() > 0) ? &B.values[0] : nullptr; + (this->values.size() > 0) ? this->values.data() : nullptr; + const NumberType *B_loc = + (B.values.size() > 0) ? B.values.data() : nullptr; pgeadd(&trans_b, &n_rows, @@ -1138,10 +1139,10 @@ ScaLAPACKMatrix::mult(const NumberType b, char trans_b = transpose_B ? 'T' : 'N'; const NumberType *A_loc = - (this->values.size() > 0) ? (&(this->values[0])) : nullptr; + (this->values.size() > 0) ? this->values.data() : nullptr; const NumberType *B_loc = - (B.values.size() > 0) ? (&(B.values[0])) : nullptr; - NumberType *C_loc = (C.values.size() > 0) ? (&(C.values[0])) : nullptr; + (B.values.size() > 0) ? B.values.data() : nullptr; + NumberType *C_loc = (C.values.size() > 0) ? C.values.data() : nullptr; int m = C.n_rows; int n = C.n_columns; int k = transpose_A ? this->n_rows : this->n_columns; @@ -1242,7 +1243,7 @@ ScaLAPACKMatrix::compute_cholesky_factorization() if (grid->mpi_process_is_active) { int info = 0; - NumberType *A_loc = &this->values[0]; + NumberType *A_loc = this->values.data(); // pdpotrf_(&uplo,&n_columns,A_loc,&submatrix_row,&submatrix_column,descriptor,&info); ppotrf(&uplo, &n_columns, @@ -1271,7 +1272,7 @@ ScaLAPACKMatrix::compute_lu_factorization() if (grid->mpi_process_is_active) { int info = 0; - NumberType *A_loc = &this->values[0]; + NumberType *A_loc = this->values.data(); const int iarow = indxg2p_(&submatrix_row, &row_block_size, @@ -1325,7 +1326,7 @@ ScaLAPACKMatrix::invert() property == LAPACKSupport::upper_triangular ? 'U' : 'L'; const char diag = 'N'; int info = 0; - NumberType *A_loc = &this->values[0]; + NumberType *A_loc = this->values.data(); ptrtri(&uploTriangular, &diag, &n_columns, @@ -1355,7 +1356,7 @@ ScaLAPACKMatrix::invert() if (grid->mpi_process_is_active) { int info = 0; - NumberType *A_loc = &this->values[0]; + NumberType *A_loc = this->values.data(); if (is_symmetric) { @@ -1575,7 +1576,7 @@ ScaLAPACKMatrix::eigenpairs_symmetric( il = std::min(eigenvalue_idx.first, eigenvalue_idx.second) + 1; iu = std::max(eigenvalue_idx.first, eigenvalue_idx.second) + 1; } - NumberType *A_loc = &this->values[0]; + NumberType *A_loc = this->values.data(); /* * by setting lwork to -1 a workspace query for optimal length of work is * performed @@ -1583,7 +1584,7 @@ ScaLAPACKMatrix::eigenpairs_symmetric( int lwork = -1; int liwork = -1; NumberType *eigenvectors_loc = - (compute_eigenvectors ? &eigenvectors->values[0] : nullptr); + (compute_eigenvectors ? eigenvectors->values.data() : nullptr); work.resize(1); iwork.resize(1); @@ -1596,12 +1597,12 @@ ScaLAPACKMatrix::eigenpairs_symmetric( &submatrix_row, &submatrix_column, descriptor, - &ev[0], + ev.data(), eigenvectors_loc, &eigenvectors->submatrix_row, &eigenvectors->submatrix_column, eigenvectors->descriptor, - &work[0], + work.data(), &lwork, &info); AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("psyev", info)); @@ -1630,19 +1631,19 @@ ScaLAPACKMatrix::eigenpairs_symmetric( &abstol, &m, &nz, - &ev[0], + ev.data(), &orfac, eigenvectors_loc, &eigenvectors->submatrix_row, &eigenvectors->submatrix_column, eigenvectors->descriptor, - &work[0], + work.data(), &lwork, - &iwork[0], + iwork.data(), &liwork, - &ifail[0], - &iclustr[0], - &gap[0], + ifail.data(), + iclustr.data(), + gap.data(), &info); AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("psyevx", info)); } @@ -1658,12 +1659,12 @@ ScaLAPACKMatrix::eigenpairs_symmetric( &submatrix_row, &submatrix_column, descriptor, - &ev[0], + ev.data(), eigenvectors_loc, &eigenvectors->submatrix_row, &eigenvectors->submatrix_column, eigenvectors->descriptor, - &work[0], + work.data(), &lwork, &info); @@ -1690,19 +1691,19 @@ ScaLAPACKMatrix::eigenpairs_symmetric( &abstol, &m, &nz, - &ev[0], + ev.data(), &orfac, eigenvectors_loc, &eigenvectors->submatrix_row, &eigenvectors->submatrix_column, eigenvectors->descriptor, - &work[0], + work.data(), &lwork, - &iwork[0], + iwork.data(), &liwork, - &ifail[0], - &iclustr[0], - &gap[0], + ifail.data(), + iclustr.data(), + gap.data(), &info); AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("psyevx", info)); @@ -1880,7 +1881,7 @@ ScaLAPACKMatrix::eigenpairs_symmetric_MRRR( il = std::min(eigenvalue_idx.first, eigenvalue_idx.second) + 1; iu = std::max(eigenvalue_idx.first, eigenvalue_idx.second) + 1; } - NumberType *A_loc = &this->values[0]; + NumberType *A_loc = this->values.data(); /* * By setting lwork to -1 a workspace query for optimal length of work is @@ -1889,7 +1890,7 @@ ScaLAPACKMatrix::eigenpairs_symmetric_MRRR( int lwork = -1; int liwork = -1; NumberType *eigenvectors_loc = - (compute_eigenvectors ? &eigenvectors->values[0] : nullptr); + (compute_eigenvectors ? eigenvectors->values.data() : nullptr); work.resize(1); iwork.resize(1); @@ -2049,9 +2050,9 @@ ScaLAPACKMatrix::compute_SVD(ScaLAPACKMatrix *U, { char jobu = left_singluar_vectors ? 'V' : 'N'; char jobvt = right_singluar_vectors ? 'V' : 'N'; - NumberType *A_loc = &this->values[0]; - NumberType *U_loc = left_singluar_vectors ? &(U->values[0]) : nullptr; - NumberType *VT_loc = right_singluar_vectors ? &(VT->values[0]) : nullptr; + NumberType *A_loc = this->values.data(); + NumberType *U_loc = left_singluar_vectors ? U->values.data() : nullptr; + NumberType *VT_loc = right_singluar_vectors ? VT->values.data() : nullptr; int info = 0; /* * by setting lwork to -1 a workspace query for optimal length of work is @@ -2077,7 +2078,7 @@ ScaLAPACKMatrix::compute_SVD(ScaLAPACKMatrix *U, &VT->submatrix_row, &VT->submatrix_column, VT->descriptor, - &work[0], + work.data(), &lwork, &info); AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("pgesvd", info)); @@ -2102,7 +2103,7 @@ ScaLAPACKMatrix::compute_SVD(ScaLAPACKMatrix *U, &VT->submatrix_row, &VT->submatrix_column, VT->descriptor, - &work[0], + work.data(), &lwork, &info); AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("pgesvd", info)); @@ -2161,8 +2162,8 @@ ScaLAPACKMatrix::least_squares(ScaLAPACKMatrix &B, if (grid->mpi_process_is_active) { char trans = transpose ? 'T' : 'N'; - NumberType *A_loc = &this->values[0]; - NumberType *B_loc = &B.values[0]; + NumberType *A_loc = this->values.data(); + NumberType *B_loc = B.values.data(); int info = 0; /* * by setting lwork to -1 a workspace query for optimal length of work is @@ -2183,7 +2184,7 @@ ScaLAPACKMatrix::least_squares(ScaLAPACKMatrix &B, &B.submatrix_row, &B.submatrix_column, B.descriptor, - &work[0], + work.data(), &lwork, &info); AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("pgels", info)); @@ -2203,7 +2204,7 @@ ScaLAPACKMatrix::least_squares(ScaLAPACKMatrix &B, &B.submatrix_row, &B.submatrix_column, B.descriptor, - &work[0], + work.data(), &lwork, &info); AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("pgels", info)); @@ -2317,7 +2318,7 @@ ScaLAPACKMatrix::reciprocal_condition_number( iwork.resize(liwork); int info = 0; - const NumberType *A_loc = &this->values[0]; + const NumberType *A_loc = this->values.data(); // by setting lwork to -1 a workspace query for optimal length of work is // performed @@ -2331,9 +2332,9 @@ ScaLAPACKMatrix::reciprocal_condition_number( descriptor, &a_norm, &rcond, - &work[0], + work.data(), &lwork, - &iwork[0], + iwork.data(), &liwork, &info); AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("pdpocon", info)); @@ -2349,9 +2350,9 @@ ScaLAPACKMatrix::reciprocal_condition_number( descriptor, &a_norm, &rcond, - &work[0], + work.data(), &lwork, - &iwork[0], + iwork.data(), &liwork, &info); AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("pdpocon", info)); @@ -2696,7 +2697,7 @@ ScaLAPACKMatrix::save_serial( hid_t dataspace_id = H5Screate_simple(2, dims, nullptr); // create the dataset within the file using chunk creation properties - hid_t type_id = hdf5_type_id(&tmp.values[0]); + hid_t type_id = hdf5_type_id(tmp.values.data()); hid_t dataset_id = H5Dcreate2(file_id, "/matrix", type_id, @@ -2707,7 +2708,7 @@ ScaLAPACKMatrix::save_serial( // write the dataset status = H5Dwrite( - dataset_id, type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, &tmp.values[0]); + dataset_id, type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp.values.data()); AssertThrow(status >= 0, ExcIO()); // create HDF5 enum type for LAPACKSupport::State and @@ -2842,7 +2843,7 @@ ScaLAPACKMatrix::save_parallel( copy_to(tmp); // get pointer to data held by the process - NumberType *data = (tmp.values.size() > 0) ? &tmp.values[0] : nullptr; + NumberType *data = (tmp.values.size() > 0) ? tmp.values.data() : nullptr; herr_t status; // dataset dimensions @@ -3095,7 +3096,7 @@ ScaLAPACKMatrix::load_serial(const std::string &filename) // Selection hid_t datatype = H5Dget_type(dataset_id); H5T_class_t t_class_in = H5Tget_class(datatype); - H5T_class_t t_class = H5Tget_class(hdf5_type_id(&tmp.values[0])); + H5T_class_t t_class = H5Tget_class(hdf5_type_id(tmp.values.data())); AssertThrow( t_class_in == t_class, ExcMessage( @@ -3120,11 +3121,11 @@ ScaLAPACKMatrix::load_serial(const std::string &filename) // read data status = H5Dread(dataset_id, - hdf5_type_id(&tmp.values[0]), + hdf5_type_id(tmp.values.data()), H5S_ALL, H5S_ALL, H5P_DEFAULT, - &tmp.values[0]); + tmp.values.data()); AssertThrow(status >= 0, ExcIO()); // create HDF5 enum type for LAPACKSupport::State and @@ -3264,7 +3265,7 @@ ScaLAPACKMatrix::load_parallel(const std::string &filename) ScaLAPACKMatrix tmp(n_rows, n_columns, column_grid, MB, NB); // get pointer to data held by the process - NumberType *data = (tmp.values.size() > 0) ? &tmp.values[0] : nullptr; + NumberType *data = (tmp.values.size() > 0) ? tmp.values.data() : nullptr; herr_t status; diff --git a/source/lac/sparsity_tools.cc b/source/lac/sparsity_tools.cc index 164231fc59..e6698f28aa 100644 --- a/source/lac/sparsity_tools.cc +++ b/source/lac/sparsity_tools.cc @@ -994,7 +994,7 @@ namespace SparsityTools unsigned int idx = 0; for (const auto &sparsity_line : send_data) { - const int ierr = MPI_Isend(&(sparsity_line.second[0]), + const int ierr = MPI_Isend(sparsity_line.second.data(), sparsity_line.second.size(), DEAL_II_DOF_INDEX_MPI_TYPE, sparsity_line.first, @@ -1138,7 +1138,7 @@ namespace SparsityTools unsigned int idx = 0; for (const auto &sparsity_line : send_data) { - const int ierr = MPI_Isend(&(sparsity_line.second[0]), + const int ierr = MPI_Isend(sparsity_line.second.data(), sparsity_line.second.size(), DEAL_II_DOF_INDEX_MPI_TYPE, sparsity_line.first, diff --git a/source/lac/trilinos_sparse_matrix.cc b/source/lac/trilinos_sparse_matrix.cc index acad71da8c..291929c5c3 100644 --- a/source/lac/trilinos_sparse_matrix.cc +++ b/source/lac/trilinos_sparse_matrix.cc @@ -146,9 +146,9 @@ namespace TrilinosWrappers this->a_row, colnums, ncols, - &((*value_cache)[0]), + value_cache->data(), reinterpret_cast( - &((*colnum_cache)[0]))); + colnum_cache->data())); value_cache->resize(ncols); colnum_cache->resize(ncols); AssertThrow(ierr == 0, ExcTrilinosError(ierr)); @@ -207,7 +207,7 @@ namespace TrilinosWrappers *column_space_map, reinterpret_cast( const_cast( - &(n_entries_per_row[0]))), + n_entries_per_row.data())), false)) , last_action(Zero) , compressed(false) @@ -238,7 +238,7 @@ namespace TrilinosWrappers input_row_map, reinterpret_cast( const_cast( - &(n_entries_per_row[0]))), + n_entries_per_row.data())), false)) , last_action(Zero) , compressed(false) @@ -291,7 +291,7 @@ namespace TrilinosWrappers Utilities::Trilinos::comm_self()), *column_space_map, reinterpret_cast( - const_cast(&(n_entries_per_row[0]))), + const_cast(n_entries_per_row.data())), false)) , last_action(Zero) , compressed(false) @@ -323,7 +323,7 @@ namespace TrilinosWrappers *column_space_map, reinterpret_cast( const_cast( - &(n_entries_per_row[0]))), + n_entries_per_row.data())), false)) , last_action(Zero) , compressed(false) @@ -358,7 +358,7 @@ namespace TrilinosWrappers Copy, row_parallel_partitioning.make_trilinos_map(communicator, false), reinterpret_cast( - const_cast(&(n_entries_per_row[0]))), + const_cast(n_entries_per_row.data())), false)) , last_action(Zero) , compressed(false) diff --git a/source/lac/trilinos_sparsity_pattern.cc b/source/lac/trilinos_sparsity_pattern.cc index 454c0ca394..33887b18c5 100644 --- a/source/lac/trilinos_sparsity_pattern.cc +++ b/source/lac/trilinos_sparsity_pattern.cc @@ -60,7 +60,7 @@ namespace TrilinosWrappers colnum_cache->size(), ncols, reinterpret_cast( - const_cast(&(*colnum_cache)[0]))); + const_cast(colnum_cache->data()))); AssertThrow(ierr == 0, ExcTrilinosError(ierr)); AssertThrow(static_cast::size_type>(ncols) == colnum_cache->size(), diff --git a/source/multigrid/mg_transfer_matrix_free.cc b/source/multigrid/mg_transfer_matrix_free.cc index 6bd39c8cc1..87e2bfdeab 100644 --- a/source/multigrid/mg_transfer_matrix_free.cc +++ b/source/multigrid/mg_transfer_matrix_free.cc @@ -500,7 +500,7 @@ MGTransferMatrixFree::do_restrict_add( [(cell / vec_size) * three_to_dim], n_components, fe_degree, - &evaluation_data[0]); + evaluation_data.data()); for (unsigned int c = 0; c < n_components; ++c) internal::FEEvaluationImplBasisChange::build_patches( // now build the patches in parallel if (all_cells.size() > 0) WorkStream::run( - &all_cells[0], - &all_cells[0] + all_cells.size(), + all_cells.data(), + all_cells.data() + all_cells.size(), std::bind(&DataOut::build_one_patch, this, std::placeholders::_1, diff --git a/source/numerics/data_out_faces.cc b/source/numerics/data_out_faces.cc index 89d173bc78..5e5b013657 100644 --- a/source/numerics/data_out_faces.cc +++ b/source/numerics/data_out_faces.cc @@ -396,8 +396,8 @@ DataOutFaces::build_patches( n_datasets, Utilities::fixed_power(n_subdivisions + 1)); // now build the patches in parallel - WorkStream::run(&all_faces[0], - &all_faces[0] + all_faces.size(), + WorkStream::run(all_faces.data(), + all_faces.data() + all_faces.size(), std::bind(&DataOutFaces::build_one_patch, this, std::placeholders::_1, diff --git a/source/numerics/data_out_rotation.cc b/source/numerics/data_out_rotation.cc index 41a3f78d0c..3704e214c5 100644 --- a/source/numerics/data_out_rotation.cc +++ b/source/numerics/data_out_rotation.cc @@ -533,8 +533,8 @@ DataOutRotation::build_patches( // now build the patches in parallel WorkStream::run( - &all_cells[0], - &all_cells[0] + all_cells.size(), + all_cells.data(), + all_cells.data() + all_cells.size(), std::bind(&DataOutRotation::build_one_patch, this, std::placeholders::_1, diff --git a/source/numerics/kdtree.cc b/source/numerics/kdtree.cc index 4f96a9d281..27e41afe0e 100644 --- a/source/numerics/kdtree.cc +++ b/source/numerics/kdtree.cc @@ -48,7 +48,7 @@ KDTree::get_points_within_ball(const Point ¢er, params.sorted = sorted; std::vector> matches; - kdtree->radiusSearch(¢er[0], radius, matches, params); + kdtree->radiusSearch(center.begin_raw(), radius, matches, params); return matches; } @@ -67,7 +67,10 @@ KDTree::get_closest_points(const Point & target, std::vector indices(n_points); std::vector distances(n_points); - kdtree->knnSearch(&target[0], n_points, &indices[0], &distances[0]); + kdtree->knnSearch(target.begin_raw(), + n_points, + indices.data(), + distances.data()); // convert it to the format we want to return std::vector> matches(n_points); diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index 3d07cbb5f7..34df0fb9ce 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -904,7 +904,7 @@ namespace Particles AssertThrowMPI(ierr); } const int ierr = - MPI_Waitall(2 * n_neighbors, &n_requests[0], MPI_STATUSES_IGNORE); + MPI_Waitall(2 * n_neighbors, n_requests.data(), MPI_STATUSES_IGNORE); AssertThrowMPI(ierr); } @@ -953,7 +953,7 @@ namespace Particles recv_ops++; } const int ierr = - MPI_Waitall(send_ops + recv_ops, &requests[0], MPI_STATUSES_IGNORE); + MPI_Waitall(send_ops + recv_ops, requests.data(), MPI_STATUSES_IGNORE); AssertThrowMPI(ierr); }