libMesh
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
libMesh::Parallel::Sort< KeyType, IdxType > Class Template Reference

The parallel sorting method is templated on the type of data which is to be sorted. More...

#include <parallel_sort.h>

Inheritance diagram for libMesh::Parallel::Sort< KeyType, IdxType >:
[legend]

Public Member Functions

 Sort (const Parallel::Communicator &comm, std::vector< KeyType > &d)
 Constructor takes the number of processors, the processor id, and a reference to a vector of data to be sorted. More...
 
void sort ()
 This is the only method which needs to be called by the user. More...
 
const std::vector< KeyType > & bin ()
 Return a constant reference to _my_bin. More...
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Protected Attributes

const Parallel::Communicator_communicator
 

Private Member Functions

void binsort ()
 Sorts the local data into bins across all processors. More...
 
void communicate_bins ()
 Communicates the bins from each processor to the appropriate processor. More...
 
void sort_local_bin ()
 After all the bins have been communicated, we can sort our local bin. More...
 
template<>
void binsort ()
 
template<>
void communicate_bins ()
 

Private Attributes

const processor_id_type _n_procs
 The number of processors to work with. More...
 
const processor_id_type _proc_id
 The identity of this processor. More...
 
bool _bin_is_sorted
 Flag which lets you know if sorting is complete. More...
 
std::vector< KeyType > & _data
 The raw, unsorted data which will need to be sorted (in parallel) across all processors. More...
 
std::vector< IdxType > _local_bin_sizes
 Vector which holds the size of each bin on this processor. More...
 
std::vector< KeyType > _my_bin
 The bin which will eventually be held by this processor. More...
 

Detailed Description

template<typename KeyType, typename IdxType = unsigned int>
class libMesh::Parallel::Sort< KeyType, IdxType >

The parallel sorting method is templated on the type of data which is to be sorted.

It may later be templated on other things if we are ambitious. This class knows about MPI, and knows how many processors there are. It is responsible for transmitting data between the processors and ensuring that the data is properly sorted between all the processors. We assume that a Sort is instantiated on all processors.

Author
Benjamin S. Kirk
John W. Peterson
Date
2007 Object for performing parallel sorts using MPI.

Definition at line 53 of file parallel_sort.h.

Constructor & Destructor Documentation

template<typename KeyType , typename IdxType >
libMesh::Parallel::Sort< KeyType, IdxType >::Sort ( const Parallel::Communicator comm,
std::vector< KeyType > &  d 
)

Constructor takes the number of processors, the processor id, and a reference to a vector of data to be sorted.

This vector is sorted by the constructor, therefore, construction of a Sort object takes O(n log n) time, where n is the length of the vector.

Definition at line 41 of file parallel_sort.C.

References libMesh::Parallel::Sort< KeyType, IdxType >::_data, libMesh::Parallel::Sort< KeyType, IdxType >::_local_bin_sizes, and libMesh::Parallel::Sort< KeyType, IdxType >::_n_procs.

42  :
43  ParallelObject(comm_in),
44  _n_procs(cast_int<processor_id_type>(comm_in.size())),
45  _proc_id(cast_int<processor_id_type>(comm_in.rank())),
46  _bin_is_sorted(false),
47  _data(d)
48 {
49  std::sort(_data.begin(), _data.end());
50 
51  // Allocate storage
52  _local_bin_sizes.resize(_n_procs);
53 }
ParallelObject(const Parallel::Communicator &comm_in)
Constructor.
const processor_id_type _proc_id
The identity of this processor.
Definition: parallel_sort.h:93
std::vector< KeyType > & _data
The raw, unsorted data which will need to be sorted (in parallel) across all processors.
std::vector< IdxType > _local_bin_sizes
Vector which holds the size of each bin on this processor.
const processor_id_type _n_procs
The number of processors to work with.
Definition: parallel_sort.h:88
bool _bin_is_sorted
Flag which lets you know if sorting is complete.
Definition: parallel_sort.h:98

Member Function Documentation

template<typename KeyType , typename IdxType >
const std::vector< KeyType > & libMesh::Parallel::Sort< KeyType, IdxType >::bin ( )

Return a constant reference to _my_bin.

This allows us to do things like check if sorting was successful by printing _my_bin.

Definition at line 376 of file parallel_sort.C.

References libMesh::Parallel::Sort< KeyType, IdxType >::_bin_is_sorted, libMesh::Parallel::Sort< KeyType, IdxType >::_my_bin, and libMesh::out.

Referenced by libMesh::MeshCommunication::assign_global_indices(), and libMesh::MeshCommunication::find_global_indices().

