From 97c89d8dfe4a95dc6fd6140b1252e1eb2667cf7e Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 5 May 2014 03:23:03 +0000 Subject: [PATCH] Remove SparsityTools::size_type and replace it by the appropriate size_type of the sparsity pattern we use. git-svn-id: https://svn.dealii.org/trunk@32885 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 11 ++ deal.II/include/deal.II/lac/sparsity_tools.h | 17 +-- deal.II/source/lac/sparsity_tools.cc | 136 +++++++++---------- 3 files changed, 84 insertions(+), 80 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index fdfb9367f9..470555d767 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -148,6 +148,17 @@ inconvenience this causes.

Specific improvements

    +
  1. Changed: Namespace SparsityTools had a local typedef size_type + that was set equal to types::global_dof_index. This typedef has been removed + and we now use SparsityPattern::size_type wherever applicable as this is the + type we really want to use. (The code worked previously because + types::global_dof_index and SparsityPattern::size_type happen to be the same + as far as the underlying type is concerned; however, they are different + semantically.) +
    + (Wolfgang Bangerth, 2014/05/04) +
  2. +
  3. Updated: The step-16 tutorial program was updated to the new layout multigrid objects and thus avoids using deprecated interfaces.
    diff --git a/deal.II/include/deal.II/lac/sparsity_tools.h b/deal.II/include/deal.II/lac/sparsity_tools.h index 55baf88362..8a616e7513 100644 --- a/deal.II/include/deal.II/lac/sparsity_tools.h +++ b/deal.II/include/deal.II/lac/sparsity_tools.h @@ -1,7 +1,7 @@ // --------------------------------------------------------------------- // $Id$ // -// Copyright (C) 2008 - 2013 by the deal.II authors +// Copyright (C) 2008 - 2014 by the deal.II authors // // This file is part of the deal.II library. // @@ -20,6 +20,7 @@ #include #include +#include #include @@ -30,9 +31,6 @@ DEAL_II_NAMESPACE_OPEN -class SparsityPattern; - - /*! @addtogroup Sparsity *@{ @@ -46,11 +44,6 @@ class SparsityPattern; */ namespace SparsityTools { - /** - * Declare type for container size. - */ - typedef types::global_dof_index size_type; - /** * Use the METIS partitioner to generate a partitioning of the degrees of * freedom represented by this sparsity pattern. In effect, we view this @@ -138,8 +131,8 @@ namespace SparsityTools */ void reorder_Cuthill_McKee (const SparsityPattern &sparsity, - std::vector &new_indices, - const std::vector &starting_indices = std::vector()); + std::vector &new_indices, + const std::vector &starting_indices = std::vector()); #ifdef DEAL_II_WITH_MPI @@ -167,7 +160,7 @@ namespace SparsityTools */ template void distribute_sparsity_pattern(CSP_t &csp, - const std::vector &rows_per_cpu, + const std::vector &rows_per_cpu, const MPI_Comm &mpi_comm, const IndexSet &myrange); diff --git a/deal.II/source/lac/sparsity_tools.cc b/deal.II/source/lac/sparsity_tools.cc index 10bac030c3..673f2783a4 100644 --- a/deal.II/source/lac/sparsity_tools.cc +++ b/deal.II/source/lac/sparsity_tools.cc @@ -1,7 +1,7 @@ // --------------------------------------------------------------------- // $Id$ // -// Copyright (C) 2008 - 2013 by the deal.II authors +// Copyright (C) 2008 - 2014 by the deal.II authors // // This file is part of the deal.II library. // @@ -94,7 +94,7 @@ namespace SparsityTools int_rowstart.reserve(sparsity_pattern.n_rows()+1); std::vector int_colnums; int_colnums.reserve(sparsity_pattern.n_nonzero_elements()); - for (size_type row=0; row &new_indices) + const std::vector &new_indices) { { - size_type starting_point = numbers::invalid_size_type; - size_type min_coordination = sparsity.n_rows(); - for (size_type row=0; row(j-sparsity.begin(row)) < + if (static_cast(j-sparsity.begin(row)) < min_coordination) { min_coordination = j-sparsity.begin(row); @@ -183,7 +183,7 @@ namespace SparsityTools // starting point, e.g. the first unnumbered one if (starting_point == numbers::invalid_size_type) { - for (size_type i=0; i &new_indices, - const std::vector &starting_indices) + reorder_Cuthill_McKee (const SparsityPattern &sparsity, + std::vector &new_indices, + const std::vector &starting_indices) { Assert (sparsity.n_rows() == sparsity.n_cols(), ExcDimensionMismatch (sparsity.n_rows(), sparsity.n_cols())); @@ -211,26 +211,26 @@ namespace SparsityTools ExcDimensionMismatch (sparsity.n_rows(), new_indices.size())); Assert (starting_indices.size() <= sparsity.n_rows(), ExcMessage ("You can't specify more starting indices than there are rows")); - for (size_type i=0; i last_round_dofs (starting_indices); + std::vector last_round_dofs (starting_indices); // initialize the new_indices array with invalid values std::fill (new_indices.begin(), new_indices.end(), numbers::invalid_size_type); // delete disallowed elements - for (size_type i=0; i=sparsity.n_rows())) last_round_dofs[i] = numbers::invalid_size_type; std::remove_if (last_round_dofs.begin(), last_round_dofs.end(), - std::bind2nd(std::equal_to(), + std::bind2nd(std::equal_to(), numbers::invalid_size_type)); // now if no valid points remain: find dof with lowest coordination number @@ -240,10 +240,10 @@ namespace SparsityTools new_indices)); // store next free dof index - size_type next_free_number = 0; + SparsityPattern::size_type next_free_number = 0; // enumerate the first round dofs - for (size_type i=0; i!=last_round_dofs.size(); ++i) + for (SparsityPattern::size_type i=0; i!=last_round_dofs.size(); ++i) new_indices[last_round_dofs[i]] = next_free_number++; // now do as many steps as needed to @@ -252,12 +252,12 @@ namespace SparsityTools { // store the indices of the dofs to be // renumbered in the next round - std::vector next_round_dofs; + std::vector next_round_dofs; // find all neighbors of the // dofs numbered in the last // round - for (size_type i=0; iis_valid_entry() == false) @@ -269,7 +269,7 @@ namespace SparsityTools std::sort (next_round_dofs.begin(), next_round_dofs.end()); // delete multiple entries - std::vector::iterator end_sorted; + std::vector::iterator end_sorted; end_sorted = std::unique (next_round_dofs.begin(), next_round_dofs.end()); next_round_dofs.erase (end_sorted, next_round_dofs.end()); @@ -332,14 +332,14 @@ namespace SparsityTools // store for each coordination // number the dofs with these // coordination number - std::multimap dofs_by_coordination; + std::multimap dofs_by_coordination; // find coordination number for // each of these dofs - for (std::vector::iterator s=next_round_dofs.begin(); + for (std::vector::iterator s=next_round_dofs.begin(); s!=next_round_dofs.end(); ++s) { - size_type coordination = 0; + SparsityPattern::size_type coordination = 0; for (SparsityPattern::iterator j=sparsity.begin(*s); jis_valid_entry() == false) @@ -349,14 +349,14 @@ namespace SparsityTools // insert this dof at its // coordination number - const std::pair new_entry (coordination, *s); + const std::pair new_entry (coordination, *s); dofs_by_coordination.insert (new_entry); } // assign new DoF numbers to // the elements of the present // front: - std::multimap::iterator i; + std::multimap::iterator i; for (i = dofs_by_coordination.begin(); i!=dofs_by_coordination.end(); ++i) new_indices[i->second] = next_free_number++; @@ -382,27 +382,27 @@ namespace SparsityTools #ifdef DEAL_II_WITH_MPI template void distribute_sparsity_pattern(CSP_t &csp, - const std::vector &rows_per_cpu, + const std::vector &rows_per_cpu, const MPI_Comm &mpi_comm, const IndexSet &myrange) { - size_type myid = Utilities::MPI::this_mpi_process(mpi_comm); - std::vector start_index(rows_per_cpu.size()+1); + const unsigned int myid = Utilities::MPI::this_mpi_process(mpi_comm); + std::vector start_index(rows_per_cpu.size()+1); start_index[0]=0; - for (size_type i=0; i > map_vec_t; + typedef std::map > map_vec_t; map_vec_t send_data; { unsigned int dest_cpu=0; - size_type n_local_rel_rows = myrange.n_elements(); - for (size_type row_idx=0; row_idx=start_index[dest_cpu+1]) @@ -415,21 +415,21 @@ namespace SparsityTools continue; } - size_type rlen = csp.row_length(row); + typename CSP_t::size_type rlen = csp.row_length(row); //skip empty lines if (!rlen) continue; //save entries - std::vector &dst = send_data[dest_cpu]; + std::vector &dst = send_data[dest_cpu]; dst.push_back(rlen); // number of entries dst.push_back(row); // row index - for (size_type c=0; c send_to; send_to.reserve(send_data.size()); - for (map_vec_t::iterator it=send_data.begin(); it!=send_data.end(); ++it) + for (typename map_vec_t::iterator it=send_data.begin(); it!=send_data.end(); ++it) send_to.push_back(it->first); num_receive = @@ -454,7 +454,7 @@ namespace SparsityTools // send data { unsigned int idx=0; - for (map_vec_t::iterator it=send_data.begin(); it!=send_data.end(); ++it, ++idx) + for (typename map_vec_t::iterator it=send_data.begin(); it!=send_data.end(); ++it, ++idx) MPI_Isend(&(it->second[0]), it->second.size(), DEAL_II_DOF_INDEX_MPI_TYPE, @@ -465,11 +465,11 @@ namespace SparsityTools } //TODO: In the following, we read individual bytes and then reinterpret them -// as size_type objects. this is error prone. use properly typed reads that +// as typename CSP_t::size_type objects. this is error prone. use properly typed reads that // match the write above { //receive - std::vector recv_buf; + std::vector recv_buf; for (unsigned int index=0; index::const_iterator ptr = recv_buf.begin(); - std::vector::const_iterator end = recv_buf.end(); + typename std::vector::const_iterator ptr = recv_buf.begin(); + typename std::vector::const_iterator end = recv_buf.end(); while (ptr+1 > map_vec_t; + typedef std::map > map_vec_t; map_vec_t send_data; { unsigned int dest_cpu=0; - size_type n_local_rel_rows = myrange.n_elements(); - for (size_type row_idx=0; row_idx &dst = send_data[dest_cpu]; + std::vector &dst = send_data[dest_cpu]; dst.push_back(rlen); // number of entries dst.push_back(row); // row index - for (size_type c=0; c send_to; send_to.reserve(send_data.size()); - for (map_vec_t::iterator it=send_data.begin(); it!=send_data.end(); ++it) + for (typename map_vec_t::iterator it=send_data.begin(); it!=send_data.end(); ++it) send_to.push_back(it->first); num_receive = @@ -578,7 +578,7 @@ namespace SparsityTools // send data { unsigned int idx=0; - for (map_vec_t::iterator it=send_data.begin(); it!=send_data.end(); ++it, ++idx) + for (typename map_vec_t::iterator it=send_data.begin(); it!=send_data.end(); ++it, ++idx) MPI_Isend(&(it->second[0]), it->second.size(), DEAL_II_DOF_INDEX_MPI_TYPE, @@ -589,11 +589,11 @@ namespace SparsityTools } //TODO: In the following, we read individual bytes and then reinterpret them -// as size_type objects. this is error prone. use properly typed reads that +// as typename CSP_t::size_type objects. this is error prone. use properly typed reads that // match the write above { //receive - std::vector recv_buf; + std::vector recv_buf; for (unsigned int index=0; index::const_iterator ptr = recv_buf.begin(); - std::vector::const_iterator end = recv_buf.end(); + typename std::vector::const_iterator ptr = recv_buf.begin(); + typename std::vector::const_iterator end = recv_buf.end(); while (ptr+1 (SparsityType & csp, \ - const std::vector & rows_per_cpu,\ + const std::vector & rows_per_cpu,\ const MPI_Comm & mpi_comm,\ const IndexSet & myrange) -- 2.39.5