source: GenericIOVerify.cxx @ 8f0a211

Revision 8f0a211, 4.6 KB checked in by Hal Finkel <hfinkel@…>, 8 years ago (diff)

Add redistribution support

  • Property mode set to 100644
Line 
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
53using namespace gio;
54using namespace std;
55
56int 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 ? GenericIO::MismatchRedistribute :
109                                        GenericIO::MismatchDisallowed);
110      if (Verbose) cout << "\theader: okay" << endl;
111
112
113      vector<GenericIO::VariableInfo> VI;
114      GIO.getVariableInfo(VI);
115
116#ifndef GENERICIO_NO_MPI
117      size_t MaxNElem = GIO.readNumElems();
118#else
119      size_t MaxNElem = 0;
120      int NR = GIO.readNRanks();
121      for (int i = 0; i < NR; ++i) {
122        size_t NElem = GIO.readNumElems(i);
123        MaxNElem = max(MaxNElem, NElem);
124      }
125#endif
126
127      vector< vector<char> > Vars(VI.size());
128      for (size_t i = 0; i < VI.size(); ++i) {
129        Vars[i].resize(VI[i].Size*MaxNElem + GIO.requestedExtraSpace());
130        GIO.addVariable(VI[i], &Vars[i][0], true);
131      }
132
133#ifndef GENERICIO_NO_MPI
134      GIO.readData(-1, false);
135      if (Verbose) cout << "\tdata from rank " << Rank << ": okay" << endl;
136#else
137      for (int i = 0; i < NR; ++i) {
138        GIO.readData(i, false);
139        if (Verbose) cout << "\tdata from rank " << i << ": okay" << endl;
140      }
141#endif
142
143      if (Rank == 0) {
144        cout << FileName << ": okay" << endl;
145        cout.flush();
146      }
147    } catch (exception &e) {
148      cerr << "ERROR: " << FileName << ": " << e.what() << endl;
149      cerr.flush();
150      AllOkay = false;
151    }
152  }
153
154#ifndef GENERICIO_NO_MPI
155  MPI_Barrier(MPI_COMM_WORLD);
156  MPI_Finalize();
157#endif
158
159  return AllOkay ? 0 : 1;
160}
161
Note: See TracBrowser for help on using the repository browser.