377 {
378  if (!_bin_is_sorted)
379  {
380  libMesh::out << "Warning! Bin is not yet sorted!" << std::endl;
381  }
382 
383  return _my_bin;
384 }
std::vector< KeyType > _my_bin
The bin which will eventually be held by this processor.
OStreamProxy out
bool _bin_is_sorted
Flag which lets you know if sorting is complete.
Definition: parallel_sort.h:98
template<typename KeyType , typename IdxType >
void libMesh::Parallel::Sort< KeyType, IdxType >::binsort ( )
private

Sorts the local data into bins across all processors.

Right now it constructs a BenSorter<KeyType> object. In the future this could be a template parameter.

Definition at line 96 of file parallel_sort.C.

References libMesh::Parallel::Sort< KeyType, IdxType >::_data, libMesh::Parallel::Sort< KeyType, IdxType >::_local_bin_sizes, libMesh::Parallel::Sort< KeyType, IdxType >::_n_procs, libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), libMesh::ParallelObject::comm(), libMesh::Parallel::Communicator::max(), and libMesh::Parallel::BinSorter< KeyType, IdxType >::sizeof_bin().

Referenced by libMesh::Parallel::Sort< KeyType, IdxType >::sort().

97 {
98  // Find the global min and max from all the
99  // processors.
100  std::vector<KeyType> global_min_max(2);
101 
102  // Insert the local min and max for this processor
103  global_min_max[0] = -_data.front();
104  global_min_max[1] = _data.back();
105 
106  // Communicate to determine the global
107  // min and max for all processors.
108  this->comm().max(global_min_max);
109 
110  // Multiply the min by -1 to obtain the true min
111  global_min_max[0] *= -1;
112 
113  // Bin-Sort based on the global min and max
114  Parallel::BinSorter<KeyType> bs(this->comm(), _data);
115  bs.binsort(_n_procs, global_min_max[1], global_min_max[0]);
116 
117  // Now save the local bin sizes in a vector so
118  // we don't have to keep around the BinSorter.
119  for (processor_id_type i=0; i<_n_procs; ++i)
120  _local_bin_sizes[i] = bs.sizeof_bin(i);
121 }
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
uint8_t processor_id_type
Definition: id_types.h:99
std::vector< KeyType > & _data
The raw, unsorted data which will need to be sorted (in parallel) across all processors.
std::vector< IdxType > _local_bin_sizes
Vector which holds the size of each bin on this processor.
const processor_id_type _n_procs
The number of processors to work with.
Definition: parallel_sort.h:88
const Parallel::Communicator & comm() const
template<>
void libMesh::Parallel::Sort< Parallel::DofObjectKey, unsigned int >::binsort ( )
private

Definition at line 130 of file parallel_sort.C.

References libMesh::Parallel::Sort< KeyType, IdxType >::_data, libMesh::Parallel::Sort< KeyType, IdxType >::_local_bin_sizes, libMesh::Parallel::Sort< KeyType, IdxType >::_n_procs, libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), libMesh::ParallelObject::comm(), dofobjectkey_max_op(), dofobjectkey_min_op(), std::max(), and libMesh::Parallel::BinSorter< KeyType, IdxType >::sizeof_bin().

131 {
132  // Find the global min and max from all the
133  // processors. Do this using MPI_Allreduce.
135  local_min, local_max,
136  global_min, global_max;
137 
138  if (_data.empty())
139  {
140 #ifdef LIBMESH_ENABLE_UNIQUE_ID
141  local_min.first.rack0 = local_min.first.rack1 = local_min.first.rack2 = static_cast<Hilbert::inttype>(-1);
142  local_min.second = std::numeric_limits<unique_id_type>::max();
143  local_max.first.rack0 = local_max.first.rack1 = local_max.first.rack2 = 0;
144  local_max.second = 0;
145 #else
146  local_min.rack0 = local_min.rack1 = local_min.rack2 = static_cast<Hilbert::inttype>(-1);
147  local_max.rack0 = local_max.rack1 = local_max.rack2 = 0;
148 #endif
149  }
150  else
151  {
152  local_min = _data.front();
153  local_max = _data.back();
154  }
155 
156  MPI_Op hilbert_max, hilbert_min;
157 
158  MPI_Op_create ((MPI_User_function*)dofobjectkey_max_op, true, &hilbert_max);
159  MPI_Op_create ((MPI_User_function*)dofobjectkey_min_op, true, &hilbert_min);
160 
161  // Communicate to determine the global
162  // min and max for all processors.
163  MPI_Allreduce(&local_min,
164  &global_min,
165  1,
166  Parallel::StandardType<Parallel::DofObjectKey>(&local_min),
167  hilbert_min,
168  this->comm().get());
169 
170  MPI_Allreduce(&local_max,
171  &global_max,
172  1,
173  Parallel::StandardType<Parallel::DofObjectKey>(&local_max),
174  hilbert_max,
175  this->comm().get());
176 
177  MPI_Op_free (&hilbert_max);
178  MPI_Op_free (&hilbert_min);
179 
180  // Bin-Sort based on the global min and max
181  Parallel::BinSorter<Parallel::DofObjectKey> bs(this->comm(),_data);
182  bs.binsort(_n_procs, global_max, global_min);
183 
184  // Now save the local bin sizes in a vector so
185  // we don't have to keep around the BinSorter.
186  for (processor_id_type i=0; i<_n_procs; ++i)
187  _local_bin_sizes[i] = bs.sizeof_bin(i);
188 }
void dofobjectkey_min_op(libMesh::Parallel::DofObjectKey *in, libMesh::Parallel::DofObjectKey *inout, int *len, void *)
std::pair< Hilbert::HilbertIndices, unique_id_type > DofObjectKey
uint8_t processor_id_type
Definition: id_types.h:99
std::vector< KeyType > & _data
The raw, unsorted data which will need to be sorted (in parallel) across all processors.
std::vector< IdxType > _local_bin_sizes
Vector which holds the size of each bin on this processor.
long double max(long double a, double b)
void dofobjectkey_max_op(libMesh::Parallel::DofObjectKey *in, libMesh::Parallel::DofObjectKey *inout, int *len, void *)
const processor_id_type _n_procs
The number of processors to work with.
Definition: parallel_sort.h:88
const Parallel::Communicator & comm() const
const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inherited
Returns
A reference to the Parallel::Communicator object used by this mesh.

