File: dataSpacesReader.cpp

package info (click to toggle)
adios2 2.11.0%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 39,984 kB
  • sloc: ansic: 250,306; cpp: 189,875; yacc: 18,929; f90: 15,117; python: 8,047; perl: 7,126; sh: 3,049; lisp: 1,106; xml: 1,011; lex: 948; makefile: 598
file content (102 lines) | stat: -rw-r--r-- 2,724 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
 * dataSpacesReader.cpp
 *
 *  Created on: Feb 06, 2019
 *      Author: Pradeep Subedi
 *      		pradeep.subedi@rutgers.edu
 */

#include <chrono>
#include <iostream>
#include <numeric>
#include <thread>
#include <vector>

#include <adios2.h>

#if ADIOS2_USE_MPI
#include <mpi.h>
#endif

int main(int argc, char *argv[])
{

    int rank;
    int size;

#if ADIOS2_USE_MPI
    int provided;

    // MPI_THREAD_MULTIPLE is only required if you enable the SST MPI_DP
    MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
#else
    rank = 0;
    size = 1;
#endif

    std::vector<float> myFloats(10);

    try
    {
#if ADIOS2_USE_MPI
        adios2::ADIOS adios(MPI_COMM_WORLD);
#else
        adios2::ADIOS adios;
#endif

        adios2::IO dataSpacesIO = adios.DeclareIO("myIO");
        dataSpacesIO.SetEngine("DATASPACES");

        adios2::Engine dataSpacesReader = dataSpacesIO.Open("helloDataSpaces", adios2::Mode::Read);
        dataSpacesReader.BeginStep();
        adios2::Variable<float> bpFloats = dataSpacesIO.InquireVariable<float>("bpFloats");
        std::cout << "Incoming variable is of size " << bpFloats.Shape()[0] << "\n";
        const std::size_t total_size = bpFloats.Shape()[0];
        const std::size_t my_start = (total_size / size) * rank;
        const std::size_t my_count = (total_size / size);
        std::cout << "Reader rank " << rank << " reading " << my_count
                  << " floats starting at element " << my_start << "\n";

        const adios2::Dims start{my_start};
        const adios2::Dims count{my_count};

        const adios2::Box<adios2::Dims> sel(start, count);

        std::vector<float> myFloats;
        myFloats.resize(my_count);

        bpFloats.SetSelection(sel);
        dataSpacesReader.Get(bpFloats, myFloats.data());
        dataSpacesReader.EndStep();

        dataSpacesReader.Close();
    }
    catch (std::invalid_argument &e)
    {
        std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n";
        std::cout << e.what() << "\n";
    }
    catch (std::ios_base::failure &e)
    {
        std::cout << "IO System base failure exception, STOPPING PROGRAM "
                     "from rank "
                  << rank << "\n";
        std::cout << e.what() << "\n";
    }
    catch (std::exception &e)
    {
        std::cout << "Exception, STOPPING PROGRAM from rank " << rank << "\n";
        std::cout << e.what() << "\n";
    }

#if ADIOS2_USE_MPI
    MPI_Finalize();
#endif

    return 0;
}