From 7c7dfcaf0594eda821ee94c35c637be7f40f4a6f Mon Sep 17 00:00:00 2001 From: Bruno Turcksin Date: Tue, 6 Oct 2015 09:55:54 -0500 Subject: [PATCH] Augment documentation of GridTools::compute_local_to_global_vertex_index_map and use vectors instead of C-style dynamic array. --- include/deal.II/base/types.h | 5 ++ include/deal.II/grid/grid_tools.h | 13 ++++-- source/grid/grid_tools.cc | 76 +++++++++---------------------- 3 files changed, 36 insertions(+), 58 deletions(-) diff --git a/include/deal.II/base/types.h b/include/deal.II/base/types.h index 410360b1cf..7928db29f8 100644 --- a/include/deal.II/base/types.h +++ b/include/deal.II/base/types.h @@ -45,6 +45,11 @@ namespace types * The type used for global indices of vertices. */ typedef unsigned long long int global_vertex_index; + + /** + * An identifier that denotes the MPI type associated with + * types::global_vertex_index. + */ # define DEAL_II_VERTEX_INDEX_MPI_TYPE MPI_UNSIGNED_LONG_LONG #ifdef DEAL_II_WITH_64BIT_INDICES diff --git a/include/deal.II/grid/grid_tools.h b/include/deal.II/grid/grid_tools.h index bc675fb322..f154b32673 100644 --- a/include/deal.II/grid/grid_tools.h +++ b/include/deal.II/grid/grid_tools.h @@ -644,10 +644,15 @@ namespace GridTools vertex_to_cell_map(const Triangulation &triangulation); /** - * Compute a global unique index for each vertex and hanging node associated - * to a locally owned active cell. The key of the map is the local index of - * the vertex and the value is the global index. The indices need to be - * recomputed after refinement or coarsening and may be different. + * Compute a globally unique index for each vertex and hanging node associated + * with a locally owned active cell. The vertices of a ghost cell that are + * hanging nodes of a locally owned cells have a global index. However, the + * other vertices of the cells that do not touch an active cell do not + * have a global index on this processor. + * + * The key of the map is the local index of the vertex and the value is the + * global index. The indices need to be recomputed after refinement or + * coarsening and may be different. */ template std::map diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index 1842b58f5e..6861251900 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -1646,7 +1646,8 @@ next_cell: std::map local_to_global_vertex_index; typedef typename Triangulation::active_cell_iterator active_cell_iterator; - std::vector > vertex_to_cell = vertex_to_cell_map(triangulation); + const std::vector > vertex_to_cell = + vertex_to_cell_map(triangulation); // Create a local index for the locally "owned" vertices types::global_vertex_index next_index = 0; @@ -1669,7 +1670,6 @@ next_cell: typename std::set::iterator adjacent_cell = vertex_to_cell[cell->vertex_index(i)].begin(), end_adj_cell = vertex_to_cell[cell->vertex_index(i)].end(); - bool can_be_recv = false; for (; adjacent_cell!=end_adj_cell; ++adjacent_cell) lowest_subdomain_id = std::min(lowest_subdomain_id, (*adjacent_cell)->subdomain_id()); @@ -1679,12 +1679,12 @@ next_cell: { // Check that the vertex we are working on a vertex that has not be // dealt with yet - if (used_vertex_index.count(cell->vertex_index(i))==0) + if (used_vertex_index.find(cell->vertex_index(i))==used_vertex_index.end()) { // Set the local index local_to_global_vertex_index[cell->vertex_index(i)] = next_index++; - // Store the informations that will be send to the adjacent cells + // Store the information that will be sent to the adjacent cells // on other subdomains adjacent_cell = vertex_to_cell[cell->vertex_index(i)].begin(); std::vector subdomain_ids; @@ -1693,7 +1693,7 @@ next_cell: { std::tuple tmp((*adjacent_cell)->subdomain_id(), cell->vertex_index(i)); - if (vertices_added.count(tmp)==0) + if (vertices_added.find(tmp)==vertices_added.end()) { vertices_to_send[(*adjacent_cell)->subdomain_id()].push_back( std::tuple > vertices_send_buffers( + vertices_to_send.size()); + std::vector first_requests(vertices_to_send.size()); typename std::map > >::iterator @@ -1783,7 +1780,7 @@ next_cell: int destination = vert_to_send_it->first; const unsigned int n_vertices = vert_to_send_it->second.size(); const int buffer_size = 2*n_vertices; - vertices_send_buffers[i] = new types::global_dof_index [buffer_size]; + vertices_send_buffers[i].resize(buffer_size); // fill the buffer for (unsigned int j=0; j > vertices_recv_buffers( + vertices_to_recv.size()); typename std::map >::iterator vert_to_recv_it = vertices_to_recv.begin(), vert_to_recv_end = vertices_to_recv.end(); @@ -1809,18 +1806,17 @@ next_cell: int source = vert_to_recv_it->first; const unsigned int n_vertices = vert_to_recv_it->second.size(); const int buffer_size = 2*n_vertices; - vertices_recv_buffers[i] = new types::global_dof_index[buffer_size]; + vertices_recv_buffers[i].resize(buffer_size); // Receive the message - MPI_Recv(vertices_recv_buffers[i],buffer_size,DEAL_II_VERTEX_INDEX_MPI_TYPE, + MPI_Recv(&vertices_recv_buffers[i][0],buffer_size,DEAL_II_VERTEX_INDEX_MPI_TYPE, source, 0, triangulation.get_communicator(), MPI_STATUS_IGNORE); } // Send second message - char **cellids_send_buffers = new char *[vertices_to_send.size()]; - MPI_Request *second_requests; - second_requests = new MPI_Request[vertices_to_send.size()]; + std::vector > cellids_send_buffers(vertices_to_send.size()); + std::vector second_requests(vertices_to_send.size()); vert_to_send_it = vertices_to_send.begin(); for (unsigned int i=0; vert_to_send_it!=vert_to_send_end; ++vert_to_send_it, ++i) @@ -1828,7 +1824,7 @@ next_cell: int destination = vert_to_send_it->first; const unsigned int n_vertices = vert_to_send_it->second.size(); const int buffer_size = max_cellid_size*n_vertices; - cellids_send_buffers[i] = new char [buffer_size]; + cellids_send_buffers[i].resize(buffer_size); // fill the buffer unsigned int pos = 0; @@ -1847,22 +1843,22 @@ next_cell: } // Send the message - MPI_Isend(cellids_send_buffers[i],buffer_size,MPI_CHAR, + MPI_Isend(&cellids_send_buffers[i][0], buffer_size, MPI_CHAR, destination, 0, triangulation.get_communicator(), &second_requests[i]); } // Receive the second message - char **cellids_recv_buffers = new char *[vertices_to_recv.size()]; + std::vector > cellids_recv_buffers(vertices_to_recv.size()); vert_to_recv_it = vertices_to_recv.begin(); for (unsigned int i=0; vert_to_recv_it!=vert_to_recv_end; ++vert_to_recv_it, ++i) { int source = vert_to_recv_it->first; const unsigned int n_vertices = vert_to_recv_it->second.size(); const int buffer_size = max_cellid_size*n_vertices; - cellids_recv_buffers[i] = new char[buffer_size]; + cellids_recv_buffers[i].resize(buffer_size); // Receive the message - MPI_Recv(cellids_recv_buffers[i],buffer_size,DEAL_II_VERTEX_INDEX_MPI_TYPE, + MPI_Recv(&cellids_recv_buffers[i][0],buffer_size, MPI_CHAR, source, 0, triangulation.get_communicator(), MPI_STATUS_IGNORE); } @@ -1903,34 +1899,6 @@ next_cell: } } - // Free the buffers used to send the messages - for (unsigned int i=0; i