Sierra Toolkit  Version of the Day
Comm.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 #include <stdexcept>
10 #include <sstream>
11 #include <algorithm>
12 
13 #include <stk_util/parallel/ParallelComm.hpp>
14 #include <stk_util/parallel/ParallelReduce.hpp>
15 
16 #include <stk_mesh/base/MetaData.hpp>
17 #include <stk_mesh/base/BulkData.hpp>
18 #include <stk_mesh/base/FieldData.hpp>
19 #include <stk_mesh/base/Comm.hpp>
20 #include <stk_mesh/base/EntityComm.hpp>
21 
22 
23 namespace stk_classic {
24 namespace mesh {
25 
27  std::vector<size_t> & counts ,
28  bool local_flag )
29 {
30  const size_t zero = 0 ;
31 
32  // Count locally owned entities
33 
34  const MetaData & S = MetaData::get(M);
35  const unsigned entity_rank_count = S.entity_rank_count();
36  const size_t comm_count = entity_rank_count + 1 ;
37 
38  std::vector<size_t> local( comm_count , zero );
39  std::vector<size_t> global( comm_count , zero );
40 
41  ParallelMachine comm = M.parallel();
42  Part & owns = S.locally_owned_part();
43 
44  for ( unsigned i = 0 ; i < entity_rank_count ; ++i ) {
45  const std::vector<Bucket*> & ks = M.buckets( i );
46 
47  std::vector<Bucket*>::const_iterator ik ;
48 
49  for ( ik = ks.begin() ; ik != ks.end() ; ++ik ) {
50  if ( has_superset( **ik , owns ) ) {
51  local[i] += (*ik)->size();
52  }
53  }
54  }
55 
56  local[ entity_rank_count ] = local_flag ;
57 
58  all_reduce_sum( comm , & local[0] , & global[0] , comm_count );
59 
60  counts.assign( global.begin() , global.begin() + entity_rank_count );
61 
62  return 0 < global[ entity_rank_count ] ;
63 }
64 
65 //----------------------------------------------------------------------
66 
67 } // namespace mesh
68 } // namespace stk_classic
69 
bool comm_mesh_counts(BulkData &M, std::vector< size_t > &counts, bool local_flag)
Global counts for a mesh&#39;s entities.
Definition: Comm.cpp:26
bool has_superset(const Bucket &bucket, const unsigned &ordinal)
Is this bucket a subset of the given part by partID.
Definition: Bucket.cpp:127
The manager of an integrated collection of parts and fields.
Definition: MetaData.hpp:56
void all_reduce_sum(ParallelMachine comm, const double *local, double *global, unsigned count)
Parallel summation to all processors.
const std::vector< Bucket * > & buckets(EntityRank rank) const
Query all buckets of a given entity rank.
Definition: BulkData.hpp:195
An application-defined subset of a problem domain.
Definition: Part.hpp:49
ParallelMachine parallel() const
The parallel machine.
Definition: BulkData.hpp:79
Part & locally_owned_part() const
Subset for the problem domain that is owned by the local process. Ghost entities are not members of t...
Definition: MetaData.hpp:93
Manager for an integrated collection of entities, entity relations, and buckets of field data...
Definition: BulkData.hpp:49
Sierra Toolkit.
MPI_Comm ParallelMachine
Definition: Parallel.hpp:32