VTK
ADIOSWriter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: ADIOSWriter.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // .NAME ADIOSWriter - The utility class performing ADIOS Write operations
16 
17 #ifndef _ADIOSWriter_h
18 #define _ADIOSWriter_h
19 #ifndef __VTK_WRAP__
20 #ifndef VTK_WRAPPING_CXX
21 
22 #include <limits>
23 #include <sstream>
24 #include <stdexcept>
25 #include <string>
26 #include <vector>
27 
28 #include <adios_mpi.h>
29 
30 #include "ADIOSDefs.h"
31 #include "ADIOSUtilities.h"
32 
33 namespace ADIOS
34 {
35 
36 // An array dimension as either a string or integer
37 struct ArrayDim
38 {
39  ArrayDim(size_t i) : ValueI(i), ValueS("") { }
40  ArrayDim(const std::string& var) : ValueI(0), ValueS(var) { }
41 
42  size_t ValueI;
44 };
45 
46 class Writer
47 {
48 public:
49  static bool SetCommunicator(MPI_Comm);
50 
51 public:
52  Writer(ADIOS::TransportMethod transport, const std::string& transportArgs);
53 
54  ~Writer();
55 
56  // Description:
57  // Define scalar attributes
58  template<typename TN>
59  void DefineAttribute(const std::string& path, const TN& value)
60  {
61  std::stringstream ss;
62  ss << value;
63  this->DefineAttribute(path, Type::NativeToADIOS<TN>(), ss.str());
64  }
65 
66  // Description:
67  // Define scalars for later writing
68  template<typename TN>
69  int DefineScalar(const std::string& path)
70  {
71  return this->DefineScalar(path, Type::NativeToADIOS<TN>());
72  }
73 
74  // Define an array for later writing
75  template<typename TN>
76  int DefineLocalArray(const std::string& path,
77  const std::vector<ArrayDim>& dims, Transform xfm = Transform_NONE)
78  {
79  return this->DefineLocalArray(path, Type::NativeToADIOS<TN>(), dims, xfm);
80  }
81  int DefineLocalArray(const std::string& path, ADIOS_DATATYPES adiosType,
82  const std::vector<ArrayDim>& dims, Transform xfm = Transform_NONE);
83 
84  // Description:
85  // Enqueue a scalar for writing
86  template<typename TN>
87  void WriteScalar(const std::string& path, const TN& val)
88  {
89  this->WriteScalar(path, Type::NativeToADIOS<TN>(), &val);
90  }
91  void WriteScalar(const std::string& path, ADIOS_DATATYPES adiosType,
92  const void* val);
93 
94  // Description:
95  // Enqueue an array for writing
96  void WriteArray(const std::string& path, const void* val);
97 
98  // Description:
99  // Perform all writes for the current time step
100  void Commit(const std::string& fileName, bool append = false);
101 
102 private:
103  struct InitContext;
104  InitContext *Ctx;
105 
106  struct WriterImpl;
107  WriterImpl *Impl;
108 
109  void DefineAttribute(const std::string& path, ADIOS_DATATYPES adiosType,
110  const std::string& value);
111  int DefineScalar(const std::string& path, ADIOS_DATATYPES adiosType);
112 };
113 
114 }
115 #endif
116 #endif
117 #endif // _ADIOSWriter_h
int DefineScalar(const std::string &path)
Definition: ADIOSWriter.h:69
TransportMethod
Definition: ADIOSDefs.h:24
int DefineLocalArray(const std::string &path, const std::vector< ArrayDim > &dims, Transform xfm=Transform_NONE)
Definition: ADIOSWriter.h:76
ArrayDim(const std::string &var)
Definition: ADIOSWriter.h:40
std::string ValueS
Definition: ADIOSWriter.h:43
void WriteScalar(const std::string &path, const TN &val)
Definition: ADIOSWriter.h:87
ArrayDim(size_t i)
Definition: ADIOSWriter.h:39
void DefineAttribute(const std::string &path, const TN &value)
Definition: ADIOSWriter.h:59
Transform
Definition: ADIOSDefs.h:40