44 #define MPICHKERR( CODE, MSG ) \
49 cerr << ( MSG ) << endl; \
54 #define dbgprint( MSG ) \
57 if( !rank ) cerr << MSG << endl; \
60 #define dbgprintall( MSG ) \
63 cerr << "[" << rank << "]: " << MSG << endl; \
71 filename = string( argv[1] );
73 filename = string(
MESH_DIR ) + string(
"/64bricks_1khex.h5m" );
77 tagName = string( argv[2] );
82 tagValues = atof( argv[3] );
92 int main(
int argc,
char** argv )
97 string filename, tagName;
99 MPI_Comm comm = MPI_COMM_WORLD;
109 string read_options =
"PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_"
110 "ENTS;PARTITION_DISTRIBUTE;PARALLEL_GHOSTS=3.0.1;PARALLEL_COMM=0";
116 cerr << argv[0] <<
" <file_name> <tag_name> <tag_value>" << endl;
117 cerr <<
"file_name : mesh file name" << endl;
118 cerr <<
"tag_name : name of tag to add to mesh" << endl;
119 cerr <<
"tag_value : a double valued string to set for highest-dimensional entities in "
120 "the mesh for the named tag"
123 ierr = MPI_Finalize();
124 MPICHKERR( ierr,
"MPI_Finalize failed; Aborting" );
130 ierr = MPI_Init( &argc, &argv );
133 ierr = MPI_Comm_rank( MPI_COMM_WORLD, &rank );
134 MPICHKERR( ierr,
"MPI_Comm_rank failed" );
136 dbgprint(
"********** reduce_exchange_tags **********\n" );
140 if( NULL == mbi )
return 1;
147 dbgprint(
" Filenames: " << filename );
148 dbgprint(
" Tag: Name=" << tagName <<
" Value=" << tagValue << endl );
160 err = mbi->
load_file( filename.c_str(), &rootset, read_options.c_str() );
MB_CHK_SET_ERR( err,
"MOAB::load_file failed" );
163 dbgprint(
"-Creating tag handle " << tagName <<
"..." );
164 Tag tagReduce, tagExchange;
168 sstr << tagName <<
"_EXC";
170 &tagValue );
MB_CHK_SET_ERR( err,
"Retrieving tag handles failed" );
174 sstr << tagName <<
"_RED";
176 &tagValue );
MB_CHK_SET_ERR( err,
"Retrieving tag handles failed" );
180 dbgprint(
"-Exchanging tags between processors " );
182 Range partEnts, dimEnts;
188 vector< int > tagValues( dimEnts.
size(),
static_cast< int >( tagValue ) * ( rank + 1 ) * (
dim + 1 ) );
190 err = mbi->
tag_set_data( tagExchange, dimEnts, &tagValues[0] );
MB_CHK_SET_ERR( err,
"Setting local tag data failed during exchange phase" );
192 partEnts.
merge( dimEnts );
196 err = parallel_communicator->
exchange_tags( tagExchange, partEnts );
MB_CHK_SET_ERR( err,
"Exchanging tags between processors failed" );
200 dbgprint(
"-Reducing tags between processors " );
211 vector< double > tagValues( partEnts.
size(), tagValue * ( rank + 1 ) );
212 err = mbi->
tag_set_data( tagReduce, partEnts, &tagValues[0] );
MB_CHK_SET_ERR( err,
"Setting local tag data failed during reduce phase" );
216 err = parallel_communicator->
reduce_tags( tagReduce, MPI_SUM, dummy );
MB_CHK_SET_ERR( err,
"Reducing tags between processors failed" );
224 dbgprint(
"\n********** reduce_exchange_tags DONE! **********" );
228 std::cout <<
" compile with MPI and HDF5 for this example to work \n";