{
int nprocs, rank;
#ifdef USE_MPI
MPI_Init( &argc, &argv );
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#else // USE_MPI
nprocs = 1;
rank = 0;
#endif // USE_MPI
std::string ifname = argc > 1 ? argv[1] : TestDir + "fourVolsBare.cub";
bool input_is_output, do_output = false;
std::string output_filename;
if ( argc > 2) {
if (!strcmp( argv[2], "-new-mesh" )) input_is_output = true;
else {
do_output = true;
output_filename = std::string(argv[2]);
}
}
Interface* imesh = new Core;
Interface* omesh = input_is_output ? imesh : new Core;
#ifdef USE_MPI
ParallelComm* ipcomm = new ParallelComm( imesh, MPI_COMM_WORLD );
#endif // USE_MPI
EntityHandle set_handle;
std::ostringstream parallel_options;
#ifdef USE_MPI
parallel_options
<< "PARALLEL=READ_DELETE" << ";"
<< "PARTITION=MATERIAL_SET" << ";"
<< "PARTITION_DISTRIBUTE" << ";"
<< "PARALLEL_RESOLVE_SHARED_ENTS" << ";"
<< "CPUTIME";
#endif
ErrorCode rval = imesh->create_meshset(MESHSET_SET, set_handle);
if (MB_SUCCESS != rval) {
std::cout << "Trouble creating set, exiting." << std::endl;
return 1;
}
rval = imesh->load_file( ifname.c_str(), &set_handle, parallel_options.str().c_str() );
if (MB_SUCCESS != rval) {
std::cout << "Trouble reading mesh file " << ifname << ", exiting." << std::endl;
return 1;
}
for ( int i = 0; i < nprocs; ++ i )
{
MPI_Barrier( MPI_COMM_WORLD );
if ( i == rank )
{
std::cout << "\n************** Rank: " << ( rank ) << " of: " << nprocs << "\n";
imesh->list_entities( 0, 0 );
std::cout << "**************\n\n";
}
MPI_Barrier( MPI_COMM_WORLD );
}
EdgeSizeSimpleImplicit* eval = new EdgeSizeSimpleImplicit();
eval->set_ratio( 2. );
MeshRefiner* mref = new MeshRefiner( imesh, omesh );
SimplexTemplateRefiner* eref = new SimplexTemplateRefiner;
mref->set_entity_refiner( eref );
eref->set_edge_size_evaluator( eval );
Range ents_to_refine;
imesh->get_entities_by_type( set_handle, MBTET, ents_to_refine );
struct timeval tic, toc;
gettimeofday( &tic, 0 );
mref->refine( ents_to_refine );
gettimeofday( &toc, 0 );
std::cout << "\nTime: " << ( (toc.tv_sec - tic.tv_sec) * 1000 + (toc.tv_usec - tic.tv_usec) / 1000. ) << " ms\n\n";
if (do_output) {
parallel_options.clear();
parallel_options << "PARALLEL=WRITE_PART";
omesh->write_file( output_filename.c_str(), NULL, parallel_options.str().c_str() );
}
#ifdef USE_MPI
for ( int i = 0; i < nprocs; ++ i )
{
MPI_Barrier( MPI_COMM_WORLD );
if ( i == rank )
{
std::cout << "\n************** Rank: " << ( rank ) << " of: " << nprocs << "\n";
omesh->list_entities( 0, 0 );
std::cout << "**************\n\n";
}
MPI_Barrier( MPI_COMM_WORLD );
}
#else // USE_MPI
omesh->list_entities( 0, 1 );
#endif // USE_MPI
#ifdef USE_MPI
delete ipcomm;
#endif // USE_MPI
if ( omesh != imesh )
delete omesh;
delete imesh;
delete mref;
#ifdef USE_MPI
MPI_Barrier( MPI_COMM_WORLD );
MPI_Finalize();
#endif // USE_MPI
return 0;
}