Definition at line 87 of file parallel_object.h.

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_petsc_preconditioner_apply(), libMesh::__libmesh_petsc_snes_jacobian(), libMesh::__libmesh_petsc_snes_postcheck(), libMesh::__libmesh_petsc_snes_residual(), libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_equality_constraints_jacobian(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_hessian(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::__libmesh_tao_inequality_constraints_jacobian(), libMesh::__libmesh_tao_objective(), libMesh::MeshRefinement::_coarsen_elements(), libMesh::ExactSolution::_compute_error(), libMesh::ParmetisPartitioner::_do_repartition(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add(), libMesh::EquationSystems::_read_impl(), libMesh::MeshRefinement::_refine_elements(), libMesh::MeshRefinement::_smooth_flags(), add_cube_convex_hull_to_mesh(), libMesh::TransientRBConstruction::add_IC_to_RB_space(), libMesh::ImplicitSystem::add_matrix(), libMesh::RBConstruction::add_scaled_matrix_and_vector(), libMesh::System::add_vector(), libMesh::EigenSparseLinearSolver< T >::adjoint_solve(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::TransientRBConstruction::allocate_data_structures(), libMesh::RBConstruction::allocate_data_structures(), libMesh::TransientRBConstruction::assemble_affine_expansion(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::DofMap::attach_matrix(), libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), libMesh::Parallel::Sort< KeyType, IdxType >::binsort(), libMesh::MeshCommunication::broadcast(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::Parallel::Histogram< KeyType, IdxType >::build_histogram(), libMesh::PetscNonlinearSolver< T >::build_mat_null_space(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::MeshBase::cache_elem_dims(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins(), libMesh::RBConstruction::compute_Fq_representor_innerprods(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::RBConstruction::compute_output_dual_innerprods(), libMesh::RBSCMConstruction::compute_SCM_bounds_on_training_set(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::MeshTools::create_bounding_box(), libMesh::MeshTools::create_nodal_bounding_box(), libMesh::MeshRefinement::create_parent_error_vector(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::MeshTools::create_subdomain_bounding_box(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), libMesh::MeshRefinement::eliminate_unrefined_patches(), libMesh::RBEIMConstruction::enrich_RB_space(), libMesh::TransientRBConstruction::enrich_RB_space(), libMesh::RBConstruction::enrich_RB_space(), AssembleOptimization::equality_constraints(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::RBEIMConstruction::evaluate_mesh_function(), libMesh::MeshRefinement::flag_elements_by_elem_fraction(), libMesh::MeshRefinement::flag_elements_by_error_fraction(), libMesh::MeshRefinement::flag_elements_by_nelem_target(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::MeshfreeInterpolation::gather_remote_data(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::EquationSystems::get_solution(), AssembleOptimization::inequality_constraints(), AssembleOptimization::inequality_constraints_jacobian(), libMesh::LocationMap< T >::init(), libMesh::TopologyMap::init(), libMesh::PetscDiffSolver::init(), libMesh::TimeSolver::init(), libMesh::TaoOptimizationSolver< T >::init(), libMesh::PetscNonlinearSolver< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ParmetisPartitioner::initialize(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), libMesh::RBEIMConstruction::initialize_rb_construction(), integrate_function(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_flags(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_p_levels(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::MeshTools::libmesh_assert_valid_unique_ids(), libMesh::MeshRefinement::limit_level_mismatch_at_edge(), libMesh::MeshRefinement::limit_level_mismatch_at_node(), libMesh::MeshRefinement::limit_overrefined_boundary(), libMesh::MeshRefinement::limit_underrefined_boundary(), main(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshCommunication::make_elems_parallel_consistent(), libMesh::MeshRefinement::make_flags_parallel_consistent(), libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_new_nodes_parallel_consistent(), libMesh::MeshCommunication::make_node_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_unique_ids_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshCommunication::make_p_levels_parallel_consistent(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::TransientRBConstruction::mass_matrix_scaled_matvec(), libMesh::FEMSystem::mesh_position_set(), libMesh::MeshSerializer::MeshSerializer(), LinearElasticityWithContact::move_mesh(), libMesh::DistributedMesh::n_active_elem(), libMesh::MeshTools::n_active_levels(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::CondensedEigenSystem::n_global_non_condensed_dofs(), libMesh::MeshTools::n_levels(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::MeshTools::n_p_levels(), libMesh::BoundaryInfo::n_shellface_conds(), new_function_base(), libMesh::DistributedMesh::parallel_max_elem_id(), libMesh::DistributedMesh::parallel_max_node_id(), libMesh::ReplicatedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_n_elem(), libMesh::DistributedMesh::parallel_n_nodes(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MeshTools::paranoid_n_levels(), libMesh::Partitioner::partition(), libMesh::MetisPartitioner::partition_range(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::SparseMatrix< T >::print(), FEMParameters::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshCommunication::redistribute(), libMesh::MeshRefinement::refine_and_coarsen_elements(), libMesh::DistributedMesh::renumber_dof_objects(), LinearElasticityWithContact::residual_and_jacobian(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::TransientRBConstruction::set_error_temporal_data(), libMesh::RBEIMConstruction::set_explicit_sys_subvector(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Partitioner::set_parent_processor_ids(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::Parallel::sync_element_data_by_parent_id(), libMesh::Parallel::sync_node_data_by_element_id(), libMesh::MeshRefinement::test_level_one(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), libMesh::MeshRefinement::test_unflagged(), PointLocatorTest::testLocator(), BoundaryInfoTest::testMesh(), SystemsTest::testProjectCubeWithMeshFunction(), libMesh::MeshTools::total_weight(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::MeshfreeSolutionTransfer::transfer(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::TransientRBConstruction::update_RB_initial_condition_all_N(), libMesh::RBEIMConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_RB_system_matrices(), libMesh::RBConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_residual_terms(), libMesh::RBConstruction::update_residual_terms(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::RBEvaluation::write_out_vectors(), libMesh::TransientRBConstruction::write_riesz_representors_to_files(), libMesh::RBConstruction::write_riesz_representors_to_files(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::RBDataSerialization::RBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::TransientRBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::RBEIMEvaluationSerialization::write_to_file(), and libMesh::RBDataSerialization::RBSCMEvaluationSerialization::write_to_file().

88  { return _communicator; }
const Parallel::Communicator & _communicator
template<typename KeyType , typename IdxType >
void libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins ( )
private

Communicates the bins from each processor to the appropriate processor.

By the time this function is finished, each processor will hold only its own bin(s).

Definition at line 194 of file parallel_sort.C.

References libMesh::Parallel::Sort< KeyType, IdxType >::_data, libMesh::Parallel::Sort< KeyType, IdxType >::_local_bin_sizes, libMesh::Parallel::Sort< KeyType, IdxType >::_my_bin, libMesh::Parallel::Sort< KeyType, IdxType >::_n_procs, libMesh::Parallel::Sort< KeyType, IdxType >::_proc_id, libMesh::Parallel::Communicator::allgather(), libMesh::ParallelObject::comm(), libmesh_nullptr, and libMesh::Parallel::Communicator::sum().

Referenced by libMesh::Parallel::Sort< KeyType, IdxType >::sort().

195 {
196 #ifdef LIBMESH_HAVE_MPI
197  // Create storage for the global bin sizes. This
198  // is the number of keys which will be held in
199  // each bin over all processors.
200  std::vector<IdxType> global_bin_sizes = _local_bin_sizes;
201 
202  // Sum to find the total number of entries in each bin.
203  this->comm().sum(global_bin_sizes);
204 
205  // Create a vector to temporarily hold the results of MPI_Gatherv
206  // calls. The vector dest may be saved away to _my_bin depending on which
207  // processor is being MPI_Gatherv'd.
208  std::vector<KeyType> dest;
209 
210  IdxType local_offset = 0;
211 
212  for (processor_id_type i=0; i<_n_procs; ++i)
213  {
214  // Vector to receive the total bin size for each
215  // processor. Processor i's bin size will be
216  // held in proc_bin_size[i]
217  std::vector<int> proc_bin_size;
218 
219  // Find the number of contributions coming from each
220  // processor for this bin. Note: allgather combines
221  // the MPI_Gather and MPI_Bcast operations into one.
222  this->comm().allgather(static_cast<int>(_local_bin_sizes[i]),
223  proc_bin_size);
224 
225  // Compute the offsets into my_bin for each processor's
226  // portion of the bin. These are basically partial sums
227  // of the proc_bin_size vector.
228  std::vector<int> displacements(_n_procs);
229  for (processor_id_type j=1; j<_n_procs; ++j)
230  displacements[j] = proc_bin_size[j-1] + displacements[j-1];
231 
232  // Resize the destination buffer
233  dest.resize (global_bin_sizes[i]);
234 
235  // Points to the beginning of the bin to be sent
236  void * sendbuf = (_data.size() > local_offset) ? &_data[local_offset] : libmesh_nullptr;
237 
238  // Enough storage to hold all bin contributions
239  void * recvbuf = (dest.empty()) ? libmesh_nullptr : &dest[0];
240 
241  // If the sendbuf is NULL, make sure we aren't claiming to send something.
242  if (sendbuf == libmesh_nullptr && _local_bin_sizes[i] != 0)
243  libmesh_error_msg("Error: invalid MPI_Gatherv call constructed!");
244 
245  KeyType example;
246 
247  MPI_Gatherv(sendbuf,
248  _local_bin_sizes[i], // How much data is in the bin being sent.
249  Parallel::StandardType<KeyType>(&example), // The data type we are sorting
250  recvbuf,
251  &proc_bin_size[0], // How much is to be received from each processor
252  &displacements[0], // Offsets into the receive buffer
253  Parallel::StandardType<KeyType>(&example), // The data type we are sorting
254  i, // The root process (we do this once for each proc)
255  this->comm().get());
256 
257  // Copy the destination buffer if it
258  // corresponds to the bin for this processor
259  if (i == _proc_id)
260  _my_bin = dest;
261 
262  // Increment the local offset counter
263  local_offset += _local_bin_sizes[i];
264  }
265 #endif // LIBMESH_HAVE_MPI
266 }
const processor_id_type _proc_id
The identity of this processor.
Definition: parallel_sort.h:93
uint8_t processor_id_type
Definition: id_types.h:99
const class libmesh_nullptr_t libmesh_nullptr
std::vector< KeyType > & _data
The raw, unsorted data which will need to be sorted (in parallel) across all processors.
std::vector< IdxType > _local_bin_sizes
Vector which holds the size of each bin on this processor.
const processor_id_type _n_procs
The number of processors to work with.
Definition: parallel_sort.h:88
std::vector< KeyType > _my_bin
The bin which will eventually be held by this processor.
const Parallel::Communicator & comm() const
void sum(T &r) const
Take a local variable and replace it with the sum of it&#39;s values on all processors.
void allgather(const T &send, std::vector< T > &recv) const
Take a vector of length this->size(), and fill in recv[processor_id] = the value of send on that proc...
template<>
void libMesh::Parallel::Sort< Parallel::DofObjectKey, unsigned int >::communicate_bins ( )
private

Definition at line 275 of file parallel_sort.C.

References libMesh::Parallel::Sort< KeyType, IdxType >::_data, libMesh::Parallel::Sort< KeyType, IdxType >::_local_bin_sizes, libMesh::Parallel::Sort< KeyType, IdxType >::_my_bin, libMesh::Parallel::Sort< KeyType, IdxType >::_n_procs, libMesh::Parallel::Sort< KeyType, IdxType >::_proc_id, libMesh::ParallelObject::comm(), and libmesh_nullptr.

276 {
277  // Create storage for the global bin sizes. This
278  // is the number of keys which will be held in
279  // each bin over all processors.
280  std::vector<unsigned int> global_bin_sizes(_n_procs);
281 
282  libmesh_assert_equal_to (_local_bin_sizes.size(), global_bin_sizes.size());
283 
284  // Sum to find the total number of entries in each bin.
285  // This is stored in global_bin_sizes. Note, we
286  // explicitly know that we are communicating MPI_UNSIGNED's here.
287  MPI_Allreduce(&_local_bin_sizes[0],
288  &global_bin_sizes[0],
289  _n_procs,
290  MPI_UNSIGNED,
291  MPI_SUM,
292  this->comm().get());
293 
294  // Create a vector to temporarily hold the results of MPI_Gatherv
295  // calls. The vector dest may be saved away to _my_bin depending on which
296  // processor is being MPI_Gatherv'd.
297  std::vector<Parallel::DofObjectKey> dest;
298 
299  unsigned int local_offset = 0;
300 
301  for (unsigned int i=0; i<_n_procs; ++i)
302  {
303  // Vector to receive the total bin size for each
304  // processor. Processor i's bin size will be
305  // held in proc_bin_size[i]
306  std::vector<int> proc_bin_size(_n_procs);
307 
308  // Find the number of contributions coming from each
309  // processor for this bin. Note: Allgather combines
310  // the MPI_Gather and MPI_Bcast operations into one.
311  // Note: Here again we know that we are communicating
312  // MPI_UNSIGNED's so there is no need to check the MPI_traits.
313  MPI_Allgather(&_local_bin_sizes[i], // Source: # of entries on this proc in bin i
314  1, // Number of items to gather
315  MPI_UNSIGNED,
316  &proc_bin_size[0], // Destination: Total # of entries in bin i
317  1,
318  MPI_INT,
319  this->comm().get());
320 
321  // Compute the offsets into my_bin for each processor's
322  // portion of the bin. These are basically partial sums
323  // of the proc_bin_size vector.
324  std::vector<int> displacements(_n_procs);
325  for (unsigned int j=1; j<_n_procs; ++j)
326  displacements[j] = proc_bin_size[j-1] + displacements[j-1];
327 
328  // Resize the destination buffer
329  dest.resize (global_bin_sizes[i]);
330 
331  // Points to the beginning of the bin to be sent
332  void * sendbuf = (_data.size() > local_offset) ? &_data[local_offset] : libmesh_nullptr;
333 
334  // Enough storage to hold all bin contributions
335  void * recvbuf = (dest.empty()) ? libmesh_nullptr : &dest[0];
336 
337  // If the sendbuf is NULL, make sure we aren't claiming to send something.
338  if (sendbuf == libmesh_nullptr && _local_bin_sizes[i] != 0)
339  libmesh_error_msg("Error: invalid MPI_Gatherv call constructed!");
340 
341  Parallel::DofObjectKey example;
342 
343  MPI_Gatherv(sendbuf,
344  _local_bin_sizes[i], // How much data is in the bin being sent.
345  Parallel::StandardType<Parallel::DofObjectKey>(&example), // The data type we are sorting
346  recvbuf,
347  &proc_bin_size[0], // How much is to be received from each processor
348  &displacements[0], // Offsets into the receive buffer
349  Parallel::StandardType<Parallel::DofObjectKey>(&example), // The data type we are sorting
350  i, // The root process (we do this once for each proc)
351  this->comm().get());
352 
353  // Copy the destination buffer if it
354  // corresponds to the bin for this processor
355  if (i == _proc_id)
356  _my_bin = dest;
357 
358  // Increment the local offset counter
359  local_offset += _local_bin_sizes[i];
360  }
361 }
const processor_id_type _proc_id
The identity of this processor.
Definition: parallel_sort.h:93
std::pair< Hilbert::HilbertIndices, unique_id_type > DofObjectKey
const class libmesh_nullptr_t libmesh_nullptr
std::vector< KeyType > & _data
The raw, unsorted data which will need to be sorted (in parallel) across all processors.
std::vector< IdxType > _local_bin_sizes
Vector which holds the size of each bin on this processor.
const processor_id_type _n_procs
The number of processors to work with.
Definition: parallel_sort.h:88
std::vector< KeyType > _my_bin
The bin which will eventually be held by this processor.
const Parallel::Communicator & comm() const
processor_id_type libMesh::ParallelObject::n_processors ( ) const
inherited
Returns
The number of processors in the group.

Definition at line 93 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::size().

Referenced by libMesh::ParmetisPartitioner::_do_repartition(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::DistributedMesh::add_elem(), libMesh::DistributedMesh::add_node(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::MeshCommunication::broadcast(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DistributedMesh::clear(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::MeshBase::get_info(), libMesh::EquationSystems::get_solution(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::DistributedMesh::insert_elem(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::DofMap::local_variable_indices(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshBase::n_active_elem_on_proc(), libMesh::MeshBase::n_elem_on_proc(), libMesh::MeshBase::n_nodes_on_proc(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::Partitioner::partition(), libMesh::MeshBase::partition(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::PetscLinearSolver< T >::PetscLinearSolver(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::CheckpointIO::read_connectivity(), libMesh::XdrIO::read_header(), libMesh::CheckpointIO::read_nodes(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::Partitioner::repartition(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), WriteVecAndScalar::testWrite(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

94  { return cast_int<processor_id_type>(_communicator.size()); }
unsigned int size() const
Definition: parallel.h:726
const Parallel::Communicator & _communicator
processor_id_type libMesh::ParallelObject::processor_id ( ) const
inherited
Returns
The rank of this processor in the group.

Definition at line 99 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::rank().

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::EquationSystems::_read_impl(), libMesh::DistributedMesh::add_elem(), libMesh::BoundaryInfo::add_elements(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::MeshRefinement::add_node(), libMesh::MeshTools::Modification::all_tri(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::MeshCommunication::broadcast(), libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::Nemesis_IO_Helper::build_element_and_node_maps(), libMesh::ParmetisPartitioner::build_graph(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DofMap::build_sparsity(), libMesh::DistributedMesh::clear(), libMesh::ExodusII_IO_Helper::close(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::compute_communication_map_parameters(), libMesh::Nemesis_IO_Helper::compute_internal_and_border_elems_and_internal_nodes(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::Nemesis_IO_Helper::compute_node_communication_maps(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::ExodusII_IO_Helper::create(), libMesh::DistributedMesh::delete_elem(), libMesh::DistributedMesh::delete_node(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::RBEIMConstruction::evaluate_mesh_function(), libMesh::MeshFunction::find_element(), libMesh::MeshFunction::find_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::Nemesis_IO_Helper::get_cmap_params(), libMesh::Nemesis_IO_Helper::get_eb_info_global(), libMesh::Nemesis_IO_Helper::get_elem_cmap(), libMesh::Nemesis_IO_Helper::get_elem_map(), libMesh::MeshBase::get_info(), libMesh::DofMap::get_info(), libMesh::Nemesis_IO_Helper::get_init_global(), libMesh::Nemesis_IO_Helper::get_init_info(), libMesh::Nemesis_IO_Helper::get_loadbal_param(), libMesh::Nemesis_IO_Helper::get_node_cmap(), libMesh::Nemesis_IO_Helper::get_node_map(), libMesh::Nemesis_IO_Helper::get_ns_param_global(), libMesh::EquationSystems::get_solution(), libMesh::Nemesis_IO_Helper::get_ss_param_global(), libMesh::SparsityPattern::Build::handle_vi_vj(), libMesh::SystemSubsetBySubdomain::init(), HeatSystem::init_data(), libMesh::ParmetisPartitioner::initialize(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::ExodusII_IO_Helper::initialize_element_variables(), libMesh::ExodusII_IO_Helper::initialize_global_variables(), libMesh::ExodusII_IO_Helper::initialize_nodal_variables(), libMesh::DistributedMesh::insert_elem(), libMesh::DofMap::is_evaluable(), libMesh::SparsityPattern::Build::join(), libMesh::TransientRBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEIMEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBSCMEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEIMEvaluation::legacy_write_out_interpolation_points_elem(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DofMap::local_variable_indices(), main(), libMesh::MeshRefinement::make_coarsening_compatible(), AugmentSparsityOnInterface::mesh_reinit(), libMesh::MeshBase::n_active_local_elem(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::System::n_local_dofs(), libMesh::MeshBase::n_local_elem(), libMesh::MeshBase::n_local_nodes(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MetisPartitioner::partition_range(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::NumericVector< T >::print_global(), libMesh::Nemesis_IO_Helper::put_cmap_params(), libMesh::Nemesis_IO_Helper::put_elem_cmap(), libMesh::Nemesis_IO_Helper::put_elem_map(), libMesh::Nemesis_IO_Helper::put_loadbal_param(), libMesh::Nemesis_IO_Helper::put_node_cmap(), libMesh::Nemesis_IO_Helper::put_node_map(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::LaplaceMeshSmoother::smooth(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), BoundaryInfoTest::testShellFaceConstraints(), WriteVecAndScalar::testWrite(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::Parallel::Packing< Node * >::unpack(), libMesh::Parallel::Packing< Elem * >::unpack(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::DTKAdapter::update_variable_values(), libMesh::MeshTools::weight(), libMesh::NameBasedIO::write(), libMesh::CheckpointIO::write(), libMesh::XdrIO::write(), libMesh::EquationSystems::write(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::ExodusII_IO_Helper::write_element_values(), libMesh::ExodusII_IO_Helper::write_elements(), libMesh::ExodusII_IO::write_global_data(), libMesh::ExodusII_IO_Helper::write_global_values(), libMesh::ExodusII_IO::write_information_records(), libMesh::ExodusII_IO_Helper::write_information_records(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), libMesh::UCDIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::ExodusII_IO_Helper::write_nodal_values(), libMesh::Nemesis_IO_Helper::write_nodesets(), libMesh::ExodusII_IO_Helper::write_nodesets(), libMesh::RBEvaluation::write_out_vectors(), write_output_solvedata(), libMesh::RBConstruction::write_riesz_representors_to_files(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::Nemesis_IO_Helper::write_sidesets(), libMesh::ExodusII_IO_Helper::write_sidesets(), libMesh::ExodusII_IO::write_timestep(), and libMesh::ExodusII_IO_Helper::write_timestep().

100  { return cast_int<processor_id_type>(_communicator.rank()); }
const Parallel::Communicator & _communicator
unsigned int rank() const
Definition: parallel.h:724
template<typename KeyType , typename IdxType >
void libMesh::Parallel::Sort< KeyType, IdxType >::sort ( )

This is the only method which needs to be called by the user.

Its only responsibility is to call three private methods in the correct order.

Definition at line 58 of file parallel_sort.C.

References libMesh::Parallel::Sort< KeyType, IdxType >::_bin_is_sorted, libMesh::Parallel::Sort< KeyType, IdxType >::_data, libMesh::Parallel::Sort< KeyType, IdxType >::_local_bin_sizes, libMesh::Parallel::Sort< KeyType, IdxType >::_my_bin, libMesh::Parallel::Communicator::allgather(), libMesh::Parallel::Sort< KeyType, IdxType >::binsort(), libMesh::ParallelObject::comm(), libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins(), libMesh::ParallelObject::n_processors(), libMesh::Parallel::Sort< KeyType, IdxType >::sort_local_bin(), and libMesh::Parallel::Communicator::sum().

Referenced by libMesh::MeshCommunication::assign_global_indices(), and libMesh::MeshCommunication::find_global_indices().

59 {
60  // Find the global data size. The sorting
61  // algorithms assume they have a range to
62  // work with, so catch the degenerate cases here
63  IdxType global_data_size = cast_int<IdxType>(_data.size());
64 
65  this->comm().sum (global_data_size);
66 
67  if (global_data_size < 2)
68  {
69  // the entire global range is either empty
70  // or contains only one element
71  _my_bin = _data;
72 
73  this->comm().allgather (static_cast<IdxType>(_my_bin.size()),
75  }
76  else
77  {
78  if (this->n_processors() > 1)
79  {
80  this->binsort();
81  this->communicate_bins();
82  }
83  else
84  _my_bin = _data;
85 
86  this->sort_local_bin();
87  }
88 
89  // Set sorted flag to true
90  _bin_is_sorted = true;
91 }
processor_id_type n_processors() const
std::vector< KeyType > & _data
The raw, unsorted data which will need to be sorted (in parallel) across all processors.
std::vector< IdxType > _local_bin_sizes
Vector which holds the size of each bin on this processor.
void sort_local_bin()
After all the bins have been communicated, we can sort our local bin.
void communicate_bins()
Communicates the bins from each processor to the appropriate processor.
std::vector< KeyType > _my_bin
The bin which will eventually be held by this processor.
const Parallel::Communicator & comm() const
void sum(T &r) const
Take a local variable and replace it with the sum of it&#39;s values on all processors.
bool _bin_is_sorted
Flag which lets you know if sorting is complete.
Definition: parallel_sort.h:98
void binsort()
Sorts the local data into bins across all processors.
Definition: parallel_sort.C:96
void allgather(const T &send, std::vector< T > &recv) const
Take a vector of length this->size(), and fill in recv[processor_id] = the value of send on that proc...
template<typename KeyType , typename IdxType >
void libMesh::Parallel::Sort< KeyType, IdxType >::sort_local_bin ( )
private

After all the bins have been communicated, we can sort our local bin.

This is nothing more than a call to std::sort

Definition at line 368 of file parallel_sort.C.

References libMesh::Parallel::Sort< KeyType, IdxType >::_my_bin.

Referenced by libMesh::Parallel::Sort< KeyType, IdxType >::sort().

369 {
370  std::sort(_my_bin.begin(), _my_bin.end());
371 }
std::vector< KeyType > _my_bin
The bin which will eventually be held by this processor.

Member Data Documentation

template<typename KeyType, typename IdxType = unsigned int>
bool libMesh::Parallel::Sort< KeyType, IdxType >::_bin_is_sorted
private

Flag which lets you know if sorting is complete.

Definition at line 98 of file parallel_sort.h.

Referenced by libMesh::Parallel::Sort< KeyType, IdxType >::bin(), and libMesh::Parallel::Sort< KeyType, IdxType >::sort().

const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited
template<typename KeyType, typename IdxType = unsigned int>
std::vector<KeyType>& libMesh::Parallel::Sort< KeyType, IdxType >::_data
private
template<typename KeyType, typename IdxType = unsigned int>
std::vector<IdxType> libMesh::Parallel::Sort< KeyType, IdxType >::_local_bin_sizes
private
template<typename KeyType, typename IdxType = unsigned int>
std::vector<KeyType> libMesh::Parallel::Sort< KeyType, IdxType >::_my_bin
private

The bin which will eventually be held by this processor.

It may be shorter or longer than _data. It will be dynamically resized when it is needed.

Definition at line 120 of file parallel_sort.h.

Referenced by libMesh::Parallel::Sort< KeyType, IdxType >::bin(), libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), and libMesh::Parallel::Sort< KeyType, IdxType >::sort_local_bin().

template<typename KeyType, typename IdxType = unsigned int>
const processor_id_type libMesh::Parallel::Sort< KeyType, IdxType >::_n_procs
private
template<typename KeyType, typename IdxType = unsigned int>
const processor_id_type libMesh::Parallel::Sort< KeyType, IdxType >::_proc_id
private

The identity of this processor.

Definition at line 93 of file parallel_sort.h.

Referenced by libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins().


The documentation for this class was generated from the following files: