Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
00001 /** @example ReadWriteTest.cpp \n 00002 * \brief Read mesh into MOAB and write some back \n 00003 * 00004 * <b>To run</b>: mpiexec -np 4 ReadWriteTest [input] [output] -O [read_opts] -o [write_opts]\n 00005 * 00006 * used for stress test of reader/writer 00007 * report times to read and write 00008 * 00009 * example ReadWriteTest ../MeshFiles/io/fv3x46x72.t.3.nc out.nc \ 00010 * -O PARALLEL=READ_PART;PARTITION_METHOD=SQIJ;PARALLEL_RESOLVE_SHARED_ENTS;VARIABLE=T,U; \ 00011 * -o PARALLEL=WRITE_PART;VARIABLE=T,U 00012 */ 00013 00014 #include "moab/Core.hpp" 00015 #ifdef MOAB_HAVE_MPI 00016 #include "moab/ParallelComm.hpp" 00017 #include "MBParallelConventions.h" 00018 #endif 00019 #include <iostream> 00020 #include <ctime> 00021 00022 using namespace moab; 00023 using namespace std; 00024 00025 int main( int argc, char** argv ) 00026 { 00027 #ifdef MOAB_HAVE_MPI 00028 string input_file, output_file, read_opts, write_opts; 00029 00030 MPI_Init( &argc, &argv ); 00031 00032 // Need option handling here for input filename 00033 if( argc < 3 ) 00034 { 00035 #ifdef MOAB_HAVE_NETCDF 00036 input_file = string( MESH_DIR ) + string( "/io/fv3x46x72.t.3.nc" ); 00037 output_file = "ReadWriteTestOut.h5m"; 00038 read_opts = "PARALLEL=READ_PART;PARTITION_METHOD=SQIJ;PARALLEL_RESOLVE_SHARED_ENTS;VARIABLE=T,U"; 00039 write_opts = "PARALLEL=WRITE_PART"; 00040 #else 00041 cout << "Usage: mpiexec -n $NP ReadWriteTest [input] [output] -O <read_opts> -o " 00042 "<write_opts>\n"; 00043 return 0; 00044 #endif 00045 } 00046 else 00047 { 00048 input_file = argv[1]; 00049 output_file = argv[2]; 00050 } 00051 00052 if( argc > 3 ) 00053 { 00054 int index = 3; 00055 while( index < argc ) 00056 { 00057 if( !strcmp( argv[index], "-O" ) ) // This is for reading options, optional 00058 read_opts = argv[++index]; 00059 if( !strcmp( argv[index], "-o" ) ) write_opts = argv[++index]; 00060 index++; 00061 } 00062 } 00063 00064 // Get MOAB instance 00065 Interface* mb = new( std::nothrow ) Core; 00066 if( NULL == mb ) return 1; 00067 00068 // Get the ParallelComm instance 00069 ParallelComm* pcomm = new ParallelComm( mb, MPI_COMM_WORLD ); 00070 int nprocs = pcomm->proc_config().proc_size(); 00071 int rank = pcomm->proc_config().proc_rank(); 00072 00073 EntityHandle set; 00074 ErrorCode rval = mb->create_meshset( MESHSET_SET, set );MB_CHK_ERR( rval ); 00075 00076 clock_t tt = clock(); 00077 00078 if( 0 == rank ) 00079 cout << "Reading file " << input_file << "\n with options: " << read_opts << "\n on " << nprocs 00080 << " processors\n"; 00081 00082 // Read the file with the specified options 00083 rval = mb->load_file( input_file.c_str(), &set, read_opts.c_str() );MB_CHK_ERR( rval ); 00084 00085 if( 0 == rank ) 00086 { 00087 cout << "Time: " << ( clock() - tt ) / (double)CLOCKS_PER_SEC << " seconds" << endl; 00088 tt = clock(); 00089 } 00090 00091 // Write back the file with the specified options 00092 rval = mb->write_file( output_file.c_str(), 0, write_opts.c_str(), &set, 1 );MB_CHK_ERR( rval ); 00093 00094 if( 0 == rank ) 00095 { 00096 cout << "Writing file " << output_file << "\n with options: " << write_opts << endl; 00097 cout << "Time: " << ( clock() - tt ) / (double)CLOCKS_PER_SEC << " seconds" << endl; 00098 tt = clock(); 00099 } 00100 00101 delete mb; 00102 00103 MPI_Finalize(); 00104 #else 00105 std::cout << " compile MOAB with mpi for this example to work\n"; 00106 #endif 00107 00108 return 0; 00109 }