source: GenericIOBenchmarkRead.cxx @ 5d57155

Revision 5d57155, 5.0 KB checked in by Hal Finkel <hfinkel@…>, 7 years ago (diff)

Add support for float4 (and other homogeneous aggregates)

  • 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 <cstdio>
44#include <cstring>
45#include <cmath>
46#include <iostream>
47#include <string>
48#include <cassert>
49
50#include "GenericIO.h"
51
52#define POSVEL_T float
53#define ID_T int64_t
54#define MASK_T uint16_t
55
56struct pos_t {
57  POSVEL_T x, y, z, w;
58};
59
60using namespace std;
61using namespace gio;
62
63int main(int argc, char *argv[]) {
64  MPI_Init(&argc, &argv);
65
66  int commRank, commRanks;
67  MPI_Comm_rank(MPI_COMM_WORLD, &commRank);
68  MPI_Comm_size(MPI_COMM_WORLD, &commRanks);
69
70  bool UseAOS = false;
71  int a = 1;
72  if (argc > 1 && string(argv[a]) == "-a") {
73    UseAOS = true;
74    --argc;
75    ++a;
76  }
77
78  if(argc != 2) {
79    fprintf(stderr,"USAGE: %s [-a] <mpiioName>\n", argv[0]);
80    exit(-1);
81  }
82
83  char *mpiioName = argv[a];
84
85  vector<POSVEL_T> xx, yy, zz, vx, vy, vz, phi;
86  vector<ID_T> id;
87  vector<MASK_T> mask;
88
89  vector<pos_t> pos, vel;
90
91  assert(sizeof(ID_T) == 8);
92
93  size_t Np = 0;
94  unsigned Method = GenericIO::FileIOPOSIX;
95  const char *EnvStr = getenv("GENERICIO_USE_MPIIO");
96  if (EnvStr && string(EnvStr) == "1")
97    Method = GenericIO::FileIOMPI;
98
99  { // scope GIO
100  GenericIO GIO(
101    MPI_COMM_WORLD,
102    mpiioName, Method);
103  GIO.openAndReadHeader(GenericIO::MismatchRedistribute);
104
105  MPI_Barrier(MPI_COMM_WORLD);
106
107  Np = GIO.readNumElems();
108
109  if (UseAOS) {
110    pos.resize(Np + (GIO.requestedExtraSpace() + sizeof(pos_t) - 1)/sizeof(pos_t));
111    vel.resize(Np + (GIO.requestedExtraSpace() + sizeof(pos_t) - 1)/sizeof(pos_t));
112  } else {
113    xx.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
114    yy.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
115    zz.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
116    vx.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
117    vy.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
118    vz.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
119    phi.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
120  }
121  id.resize(Np + GIO.requestedExtraSpace()/sizeof(ID_T));
122  mask.resize(Np + GIO.requestedExtraSpace()/sizeof(MASK_T));
123
124  if (UseAOS) {
125    GIO.addVariable("pos", pos, GenericIO::VarHasExtraSpace);
126    GIO.addVariable("vel", vel, GenericIO::VarHasExtraSpace);
127  } else {
128    GIO.addVariable("x", xx, GenericIO::VarHasExtraSpace);
129    GIO.addVariable("y", yy, GenericIO::VarHasExtraSpace);
130    GIO.addVariable("z", zz, GenericIO::VarHasExtraSpace);
131    GIO.addVariable("vx", vx, GenericIO::VarHasExtraSpace);
132    GIO.addVariable("vy", vy, GenericIO::VarHasExtraSpace);
133    GIO.addVariable("vz", vz, GenericIO::VarHasExtraSpace);
134    GIO.addVariable("phi", phi, GenericIO::VarHasExtraSpace);
135  }
136  GIO.addVariable("id", id, GenericIO::VarHasExtraSpace);
137  GIO.addVariable("mask", mask, GenericIO::VarHasExtraSpace);
138
139  GIO.readData();
140  } // destroy GIO prior to calling MPI_Finalize
141
142  if (UseAOS) {
143    pos.resize(Np);
144    vel.resize(Np);
145  } else {
146    xx.resize(Np);
147    yy.resize(Np);
148    zz.resize(Np);
149    vx.resize(Np);
150    vy.resize(Np);
151    vz.resize(Np);
152    phi.resize(Np);
153  }
154  id.resize(Np);
155  mask.resize(Np);
156
157  MPI_Barrier(MPI_COMM_WORLD);
158  MPI_Finalize();
159
160  return 0;
161}
162
Note: See TracBrowser for help on using the repository browser.