source: GenericIOBenchmarkRead.cxx @ ba0fbd1

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

Add some simple benchmark programs

  • 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
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 != 2) {
67    fprintf(stderr,"USAGE: %s <mpiioName>\n", argv[0]);
68    exit(-1);
69  }
70
71  char *mpiioName = argv[1];
72
73  vector<POSVEL_T> xx, yy, zz, vx, vy, vz, phi;
74  vector<ID_T> id;
75  vector<MASK_T> mask;
76
77  assert(sizeof(ID_T) == 8);
78
79  size_t Np = 0;
80  unsigned Method = GenericIO::FileIOPOSIX;
81  const char *EnvStr = getenv("GENERICIO_USE_MPIIO");
82  if (EnvStr && string(EnvStr) == "1")
83    Method = GenericIO::FileIOMPI;
84
85  { // scope GIO
86  GenericIO GIO(
87    MPI_COMM_WORLD,
88    mpiioName, Method);
89  GIO.openAndReadHeader();
90
91  MPI_Barrier(MPI_COMM_WORLD);
92
93  Np = GIO.readNumElems();
94
95  xx.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
96  yy.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
97  zz.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
98  vx.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
99  vy.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
100  vz.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
101  phi.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T));
102  id.resize(Np + GIO.requestedExtraSpace()/sizeof(ID_T));
103  mask.resize(Np + GIO.requestedExtraSpace()/sizeof(MASK_T));
104
105  GIO.addVariable("x", xx, true);
106  GIO.addVariable("y", yy, true);
107  GIO.addVariable("z", zz, true);
108  GIO.addVariable("vx", vx, true);
109  GIO.addVariable("vy", vy, true);
110  GIO.addVariable("vz", vz, true);
111  GIO.addVariable("phi", phi, true);
112  GIO.addVariable("id", id, true);
113  GIO.addVariable("mask", mask, true);
114
115  GIO.readData();
116  } // destroy GIO prior to calling MPI_Finalize
117
118  xx.resize(Np);
119  yy.resize(Np);
120  zz.resize(Np);
121  vx.resize(Np);
122  vy.resize(Np);
123  vz.resize(Np);
124  phi.resize(Np);
125  id.resize(Np);
126  mask.resize(Np);
127
128  MPI_Barrier(MPI_COMM_WORLD);
129  MPI_Finalize();
130
131  return 0;
132}
133
Note: See TracBrowser for help on using the repository browser.