Go to the documentation of this file. 1
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
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" ) )
58 read_opts = argv[++index];
59 if( !strcmp( argv[index], "-o" ) ) write_opts = argv[++index];
60 index++;
61 }
62 }
63
64
65 Interface* mb = new( std::nothrow ) Core;
66 if( NULL == mb ) return 1;
67
68
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
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
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 }