source: GenericIORewrite.cxx @ 95f86a3

Revision 95f86a3, 2.5 KB checked in by Hal Finkel <hfinkel@…>, 8 years ago (diff)

drop gio topology column tags when not preserving topology

  • Property mode set to 100644
RevLine 
[fc4fc2f]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
12using namespace gio;
13using namespace std;
14
15int main(int argc, char *argv[]) {
16  MPI_Init(&argc, &argv);
17
18  if (argc < 2) {
19    cerr << "Usage: " << argv[0] << " <mpiioOld> <mpiioNew>" << endl;
20    exit(-1);
21  }
22
23  GenericIO::setNaturalDefaultPartition();
24  GenericIO::setDefaultShouldCompress(true);
25
26  {
27    int arg = 1;
28    int Rank, NRanks;
29    MPI_Comm_rank(MPI_COMM_WORLD, &Rank);
30    MPI_Comm_size(MPI_COMM_WORLD, &NRanks);
31
32    string FileName(argv[arg++]);
33    string NewFileName(argv[arg++]);
34
35    unsigned Method = GenericIO::FileIOPOSIX;
36    const char *EnvStr = getenv("GENERICIO_USE_MPIIO");
37    if (EnvStr && string(EnvStr) == "1")
38      Method = GenericIO::FileIOMPI;
39
40    GenericIO GIO(MPI_COMM_WORLD, FileName, Method);
[7ff84e0]41    GIO.openAndReadHeader(GenericIO::MismatchRedistribute);
42
43    int NR = GIO.readNRanks();
44    if (!Rank && NR != NRanks) {
45      cout << "Redistributing data from " << NR << " ranks to " << NRanks <<
46              " ranks; dropping rank topology information!\n";
47    }
[fc4fc2f]48
49    vector<GenericIO::VariableInfo> VI;
50    GIO.getVariableInfo(VI);
51
52    size_t NElem = GIO.readNumElems();
53
54    double PhysOrigin[3], PhysScale[3];
55    GIO.readPhysOrigin(PhysOrigin);
56    GIO.readPhysScale(PhysScale);
57
58    vector< vector<char> > Vars(VI.size());
59    for (size_t i = 0; i < VI.size(); ++i) {
60      Vars[i].resize(VI[i].Size*NElem + GIO.requestedExtraSpace());
61      GIO.addVariable(VI[i], &Vars[i][0], GenericIO::VarHasExtraSpace);
62    }
63
64    GIO.readData(-1, false);
65
[7ff84e0]66    MPI_Comm Comm = MPI_COMM_WORLD;
67    if (NR == NRanks) {
68      int Periods[3] = { 0, 0, 0 };
69      int Dims[3];
70      GIO.readDims(Dims);
71      MPI_Cart_create(Comm, 3, Dims, Periods, 0, &Comm);
72    }
73
74    GenericIO NewGIO(Comm, NewFileName);
[fc4fc2f]75    NewGIO.setNumElems(NElem);
76
77    for (int d = 0; d < 3; ++d) {
78      NewGIO.setPhysOrigin(PhysOrigin[d], d);
79      NewGIO.setPhysScale(PhysScale[d], d);
80    }
81
[95f86a3]82    for (size_t i = 0; i < VI.size(); ++i) {
83      if (NR != NRanks) {
84        // When dropping topology information, also drop the related column tags.
85        VI[i].IsPhysCoordX = VI[i].IsPhysCoordY = VI[i].IsPhysCoordZ =
86          VI[i].MaybePhysGhost = false;
87      }
88
[fc4fc2f]89      NewGIO.addVariable(VI[i], &Vars[i][0], GenericIO::VarHasExtraSpace);
[95f86a3]90    }
[fc4fc2f]91
92    NewGIO.write();
93  }
94
95  MPI_Barrier(MPI_COMM_WORLD);
96  MPI_Finalize();
97
98  return 0;
99}
100
Note: See TracBrowser for help on using the repository browser.