Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
ReadWriteTest.cpp File Reference
#include "moab/Core.hpp"
#include <iostream>
#include <ctime>
+ Include dependency graph for ReadWriteTest.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
Examples
ReadWriteTest.cpp.

Definition at line 25 of file ReadWriteTest.cpp.

26 {
27 #ifdef MOAB_HAVE_MPI
28  string input_file, output_file, read_opts, write_opts;
29 
30  MPI_Init( &argc, &argv );
31 
32  // Need option handling here for input filename
33  if( argc < 3 )
34  {
35 #ifdef MOAB_HAVE_NETCDF
36  input_file = string( MESH_DIR ) + string( "/io/fv3x46x72.t.3.nc" );
37  output_file = "ReadWriteTestOut.h5m";
38  read_opts = "PARALLEL=READ_PART;PARTITION_METHOD=SQIJ;PARALLEL_RESOLVE_SHARED_ENTS;VARIABLE=T,U";
39  write_opts = "PARALLEL=WRITE_PART";
40 #else
41  cout << "Usage: mpiexec -n $NP ReadWriteTest [input] [output] -O <read_opts> -o "
42  "<write_opts>\n";
43  return 0;
44 #endif
45  }
46  else
47  {
48  input_file = argv[1];
49  output_file = argv[2];
50  }
51 
52  if( argc > 3 )
53  {
54  int index = 3;
55  while( index < argc )
56  {
57  if( !strcmp( argv[index], "-O" ) ) // This is for reading options, optional
58  read_opts = argv[++index];
59  if( !strcmp( argv[index], "-o" ) ) write_opts = argv[++index];
60  index++;
61  }
62  }
63 
64  // Get MOAB instance
65  Interface* mb = new( std::nothrow ) Core;
66  if( NULL == mb ) return 1;
67 
68  // Get the ParallelComm instance
69  ParallelComm* pcomm = new ParallelComm( mb, MPI_COMM_WORLD );
70  int nprocs = pcomm->proc_config().proc_size();
71  int rank = pcomm->proc_config().proc_rank();
72 
73  EntityHandle set;
74  ErrorCode rval = mb->create_meshset( MESHSET_SET, set );MB_CHK_ERR( rval );
75 
76  clock_t tt = clock();
77 
78  if( 0 == rank )
79  cout << "Reading file " << input_file << "\n with options: " << read_opts << "\n on " << nprocs
80  << " processors\n";
81 
82  // Read the file with the specified options
83  rval = mb->load_file( input_file.c_str(), &set, read_opts.c_str() );MB_CHK_ERR( rval );
84 
85  if( 0 == rank )
86  {
87  cout << "Time: " << ( clock() - tt ) / (double)CLOCKS_PER_SEC << " seconds" << endl;
88  tt = clock();
89  }
90 
91  // Write back the file with the specified options
92  rval = mb->write_file( output_file.c_str(), 0, write_opts.c_str(), &set, 1 );MB_CHK_ERR( rval );
93 
94  if( 0 == rank )
95  {
96  cout << "Writing file " << output_file << "\n with options: " << write_opts << endl;
97  cout << "Time: " << ( clock() - tt ) / (double)CLOCKS_PER_SEC << " seconds" << endl;
98  tt = clock();
99  }
100 
101  delete mb;
102 
103  MPI_Finalize();
104 #else
105  std::cout << " compile MOAB with mpi for this example to work\n";
106 #endif
107 
108  return 0;
109 }

References moab::Core::create_meshset(), ErrorCode, input_file, moab::Core::load_file(), mb, MB_CHK_ERR, MESH_DIR, MESHSET_SET, moab::ParallelComm::proc_config(), moab::ProcConfig::proc_rank(), moab::ProcConfig::proc_size(), and moab::Core::write_file().