Loading [MathJax]/extensions/tex2jax.js
Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ReadWriteTest.cpp
Go to the documentation of this file.
1 /** @example ReadWriteTest.cpp \n 2  * \brief Read mesh into MOAB and write some back \n 3  * 4  * <b>To run</b>: mpiexec -np 4 ReadWriteTest [input] [output] -O [read_opts] -o [write_opts]\n 5  * 6  * used for stress test of reader/writer 7  * report times to read and write 8  * 9  * example ReadWriteTest ../MeshFiles/io/fv3x46x72.t.3.nc out.nc \ 10  * -O PARALLEL=READ_PART;PARTITION_METHOD=SQIJ;PARALLEL_RESOLVE_SHARED_ENTS;VARIABLE=T,U; \ 11  * -o PARALLEL=WRITE_PART;VARIABLE=T,U 12  */ 13  14 #include "moab/Core.hpp" 15 #ifdef MOAB_HAVE_MPI 16 #include "moab/ParallelComm.hpp" 17 #include "MBParallelConventions.h" 18 #endif 19 #include <iostream> 20 #include <ctime> 21  22 using namespace moab; 23 using namespace std; 24  25 int main( int argc, char** argv ) 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 }