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