source: GenericIOBenchmarkWrite.cxx @ ba0fbd1

Revision ba0fbd1, 5.0 KB checked in by Hal Finkel <hfinkel@…>, 9 years ago (diff)

Add some simple benchmark programs

  • Property mode set to 100644
RevLine 
[ba0fbd1]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
56using namespace std;
57using namespace gio;
58
59int main(int argc, char *argv[]) {
60  MPI_Init(&argc, &argv);
61
62  int commRank, commRanks;
63  MPI_Comm_rank(MPI_COMM_WORLD, &commRank);
64  MPI_Comm_size(MPI_COMM_WORLD, &commRanks);
65
66  if(argc != 4) {
67    fprintf(stderr,"USAGE: %s <mpiioName> <NP> <seed>\n", argv[0]);
68    exit(-1);
69  }
70
71  GenericIO::setNaturalDefaultPartition();
72
73  char *mpiioName = argv[1];
74  size_t Np = atoi(argv[2])/commRanks;
75  int seed = atoi(argv[3]);
76
77  srand48(seed + commRank);
78
79  // Add a 2% variance to make things a bit more realistic.
80  Np = double(Np)*(1.0 + (drand48() - 0.5)*0.02);
81
82  vector<POSVEL_T> xx, yy, zz, vx, vy, vz, phi;
83  vector<ID_T> id;
84  vector<MASK_T> mask;
85
86  assert(sizeof(ID_T) == 8);
87
88  unsigned Method = GenericIO::FileIOPOSIX;
89  const char *EnvStr = getenv("GENERICIO_USE_MPIIO");
90  if (EnvStr && string(EnvStr) == "1")
91    Method = GenericIO::FileIOMPI;
92
93  { // scope GIO
94  GenericIO GIO(
95    MPI_COMM_WORLD,
96    mpiioName, Method);
97  GIO.setNumElems(Np);
98
99  int CoordFlagsX = GenericIO::VarIsPhysCoordX;
100  int CoordFlagsY = GenericIO::VarIsPhysCoordY;
101  int CoordFlagsZ = GenericIO::VarIsPhysCoordZ;
102  GIO.setPhysOrigin(0.0);
103  GIO.setPhysScale(256.0);
104
105  xx.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
106  yy.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
107  zz.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
108  vx.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
109  vy.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
110  vz.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
111  phi.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
112  id.resize(Np + GIO.requestedExtraSpace()/sizeof(ID_T));
113  mask.resize(Np + GIO.requestedExtraSpace()/sizeof(MASK_T));
114
115  std::fill(xx.begin(), xx.end(), 25);
116  std::fill(yy.begin(), yy.end(), 25);
117  std::fill(zz.begin(), zz.end(), 25);
118  std::fill(vx.begin(), vx.end(), 25);
119  std::fill(vy.begin(), vy.end(), 25);
120  std::fill(vz.begin(), vz.end(), 25);
121  std::fill(phi.begin(), phi.end(), 25);
122  std::fill(id.begin(), id.end(), 25);
123  std::fill(mask.begin(), mask.end(), 25);
124
125  GIO.addVariable("x", xx, CoordFlagsX | GenericIO::VarHasExtraSpace);
126  GIO.addVariable("y", yy, CoordFlagsY | GenericIO::VarHasExtraSpace);
127  GIO.addVariable("z", zz, CoordFlagsZ | GenericIO::VarHasExtraSpace);
128  GIO.addVariable("vx", vx, GenericIO::VarHasExtraSpace);
129  GIO.addVariable("vy", vy, GenericIO::VarHasExtraSpace);
130  GIO.addVariable("vz", vz, GenericIO::VarHasExtraSpace);
131  GIO.addVariable("phi", phi, GenericIO::VarHasExtraSpace);
132  GIO.addVariable("id", id, GenericIO::VarHasExtraSpace);
133  GIO.addVariable("mask", mask, GenericIO::VarHasExtraSpace);
134
135  GIO.write();
136  } // destroy GIO prior to calling MPI_Finalize
137
138  xx.resize(Np);
139  yy.resize(Np);
140  zz.resize(Np);
141  vx.resize(Np);
142  vy.resize(Np);
143  vz.resize(Np);
144  phi.resize(Np);
145  id.resize(Np);
146  mask.resize(Np);
147
148  MPI_Barrier(MPI_COMM_WORLD);
149  MPI_Finalize();
150
151  return 0;
152}
153
Note: See TracBrowser for help on using the repository browser.