1 | /* |
---|
2 | * Copyright (C) 2015, UChicago Argonne, LLC |
---|
3 | * All Rights Reserved |
---|
4 | * |
---|
5 | * Generic IO (ANL-15-066) |
---|
6 | * Hal Finkel, Argonne National Laboratory |
---|
7 | * |
---|
8 | * OPEN SOURCE LICENSE |
---|
9 | * |
---|
10 | * Under the terms of Contract No. DE-AC02-06CH11357 with UChicago Argonne, |
---|
11 | * LLC, the U.S. Government retains certain rights in this software. |
---|
12 | * |
---|
13 | * Redistribution and use in source and binary forms, with or without |
---|
14 | * modification, are permitted provided that the following conditions are met: |
---|
15 | * |
---|
16 | * 1. Redistributions of source code must retain the above copyright notice, |
---|
17 | * this list of conditions and the following disclaimer. |
---|
18 | * |
---|
19 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
20 | * notice, this list of conditions and the following disclaimer in the |
---|
21 | * documentation and/or other materials provided with the distribution. |
---|
22 | * |
---|
23 | * 3. Neither the names of UChicago Argonne, LLC or the Department of Energy |
---|
24 | * nor the names of its contributors may be used to endorse or promote |
---|
25 | * products derived from this software without specific prior written |
---|
26 | * permission. |
---|
27 | * |
---|
28 | * ***************************************************************************** |
---|
29 | * |
---|
30 | * DISCLAIMER |
---|
31 | * THE SOFTWARE IS SUPPLIED “AS IS” WITHOUT WARRANTY OF ANY KIND. NEITHER THE |
---|
32 | * UNTED STATES GOVERNMENT, NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR |
---|
33 | * UCHICAGO ARGONNE, LLC, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, |
---|
34 | * EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE |
---|
35 | * ACCURACY, COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, DATA, APPARATUS, |
---|
36 | * PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE |
---|
37 | * PRIVATELY OWNED RIGHTS. |
---|
38 | * |
---|
39 | * ***************************************************************************** |
---|
40 | */ |
---|
41 | |
---|
42 | #include <cstdlib> |
---|
43 | #include <iostream> |
---|
44 | #include <iomanip> |
---|
45 | #include <string> |
---|
46 | #include <algorithm> |
---|
47 | #include <limits> |
---|
48 | #include <stdexcept> |
---|
49 | #include <stdint.h> |
---|
50 | |
---|
51 | #include "GenericIO.h" |
---|
52 | |
---|
53 | using namespace gio; |
---|
54 | using namespace std; |
---|
55 | |
---|
56 | int main(int argc, char *argv[]) { |
---|
57 | #ifndef GENERICIO_NO_MPI |
---|
58 | MPI_Init(&argc, &argv); |
---|
59 | #endif |
---|
60 | |
---|
61 | if (argc < 2) { |
---|
62 | cerr << "Usage: " << argv[0] << " [-v] <mpiioName1> <mpiioName2> ..." << endl; |
---|
63 | exit(-1); |
---|
64 | } |
---|
65 | |
---|
66 | int arg = 1; |
---|
67 | bool Verbose = false; |
---|
68 | if (string(argv[arg]) == "-v") { |
---|
69 | Verbose = true; |
---|
70 | ++arg; |
---|
71 | } |
---|
72 | |
---|
73 | int Rank, NRanks; |
---|
74 | #ifndef GENERICIO_NO_MPI |
---|
75 | MPI_Comm_rank(MPI_COMM_WORLD, &Rank); |
---|
76 | MPI_Comm_size(MPI_COMM_WORLD, &NRanks); |
---|
77 | #else |
---|
78 | Rank = 0; |
---|
79 | NRanks = 1; |
---|
80 | #endif |
---|
81 | |
---|
82 | bool AllOkay = true; |
---|
83 | |
---|
84 | for (; arg < argc; ++arg) { |
---|
85 | string FileName(argv[arg]); |
---|
86 | |
---|
87 | try { |
---|
88 | if (Verbose) cout << "verifying: " << FileName << endl; |
---|
89 | |
---|
90 | unsigned Method = GenericIO::FileIOPOSIX; |
---|
91 | #ifndef GENERICIO_NO_MPI |
---|
92 | const char *EnvStr = getenv("GENERICIO_USE_MPIIO"); |
---|
93 | if (EnvStr && string(EnvStr) == "1") |
---|
94 | Method = GenericIO::FileIOMPI; |
---|
95 | #endif |
---|
96 | |
---|
97 | #ifndef GENERICIO_NO_MPI |
---|
98 | GenericIO GIO(MPI_COMM_WORLD, FileName, Method); |
---|
99 | #else |
---|
100 | GenericIO GIO(FileName, Method); |
---|
101 | #endif |
---|
102 | |
---|
103 | #ifndef GENERICIO_NO_MPI |
---|
104 | bool MustMatch = true; |
---|
105 | #else |
---|
106 | bool MustMatch = false; |
---|
107 | #endif |
---|
108 | GIO.openAndReadHeader(MustMatch); |
---|
109 | if (Verbose) cout << "\theader: okay" << endl; |
---|
110 | |
---|
111 | |
---|
112 | vector<GenericIO::VariableInfo> VI; |
---|
113 | GIO.getVariableInfo(VI); |
---|
114 | |
---|
115 | #ifndef GENERICIO_NO_MPI |
---|
116 | size_t MaxNElem = GIO.readNumElems(); |
---|
117 | #else |
---|
118 | size_t MaxNElem = 0; |
---|
119 | int NR = GIO.readNRanks(); |
---|
120 | for (int i = 0; i < NR; ++i) { |
---|
121 | size_t NElem = GIO.readNumElems(i); |
---|
122 | MaxNElem = max(MaxNElem, NElem); |
---|
123 | } |
---|
124 | #endif |
---|
125 | |
---|
126 | vector< vector<char> > Vars(VI.size()); |
---|
127 | for (size_t i = 0; i < VI.size(); ++i) { |
---|
128 | Vars[i].resize(VI[i].Size*MaxNElem + GIO.requestedExtraSpace()); |
---|
129 | GIO.addVariable(VI[i], &Vars[i][0], true); |
---|
130 | } |
---|
131 | |
---|
132 | #ifndef GENERICIO_NO_MPI |
---|
133 | GIO.readData(-1, false); |
---|
134 | if (Verbose) cout << "\tdata from rank " << Rank << ": okay" << endl; |
---|
135 | #else |
---|
136 | for (int i = 0; i < NR; ++i) { |
---|
137 | GIO.readData(i, false); |
---|
138 | if (Verbose) cout << "\tdata from rank " << i << ": okay" << endl; |
---|
139 | } |
---|
140 | #endif |
---|
141 | |
---|
142 | if (Rank == 0) { |
---|
143 | cout << FileName << ": okay" << endl; |
---|
144 | cout.flush(); |
---|
145 | } |
---|
146 | } catch (exception &e) { |
---|
147 | cerr << "ERROR: " << FileName << ": " << e.what() << endl; |
---|
148 | cerr.flush(); |
---|
149 | AllOkay = false; |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | #ifndef GENERICIO_NO_MPI |
---|
154 | MPI_Barrier(MPI_COMM_WORLD); |
---|
155 | MPI_Finalize(); |
---|
156 | #endif |
---|
157 | |
---|
158 | return AllOkay ? 0 : 1; |
---|
159 | } |
---|
160 | |
---|