1 | #include <cstdlib> |
---|
2 | #include <iostream> |
---|
3 | #include <iomanip> |
---|
4 | #include <string> |
---|
5 | #include <algorithm> |
---|
6 | #include <limits> |
---|
7 | #include <stdexcept> |
---|
8 | #include <stdint.h> |
---|
9 | |
---|
10 | #include "GenericIO.h" |
---|
11 | |
---|
12 | using namespace gio; |
---|
13 | using namespace std; |
---|
14 | |
---|
15 | int main(int argc, char *argv[]) { |
---|
16 | #ifndef GENERICIO_NO_MPI |
---|
17 | MPI_Init(&argc, &argv); |
---|
18 | #endif |
---|
19 | |
---|
20 | if (argc < 2) { |
---|
21 | cerr << "Usage: " << argv[0] << " [-v] <mpiioName1> <mpiioName2> ..." << endl; |
---|
22 | exit(-1); |
---|
23 | } |
---|
24 | |
---|
25 | int arg = 1; |
---|
26 | bool Verbose = false; |
---|
27 | if (string(argv[arg]) == "-v") { |
---|
28 | Verbose = true; |
---|
29 | ++arg; |
---|
30 | } |
---|
31 | |
---|
32 | int Rank, NRanks; |
---|
33 | #ifndef GENERICIO_NO_MPI |
---|
34 | MPI_Comm_rank(MPI_COMM_WORLD, &Rank); |
---|
35 | MPI_Comm_size(MPI_COMM_WORLD, &NRanks); |
---|
36 | #else |
---|
37 | Rank = 0; |
---|
38 | NRanks = 1; |
---|
39 | #endif |
---|
40 | |
---|
41 | bool AllOkay = true; |
---|
42 | |
---|
43 | for (; arg < argc; ++arg) { |
---|
44 | string FileName(argv[arg]); |
---|
45 | |
---|
46 | try { |
---|
47 | if (Verbose) cout << "verifying: " << FileName << endl; |
---|
48 | |
---|
49 | unsigned Method = GenericIO::FileIOPOSIX; |
---|
50 | #ifndef GENERICIO_NO_MPI |
---|
51 | const char *EnvStr = getenv("GENERICIO_USE_MPIIO"); |
---|
52 | if (EnvStr && string(EnvStr) == "1") |
---|
53 | Method = GenericIO::FileIOMPI; |
---|
54 | #endif |
---|
55 | |
---|
56 | #ifndef GENERICIO_NO_MPI |
---|
57 | GenericIO GIO(MPI_COMM_WORLD, FileName, Method); |
---|
58 | #else |
---|
59 | GenericIO GIO(FileName, Method); |
---|
60 | #endif |
---|
61 | |
---|
62 | #ifndef GENERICIO_NO_MPI |
---|
63 | bool MustMatch = true; |
---|
64 | #else |
---|
65 | bool MustMatch = false; |
---|
66 | #endif |
---|
67 | GIO.openAndReadHeader(MustMatch); |
---|
68 | if (Verbose) cout << "\theader: okay" << endl; |
---|
69 | |
---|
70 | |
---|
71 | vector<GenericIO::VariableInfo> VI; |
---|
72 | GIO.getVariableInfo(VI); |
---|
73 | |
---|
74 | #ifndef GENERICIO_NO_MPI |
---|
75 | size_t MaxNElem = GIO.readNumElems(); |
---|
76 | #else |
---|
77 | size_t MaxNElem = 0; |
---|
78 | int NR = GIO.readNRanks(); |
---|
79 | for (int i = 0; i < NR; ++i) { |
---|
80 | size_t NElem = GIO.readNumElems(i); |
---|
81 | MaxNElem = max(MaxNElem, NElem); |
---|
82 | } |
---|
83 | #endif |
---|
84 | |
---|
85 | vector< vector<char> > Vars(VI.size()); |
---|
86 | for (size_t i = 0; i < VI.size(); ++i) { |
---|
87 | Vars[i].resize(VI[i].Size*MaxNElem + GIO.requestedExtraSpace()); |
---|
88 | GIO.addVariable(VI[i], &Vars[i][0], true); |
---|
89 | } |
---|
90 | |
---|
91 | #ifndef GENERICIO_NO_MPI |
---|
92 | GIO.readData(-1, false); |
---|
93 | if (Verbose) cout << "\tdata from rank " << Rank << ": okay" << endl; |
---|
94 | #else |
---|
95 | for (int i = 0; i < NR; ++i) { |
---|
96 | GIO.readData(i, false); |
---|
97 | if (Verbose) cout << "\tdata from rank " << i << ": okay" << endl; |
---|
98 | } |
---|
99 | #endif |
---|
100 | |
---|
101 | if (Rank == 0) { |
---|
102 | cout << FileName << ": okay" << endl; |
---|
103 | cout.flush(); |
---|
104 | } |
---|
105 | } catch (exception &e) { |
---|
106 | cerr << "ERROR: " << FileName << ": " << e.what() << endl; |
---|
107 | cerr.flush(); |
---|
108 | AllOkay = false; |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | #ifndef GENERICIO_NO_MPI |
---|
113 | MPI_Barrier(MPI_COMM_WORLD); |
---|
114 | MPI_Finalize(); |
---|
115 | #endif |
---|
116 | |
---|
117 | return AllOkay ? 0 : 1; |
---|
118 | } |
---|
119 | |
---|