[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> |
---|
[cda87e9] | 46 | #include <algorithm> |
---|
[ba0fbd1] | 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 | |
---|
| 57 | using namespace std; |
---|
| 58 | using namespace gio; |
---|
| 59 | |
---|
[cda87e9] | 60 | template <typename T> |
---|
| 61 | struct 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 | |
---|
[ba0fbd1] | 72 | int main(int argc, char *argv[]) { |
---|
| 73 | MPI_Init(&argc, &argv); |
---|
| 74 | |
---|
| 75 | int commRank, commRanks; |
---|
| 76 | MPI_Comm_rank(MPI_COMM_WORLD, &commRank); |
---|
| 77 | MPI_Comm_size(MPI_COMM_WORLD, &commRanks); |
---|
| 78 | |
---|
[72ac664] | 79 | int a = 1; |
---|
| 80 | if (argc > 1 && string(argv[a]) == "-c") { |
---|
| 81 | GenericIO::setDefaultShouldCompress(true); |
---|
| 82 | --argc; |
---|
| 83 | ++a; |
---|
| 84 | } |
---|
| 85 | |
---|
[ba0fbd1] | 86 | if(argc != 4) { |
---|
[72ac664] | 87 | fprintf(stderr,"USAGE: %s [-c] <mpiioName> <NP> <seed>\n", argv[0]); |
---|
[ba0fbd1] | 88 | exit(-1); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | GenericIO::setNaturalDefaultPartition(); |
---|
| 92 | |
---|
[72ac664] | 93 | char *mpiioName = argv[a++]; |
---|
| 94 | size_t Np = atoi(argv[a++])/commRanks; |
---|
| 95 | int seed = atoi(argv[a++]); |
---|
[ba0fbd1] | 96 | |
---|
| 97 | srand48(seed + commRank); |
---|
| 98 | |
---|
| 99 | // Add a 2% variance to make things a bit more realistic. |
---|
| 100 | Np = double(Np)*(1.0 + (drand48() - 0.5)*0.02); |
---|
| 101 | |
---|
| 102 | vector<POSVEL_T> xx, yy, zz, vx, vy, vz, phi; |
---|
| 103 | vector<ID_T> id; |
---|
| 104 | vector<MASK_T> mask; |
---|
| 105 | |
---|
| 106 | assert(sizeof(ID_T) == 8); |
---|
| 107 | |
---|
| 108 | unsigned Method = GenericIO::FileIOPOSIX; |
---|
| 109 | const char *EnvStr = getenv("GENERICIO_USE_MPIIO"); |
---|
| 110 | if (EnvStr && string(EnvStr) == "1") |
---|
| 111 | Method = GenericIO::FileIOMPI; |
---|
| 112 | |
---|
| 113 | { // scope GIO |
---|
| 114 | GenericIO GIO( |
---|
| 115 | MPI_COMM_WORLD, |
---|
| 116 | mpiioName, Method); |
---|
| 117 | GIO.setNumElems(Np); |
---|
| 118 | |
---|
| 119 | int CoordFlagsX = GenericIO::VarIsPhysCoordX; |
---|
| 120 | int CoordFlagsY = GenericIO::VarIsPhysCoordY; |
---|
| 121 | int CoordFlagsZ = GenericIO::VarIsPhysCoordZ; |
---|
| 122 | GIO.setPhysOrigin(0.0); |
---|
| 123 | GIO.setPhysScale(256.0); |
---|
| 124 | |
---|
| 125 | xx.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T)); |
---|
| 126 | yy.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T)); |
---|
| 127 | zz.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T)); |
---|
| 128 | vx.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T)); |
---|
| 129 | vy.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T)); |
---|
| 130 | vz.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T)); |
---|
| 131 | phi.resize(Np + GIO.requestedExtraSpace()/sizeof(POSVEL_T)); |
---|
| 132 | id.resize(Np + GIO.requestedExtraSpace()/sizeof(ID_T)); |
---|
| 133 | mask.resize(Np + GIO.requestedExtraSpace()/sizeof(MASK_T)); |
---|
| 134 | |
---|
[cda87e9] | 135 | std::generate(xx.begin(), xx.end(), Generator<POSVEL_T>(25, 3)); |
---|
| 136 | std::generate(yy.begin(), yy.end(), Generator<POSVEL_T>(25, 3)); |
---|
| 137 | std::generate(zz.begin(), zz.end(), Generator<POSVEL_T>(25, 3)); |
---|
| 138 | std::generate(vx.begin(), vx.end(), Generator<POSVEL_T>(25, 3)); |
---|
| 139 | std::generate(vy.begin(), vy.end(), Generator<POSVEL_T>(25, 3)); |
---|
| 140 | std::generate(vz.begin(), vz.end(), Generator<POSVEL_T>(25, 3)); |
---|
| 141 | std::generate(phi.begin(), phi.end(), Generator<POSVEL_T>(25, 3)); |
---|
| 142 | std::generate(id.begin(), id.end(), Generator<ID_T>(25, 3)); |
---|
[ba0fbd1] | 143 | std::fill(mask.begin(), mask.end(), 25); |
---|
| 144 | |
---|
| 145 | GIO.addVariable("x", xx, CoordFlagsX | GenericIO::VarHasExtraSpace); |
---|
| 146 | GIO.addVariable("y", yy, CoordFlagsY | GenericIO::VarHasExtraSpace); |
---|
| 147 | GIO.addVariable("z", zz, CoordFlagsZ | GenericIO::VarHasExtraSpace); |
---|
| 148 | GIO.addVariable("vx", vx, GenericIO::VarHasExtraSpace); |
---|
| 149 | GIO.addVariable("vy", vy, GenericIO::VarHasExtraSpace); |
---|
| 150 | GIO.addVariable("vz", vz, GenericIO::VarHasExtraSpace); |
---|
| 151 | GIO.addVariable("phi", phi, GenericIO::VarHasExtraSpace); |
---|
| 152 | GIO.addVariable("id", id, GenericIO::VarHasExtraSpace); |
---|
| 153 | GIO.addVariable("mask", mask, GenericIO::VarHasExtraSpace); |
---|
| 154 | |
---|
| 155 | GIO.write(); |
---|
| 156 | } // destroy GIO prior to calling MPI_Finalize |
---|
| 157 | |
---|
| 158 | xx.resize(Np); |
---|
| 159 | yy.resize(Np); |
---|
| 160 | zz.resize(Np); |
---|
| 161 | vx.resize(Np); |
---|
| 162 | vy.resize(Np); |
---|
| 163 | vz.resize(Np); |
---|
| 164 | phi.resize(Np); |
---|
| 165 | id.resize(Np); |
---|
| 166 | mask.resize(Np); |
---|
| 167 | |
---|
| 168 | MPI_Barrier(MPI_COMM_WORLD); |
---|
| 169 | MPI_Finalize(); |
---|
| 170 | |
---|
| 171 | return 0; |
---|
| 172 | } |
---|
| 173 | |
---|