本文整理汇总了C++中boost::multi_array::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ multi_array::clear方法的具体用法?C++ multi_array::clear怎么用?C++ multi_array::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::multi_array
的用法示例。
在下文中一共展示了multi_array::clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: distribute_vertices
//-----------------------------------------------------------------------------
void MeshPartitioning::distribute_vertices(const LocalMeshData& mesh_data,
const boost::multi_array<std::size_t, 2>& cell_vertices,
std::vector<std::size_t>& vertex_indices,
std::map<std::size_t, std::size_t>& vertex_global_to_local,
boost::multi_array<double, 2>& vertex_coordinates)
{
// This function distributes all vertices (coordinates and
// local-to-global mapping) according to the cells that are stored on
// each process. This happens in several stages: First each process
// figures out which vertices it needs (by looking at its cells)
// and where those vertices are located. That information is then
// distributed so that each process learns where it needs to send
// its vertices.
// Get number of processes
const std::size_t num_processes = MPI::num_processes();
// Get geometric dimension
const std::size_t gdim = mesh_data.gdim;
// Compute which vertices we need
std::set<std::size_t> needed_vertex_indices;
boost::multi_array<std::size_t, 2>::const_iterator vertices;
for (vertices = cell_vertices.begin(); vertices != cell_vertices.end();
++vertices)
{
needed_vertex_indices.insert(vertices->begin(), vertices->end());
}
// Compute where (process number) the vertices we need are located
std::vector<std::vector<std::size_t> > send_vertex_indices(num_processes);
std::vector<std::vector<std::size_t> > vertex_location(num_processes);
std::set<std::size_t>::const_iterator required_vertex;
for (required_vertex = needed_vertex_indices.begin();
required_vertex != needed_vertex_indices.end(); ++required_vertex)
{
// Get process that has required vertex
const std::size_t location
= MPI::index_owner(*required_vertex, mesh_data.num_global_vertices);
send_vertex_indices[location].push_back(*required_vertex);
vertex_location[location].push_back(*required_vertex);
}
// Send required vertices to other processes, and receive back vertices
// required by other processes.
std::vector<std::vector<std::size_t> > received_vertex_indices;
MPI::all_to_all(send_vertex_indices, received_vertex_indices);
// Distribute vertex coordinates
std::vector<std::vector<double> > send_vertex_coordinates(num_processes);
const std::pair<std::size_t, std::size_t> local_vertex_range
= MPI::local_range(mesh_data.num_global_vertices);
for (std::size_t p = 0; p < num_processes; ++p)
{
send_vertex_coordinates[p].reserve(received_vertex_indices[p].size()*gdim);
for (std::size_t i = 0; i < received_vertex_indices[p].size(); ++i)
{
dolfin_assert(received_vertex_indices[p][i] >= local_vertex_range.first
&& received_vertex_indices[p][i] < local_vertex_range.second);
const std::size_t location
= received_vertex_indices[p][i] - local_vertex_range.first;
for (std::size_t j = 0; j < gdim; ++j)
send_vertex_coordinates[p].push_back(mesh_data.vertex_coordinates[location][j]);
}
}
std::vector<std::vector<double> > received_vertex_coordinates;
MPI::all_to_all(send_vertex_coordinates, received_vertex_coordinates);
// Set index counters to first position in receive buffers
std::vector<std::size_t> index_counters(num_processes, 0);
// Clear data
vertex_indices.clear();
vertex_global_to_local.clear();
// Count number of local vertices
std::size_t num_local_vertices = 0;
for (std::size_t p = 0; p < num_processes; ++p)
num_local_vertices += received_vertex_coordinates[p].size()/gdim;
// Store coordinates and construct global to local mapping
vertex_coordinates.resize(boost::extents[num_local_vertices][gdim]);
vertex_indices.resize(num_local_vertices);
std::size_t v = 0;
for (std::size_t p = 0; p < num_processes; ++p)
{
for (std::size_t i = 0; i < received_vertex_coordinates[p].size();
i += gdim)
{
for (std::size_t j = 0; j < gdim; ++j)
vertex_coordinates[v][j] = received_vertex_coordinates[p][i + j];
const std::size_t global_vertex_index
= vertex_location[p][index_counters[p]++];
vertex_global_to_local[global_vertex_index] = v;
vertex_indices[v] = global_vertex_index;
++v;
}
//.........这里部分代码省略.........