MOAB: Mesh Oriented datABase  (version 5.5.0)
read_esmf.cpp
Go to the documentation of this file.
1 #include "TestUtil.hpp"
2 #include "moab/Core.hpp"
3 #include "moab/ParallelComm.hpp"
4 #include "moab/ProgOptions.hpp"
6 #include "moab/ReadUtilIface.hpp"
7 #include "MBTagConventions.hpp"
8 
9 #include <sstream>
10 
11 using namespace moab;
12 
13 std::string example = TestDir + "unittest/io/ne4np4-esmf.nc";
14 
15 std::string read_options;
16 const double eps = 1e-20;
17 
18 
19 void read_mesh_parallel( bool rcbzoltan, bool no_mixed_elements )
20 {
21  Core moab;
22  Interface& mb = moab;
23 
24  read_options = "PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS;VARIABLE=";
25  if( rcbzoltan )
26  read_options = "PARALLEL=READ_PART;PARTITION_METHOD=RCBZOLTAN;PARALLEL_RESOLVE_SHARED_ENTS;VARIABLE=";
27 
28  if( no_mixed_elements ) read_options += ";NO_MIXED_ELEMENTS";
29 
30  ErrorCode rval = mb.load_file( example.c_str(), NULL, read_options.c_str() );CHECK_ERR( rval );
31 
32  ParallelComm* pcomm = ParallelComm::get_pcomm( &mb, 0 );
33  int procs = pcomm->proc_config().proc_size();
34  int rank = pcomm->proc_config().proc_rank();
35 
36  rval = pcomm->check_all_shared_handles();CHECK_ERR( rval );
37 
38  // Get local vertices
39  Range local_verts;
40  rval = mb.get_entities_by_type( 0, MBVERTEX, local_verts );CHECK_ERR( rval );
41 
42  int verts_num = local_verts.size();
43  if( 2 == procs )
44  {
45  if( rcbzoltan )
46  {
47  if( 0 == rank )
48  CHECK_EQUAL( 457, verts_num );
49  else if( 1 == rank )
50  CHECK_EQUAL( 457, verts_num ); // Not owned vertices included
51  }
52  else
53  {
54  if( 0 == rank )
55  CHECK_EQUAL( 485, verts_num );
56  else if( 1 == rank )
57  CHECK_EQUAL( 471, verts_num ); // Not owned vertices included
58  }
59  }
60 
61  rval = pcomm->filter_pstatus( local_verts, PSTATUS_NOT_OWNED, PSTATUS_NOT );CHECK_ERR( rval );
62 
63  verts_num = local_verts.size();
64  if( 2 == procs )
65  {
66  if( rcbzoltan )
67  {
68  if( 0 == rank )
69  CHECK_EQUAL( 457, verts_num );
70  else if( 1 == rank )
71  CHECK_EQUAL( 409, verts_num ); // Not owned vertices excluded
72  }
73  else
74  {
75  if( 0 == rank )
76  CHECK_EQUAL( 485, verts_num );
77  else if( 1 == rank )
78  CHECK_EQUAL( 381, verts_num ); // Not owned vertices excluded
79  }
80  }
81 
82  // Get local cells
83  Range local_cells;
84 
85  rval = mb.get_entities_by_dimension( 0, 2, local_cells );CHECK_ERR( rval );
86 
87  rval = pcomm->filter_pstatus( local_cells, PSTATUS_NOT_OWNED, PSTATUS_NOT );CHECK_ERR( rval );
88 
89  int cells_num = (int)local_cells.size();
90  if( 2 == procs )
91  {
92  CHECK_EQUAL( 468, cells_num );
93  }
94 
95  std::cout << "proc: " << rank << " cells:" << cells_num << "\n";
96 
97  int total_cells_num;
98  MPI_Reduce( &cells_num, &total_cells_num, 1, MPI_INT, MPI_SUM, 0, pcomm->proc_config().proc_comm() );
99  if( 0 == rank )
100  {
101  std::cout << "total cells: " << total_cells_num << "\n";
102  CHECK_EQUAL( 936, total_cells_num );
103  }
104 
105 #ifdef MOAB_HAVE_HDF5_PARALLEL
106  std::string write_options( "PARALLEL=WRITE_PART;" );
107 
108  std::string output_file = "test_esmf";
109  if( rcbzoltan ) output_file += "_rcbzoltan";
110  if( no_mixed_elements ) output_file += "_no_mixed_elements";
111  output_file += ".h5m";
112 
113  mb.write_file( output_file.c_str(), NULL, write_options.c_str() );
114 #endif
115 }
116 
117 
119 {
120  read_mesh_parallel( false, false );
121 }
122 
124 {
125  read_mesh_parallel( false, true );
126 }
127 
129 {
130  read_mesh_parallel( true, false );
131 }
132 
134 {
135  read_mesh_parallel( true, true );
136 }
137 
138 
139 int main( int argc, char* argv[] )
140 {
141  MPI_Init( &argc, &argv );
142  int result = 0;
143 
146 #if defined( MOAB_HAVE_MPI ) && defined( MOAB_HAVE_ZOLTAN )
149 #endif
150 
151  MPI_Finalize();
152  return result;
153 }