59 bool use_defaults =
false;
65 std::cout <<
"Usage: mpiexec -np <num_procs> " << program_name <<
" [input_file] [output_file] [options]\n"
67 <<
" -O <read_opts> Options for reading the input file\n"
68 <<
" -o <write_opts> Options for writing the output file\n"
70 <<
" mpiexec -np 4 " << program_name <<
" input.nc output.h5m \\\n"
71 <<
" -O \"PARALLEL=READ_PART;PARTITION_METHOD=SQIJ\" \\n"
72 <<
" -o \"PARALLEL=WRITE_PART\"\n";
81 #ifdef MOAB_HAVE_NETCDF
84 config.
read_opts =
"PARALLEL=READ_PART;PARTITION_METHOD=SQIJ;PARALLEL_RESOLVE_SHARED_ENTS;VARIABLE=T,U";
104 for(
int i = 3; i < argc; ++i )
106 std::string arg = argv[i];
107 if( arg ==
"-O" && i + 1 < argc )
111 else if( arg ==
"-o" && i + 1 < argc )
115 else if( arg ==
"-h" || arg ==
"--help" )
130 std::cout <<
"\n=== MOAB Parallel Read/Write Test ===\n"
131 <<
"Input file: " << config.
input_file <<
"\n"
133 <<
"Read options: " << ( config.
read_opts.empty() ?
"(default)" : config.
read_opts ) <<
"\n"
135 <<
"Running on " << nprocs <<
" MPI processes\n"
141 int main(
int argc,
char** argv )
144 int mpi_initialized = 0;
145 MPI_Initialized( &mpi_initialized );
146 if( !mpi_initialized )
148 MPI_Init( &argc, &argv );
153 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
154 MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
166 auto moab = std::make_unique< Core >();
169 std::cerr <<
"Error: Failed to create MOAB instance" << std::endl;
170 MPI_Abort( MPI_COMM_WORLD, 1 );
174 auto pcomm = std::make_unique< ParallelComm >(
moab.get(), MPI_COMM_WORLD );
181 auto read_start = std::chrono::high_resolution_clock::now();
185 std::cout <<
"Reading mesh file..." << std::endl;
189 MB_CHK_SET_ERR(
moab->load_file( config.input_file.c_str(), &mesh_set, config.read_opts.c_str() ),
190 "Failed to read input file: " << config.input_file );
192 auto read_end = std::chrono::high_resolution_clock::now();
193 std::chrono::duration< double > read_elapsed = read_end - read_start;
197 std::cout <<
"Read completed in " << read_elapsed.count() <<
" seconds" << std::endl;
198 std::cout <<
"Writing mesh file..." << std::endl;
202 auto write_start = std::chrono::high_resolution_clock::now();
205 MB_CHK_SET_ERR(
moab->write_file( config.output_file.c_str(),
nullptr, config.write_opts.c_str(), &mesh_set,
207 "Failed to write output file: " << config.output_file );
209 auto write_end = std::chrono::high_resolution_clock::now();
210 std::chrono::duration< double > write_elapsed = write_end - write_start;
214 std::cout <<
"Write completed in " << write_elapsed.count() <<
" seconds" << std::endl;
215 std::cout <<
"\n=== Test completed successfully ===" << std::endl;
223 if( !mpi_initialized )
230 catch(
const std::exception& e )
232 std::cerr <<
"Error on rank " << rank <<
": " << e.what() << std::endl;
233 MPI_Abort( MPI_COMM_WORLD, 1 );
238 std::cerr <<
"Unknown error occurred on rank " << rank << std::endl;
239 MPI_Abort( MPI_COMM_WORLD, 1 );