Sierra Toolkit Version of the Day
Comm.cpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 #include <stdexcept>
00010 #include <sstream>
00011 #include <algorithm>
00012 
00013 #include <stk_util/parallel/ParallelComm.hpp>
00014 #include <stk_util/parallel/ParallelReduce.hpp>
00015 
00016 #include <stk_mesh/base/MetaData.hpp>
00017 #include <stk_mesh/base/BulkData.hpp>
00018 #include <stk_mesh/base/FieldData.hpp>
00019 #include <stk_mesh/base/Comm.hpp>
00020 #include <stk_mesh/base/EntityComm.hpp>
00021 
00022 
00023 namespace stk {
00024 namespace mesh {
00025 
00026 bool comm_mesh_counts( BulkData & M ,
00027                        std::vector<size_t> & counts ,
00028                        bool local_flag )
00029 {
00030   const size_t zero = 0 ;
00031 
00032   // Count locally owned entities
00033 
00034   const MetaData & S = MetaData::get(M);
00035   const unsigned entity_rank_count = S.entity_rank_count();
00036   const size_t   comm_count        = entity_rank_count + 1 ;
00037 
00038   std::vector<size_t> local(  comm_count , zero );
00039   std::vector<size_t> global( comm_count , zero );
00040 
00041   ParallelMachine comm = M.parallel();
00042   Part & owns = S.locally_owned_part();
00043 
00044   for ( unsigned i = 0 ; i < entity_rank_count ; ++i ) {
00045     const std::vector<Bucket*> & ks = M.buckets( i );
00046 
00047     std::vector<Bucket*>::const_iterator ik ;
00048 
00049     for ( ik = ks.begin() ; ik != ks.end() ; ++ik ) {
00050       if ( has_superset( **ik , owns ) ) {
00051         local[i] += (*ik)->size();
00052       }
00053     }
00054   }
00055 
00056   local[ entity_rank_count ] = local_flag ;
00057 
00058   all_reduce_sum( comm , & local[0] , & global[0] , comm_count );
00059 
00060   counts.assign( global.begin() , global.begin() + entity_rank_count );
00061 
00062   return 0 < global[ entity_rank_count ] ;
00063 }
00064 
00065 //----------------------------------------------------------------------
00066 
00067 } // namespace mesh
00068 } // namespace stk
00069 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines