source: GenericIOBenchmarkWrite.cxx @ 5d57155

Revision 5d57155, 6.8 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 <algorithm>
47#include <iostream>
48#include <string>
49#include <cassert>
50
51#include "GenericIO.h"
52
53#define POSVEL_T float
54#define ID_T int64_t
55#define MASK_T uint16_t
56
57using namespace std;
58using namespace gio;
59
60template <typename T>
61struct Generator {
62    Generator(T start, T inc) : value(start), inc(inc) {}
63    T operator()() {
64      value += inc;
65      return value;
66    }
67
68    T value;
69    T inc;
70};
71
72struct pos_t {
73  POSVEL_T x, y, z, w;
74};
75
76template <>
77struct Generator<pos_t> {
78  Generator(POSVEL_T start, POSVEL_T inc) :
79    GenX(start, inc), GenY(start, inc), GenZ(start, inc), GenW(start, inc) {}
80
81  pos_t operator()() {
82    pos_t v;
83    v.x = GenX();
84    v.y = GenY();
85    v.z = GenZ();
86    v.w = GenW();
87
88    return v;
89  }
90
91  Generator<POSVEL_T> GenX, GenY, GenZ, GenW;
92};
93
94int main(int argc, char *argv[]) {
95  MPI_Init(&argc, &argv);
96
97  int commRank, commRanks;
98  MPI_Comm_rank(MPI_COMM_WORLD, &commRank);
99  MPI_Comm_size(MPI_COMM_WORLD, &commRanks);
100
101  bool UseAOS = false;
102  int a = 1;
103  if (argc > 1 && string(argv[a]) == "-a") {
104    UseAOS = true;
105    --argc;
106    ++a;
107  }
108
109  if (argc > 1 && string(argv[a]) == "-c") {
110    GenericIO::setDefaultShouldCompress(true);
111    --argc;
112    ++a;
113  }
114
115  if(argc != 4) {
116    fprintf(stderr,"USAGE: %s [-a] [-c] <mpiioName> <NP> <seed>\n", argv[0]);
117    exit(-1);
118  }
119
120  GenericIO::setNaturalDefaultPartition();
121
122  char *mpiioName = argv[a++];
123  size_t Np = atoi(argv[a++])/commRanks;
124  int seed = atoi(argv[a++]);
125
126  srand48(seed + commRank);
127
128  // Add a 2% variance to make things a bit more realistic.
129  Np = double(Np)*(1.0 + (drand48() - 0.5)*0.02);
130
131  vector<POSVEL_T> xx, yy, zz, vx, vy, vz, phi;
132  vector<ID_T> id;
133  vector<MASK_T> mask;
134
135  vector<pos_t> pos, vel;
136
137  assert(sizeof(ID_T) == 8);
138
139  unsigned Method = GenericIO::FileIOPOSIX;
140  const char *EnvStr = getenv("GENERICIO_USE_MPIIO");
141  if (EnvStr && string(EnvStr) == "1")
142    Method = GenericIO::FileIOMPI;
143
144  { // scope GIO
145  GenericIO GIO(
146    MPI_COMM_WORLD,
147    mpiioName, Method);
148  GIO.setNumElems(Np);
149
150  int CoordFlagsX = GenericIO::VarIsPhysCoordX;
151  int CoordFlagsY = GenericIO::VarIsPhysCoordY;
152  int CoordFlagsZ = GenericIO::VarIsPhysCoordZ;
153  GIO.setPhysOrigin(0.0);
154  GIO.setPhysScale(256.0);
155
156  if (UseAOS) {
157    pos.resize(Np + (GIO.requestedExtraSpace() + sizeof(pos_t) - 1)/sizeof(pos_t));
158    vel.resize(Np + (GIO.requestedExtraSpace() + sizeof(pos_t) - 1)/sizeof(pos_t));
159  } else {
160    xx.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
161    yy.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
162    zz.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
163    vx.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
164    vy.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
165    vz.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
166    phi.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
167  }
168  id.resize(Np + GIO.requestedExtraSpace()/sizeof(ID_T));
169  mask.resize(Np + GIO.requestedExtraSpace()/sizeof(MASK_T));
170
171  if (UseAOS) {
172    std::generate(pos.begin(), pos.end(), Generator<pos_t>(25, 3));
173    std::generate(vel.begin(), vel.end(), Generator<pos_t>(25, 3));
174  } else {
175    std::generate(xx.begin(), xx.end(), Generator<POSVEL_T>(25, 3));
176    std::generate(yy.begin(), yy.end(), Generator<POSVEL_T>(25, 3));
177    std::generate(zz.begin(), zz.end(), Generator<POSVEL_T>(25, 3));
178    std::generate(vx.begin(), vx.end(), Generator<POSVEL_T>(25, 3));
179    std::generate(vy.begin(), vy.end(), Generator<POSVEL_T>(25, 3));
180    std::generate(vz.begin(), vz.end(), Generator<POSVEL_T>(25, 3));
181    std::generate(phi.begin(), phi.end(), Generator<POSVEL_T>(25, 3));
182  }
183  std::generate(id.begin(), id.end(), Generator<ID_T>(25, 3));
184  std::fill(mask.begin(), mask.end(), 25);
185
186  if (UseAOS) {
187    GIO.addVariable("pos", pos, CoordFlagsX | CoordFlagsY | CoordFlagsZ |
188                                GenericIO::VarHasExtraSpace);
189    GIO.addVariable("vel", vel, GenericIO::VarHasExtraSpace);
190  } else {
191    GIO.addVariable("x", xx, CoordFlagsX | GenericIO::VarHasExtraSpace);
192    GIO.addVariable("y", yy, CoordFlagsY | GenericIO::VarHasExtraSpace);
193    GIO.addVariable("z", zz, CoordFlagsZ | GenericIO::VarHasExtraSpace);
194    GIO.addVariable("vx", vx, GenericIO::VarHasExtraSpace);
195    GIO.addVariable("vy", vy, GenericIO::VarHasExtraSpace);
196    GIO.addVariable("vz", vz, GenericIO::VarHasExtraSpace);
197    GIO.addVariable("phi", phi, GenericIO::VarHasExtraSpace);
198  }
199  GIO.addVariable("id", id, GenericIO::VarHasExtraSpace);
200  GIO.addVariable("mask", mask, GenericIO::VarHasExtraSpace);
201
202  GIO.write();
203  } // destroy GIO prior to calling MPI_Finalize
204
205  if (UseAOS) {
206    pos.resize(Np);
207    vel.resize(Np);
208  } else {
209    xx.resize(Np);
210    yy.resize(Np);
211    zz.resize(Np);
212    vx.resize(Np);
213    vy.resize(Np);
214    vz.resize(Np);
215    phi.resize(Np);
216  }
217  id.resize(Np);
218  mask.resize(Np);
219
220  MPI_Barrier(MPI_COMM_WORLD);
221  MPI_Finalize();
222
223  return 0;
224}
225
Note: See TracBrowser for help on using the repository browser.