Skip to content

Commit fa8efe7

Browse files
updated heat2d for the new ADIOS2 public API
1 parent 100efb0 commit fa8efe7

File tree

7 files changed

+67
-66
lines changed

7 files changed

+67
-66
lines changed

Tutorial/heat2d/cpp/analysis/heatAnalysis.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,27 @@ int main(int argc, char *argv[])
8888
adios2::ADIOS ad(settings.configfile, mpiReaderComm, adios2::DebugON);
8989

9090
// Define IO method for engine creation
91-
adios2::IO &inIO = ad.DeclareIO("SimulationOutput");
92-
adios2::IO &outIO = ad.DeclareIO("AnalysisOutput");
91+
adios2::IO inIO = ad.DeclareIO("SimulationOutput");
92+
adios2::IO outIO = ad.DeclareIO("AnalysisOutput");
9393
if (!rank)
9494
{
95-
std::cout << "Using " << inIO.m_EngineType << " engine for input" << std::endl;
96-
std::cout << "Using " << outIO.m_EngineType << " engine for output" << std::endl;
95+
// std::cout << "Using " << inIO.m_EngineType << " engine for input" << std::endl;
96+
// std::cout << "Using " << outIO.m_EngineType << " engine for output" << std::endl;
9797
}
9898

9999

100-
adios2::Engine &reader =
100+
adios2::Engine reader =
101101
inIO.Open(settings.inputfile, adios2::Mode::Read, mpiReaderComm);
102102

103103
reader.FixedSchedule(); // a promise here that we don't change the read pattern over steps
104104

105105
std::vector<double> Tin;
106106
std::vector<double> Tout;
107107
std::vector<double> dT;
108-
adios2::Variable<double> *vTin = nullptr;
109-
adios2::Variable<double> *vTout = nullptr;
110-
adios2::Variable<double> *vdT = nullptr;
111-
adios2::Engine *writer = nullptr;
108+
adios2::Variable<double> vTin;
109+
adios2::Variable<double> vTout;
110+
adios2::Variable<double> vdT;
111+
adios2::Engine writer;
112112
bool firstStep = true;
113113
int step = 0;
114114

@@ -133,8 +133,8 @@ int main(int argc, char *argv[])
133133

134134
if (firstStep)
135135
{
136-
unsigned int gndx = vTin->m_Shape[0];
137-
unsigned int gndy = vTin->m_Shape[1];
136+
unsigned int gndx = vTin.Shape()[0];
137+
unsigned int gndy = vTin.Shape()[1];
138138

139139
if (rank == 0)
140140
{
@@ -148,24 +148,24 @@ int main(int argc, char *argv[])
148148
dT.resize(settings.readsize[0] * settings.readsize[1]);
149149

150150
/* Create output variables and open output stream */
151-
vTout = &outIO.DefineVariable<double>(
151+
vTout = outIO.DefineVariable<double>(
152152
"T", {gndx, gndy}, settings.offset, settings.readsize);
153-
vdT = &outIO.DefineVariable<double>(
153+
vdT = outIO.DefineVariable<double>(
154154
"dT", {gndx, gndy}, settings.offset, settings.readsize);
155-
writer = &outIO.Open(settings.outputfile, adios2::Mode::Write,
155+
writer = outIO.Open(settings.outputfile, adios2::Mode::Write,
156156
mpiReaderComm);
157-
writer->FixedSchedule();
157+
writer.FixedSchedule();
158158

159159
MPI_Barrier(mpiReaderComm); // sync processes just for stdout
160160
}
161161

162162
// Create a 2D selection for the subset
163-
vTin->SetSelection(
163+
vTin.SetSelection(
164164
adios2::Box<adios2::Dims>(settings.offset, settings.readsize));
165165

166166
// Arrays are read by scheduling one or more of them
167167
// and performing the reads at once
168-
reader.Get<double>(*vTin, Tin.data());
168+
reader.Get<double>(vTin, Tin.data());
169169
/*printDataStep(Tin.data(), settings.readsize.data(),
170170
settings.offset.data(), rank, step); */
171171
reader.EndStep();
@@ -183,17 +183,16 @@ int main(int argc, char *argv[])
183183
Compute(Tin, Tout, dT, firstStep);
184184

185185
/* Output Tout and dT */
186-
writer->BeginStep();
187-
writer->Put<double>(*vTout, Tout.data());
188-
writer->Put<double>(*vdT, dT.data());
189-
writer->EndStep();
186+
writer.BeginStep();
187+
writer.Put<double>(vTout, Tout.data());
188+
writer.Put<double>(vdT, dT.data());
189+
writer.EndStep();
190190

191191
step++;
192192
firstStep = false;
193193
}
194194
reader.Close();
195-
if (writer != nullptr)
196-
writer->Close();
195+
writer.Close();
197196
}
198197
catch (std::invalid_argument &e) // command-line argument errors
199198
{

Tutorial/heat2d/cpp/make.settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ LDFLAGS=-g -O2
2626
# VTK-m settings (need separate include and libraries)
2727
#
2828
# set USE_VTKM to OFF if you don't have VTK-m
29-
USE_VTKM=ON
29+
USE_VTKM=ON
3030
override VTKM_DIR=/opt/vtk-m
3131
override VTKM_INC=-I${VTKM_DIR}/include/vtkm-1.1
3232
override VTKM_LIB=-L${VTKM_DIR}/lib -lvtkm_rendering-1.1 -lvtkm_cont-1.1

Tutorial/heat2d/cpp/simulation/IO_adios2.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
#include <adios2.h>
1717

1818
adios2::ADIOS *ad = nullptr;
19-
adios2::Engine *writer = nullptr;
20-
adios2::Variable<double> *varT = nullptr;
21-
adios2::Variable<unsigned int> *varGndx = nullptr;
19+
adios2::Engine writer;
20+
adios2::Variable<double> varT;
21+
adios2::Variable<unsigned int> varGndx;
2222

2323
IO::IO(const Settings &s, MPI_Comm comm)
2424
{
2525
ad = new adios2::ADIOS(s.configfile, comm, adios2::DebugON);
2626

27-
adios2::IO &io = ad->DeclareIO("SimulationOutput");
27+
adios2::IO io = ad->DeclareIO("SimulationOutput");
2828
if (!io.InConfigFile())
2929
{
3030
// if not defined by user, we can change the default settings
@@ -39,11 +39,11 @@ IO::IO(const Settings &s, MPI_Comm comm)
3939

4040
if (!s.rank)
4141
{
42-
std::cout << "Using " << io.m_EngineType << " engine for output" << std::endl;
42+
// std::cout << "Using " << io.m_EngineType << " engine for output" << std::endl;
4343
}
4444

4545
// define T as 2D global array
46-
varT = &io.DefineVariable<double>(
46+
varT = io.DefineVariable<double>(
4747
"T",
4848
// Global dimensions
4949
{s.gndx, s.gndy},
@@ -52,29 +52,29 @@ IO::IO(const Settings &s, MPI_Comm comm)
5252
// local size, could be defined later using SetSelection()
5353
{s.ndx, s.ndy});
5454

55-
writer = &io.Open(s.outputfile, adios2::Mode::Write, comm);
55+
writer = io.Open(s.outputfile, adios2::Mode::Write, comm);
5656

5757
// Some optimization:
5858
// we promise here that we don't change the variables over steps
5959
// (the list of variables, their dimensions, and their selections)
60-
writer->FixedSchedule();
60+
writer.FixedSchedule();
6161
}
6262

6363
IO::~IO()
6464
{
65-
writer->Close();
65+
writer.Close();
6666
delete ad;
6767
}
6868

6969
void IO::write(int step, const HeatTransfer &ht, const Settings &s,
7070
MPI_Comm comm)
7171
{
72-
writer->BeginStep();
72+
writer.BeginStep();
7373
// using Put() you promise the pointer to the data will be intact
7474
// until the end of the output step.
7575
// We need to have the vector object here not to destruct here until the end
7676
// of function.
7777
std::vector<double> v = ht.data_noghost();
78-
writer->Put<double>(*varT, v.data());
79-
writer->EndStep();
78+
writer.Put<double>(varT, v.data());
79+
writer.EndStep();
8080
}

Tutorial/heat2d/cpp/visualization/VizOutput.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
#include "VizSettings.h"
1717

18-
void OutputVariable(const adios2::VariableBase *var,
19-
const std::vector<double> data, VizSettings &settings,
18+
void OutputVariable(const adios2::Variable<double> &var,
19+
const std::vector<double> &data, VizSettings &settings,
2020
const int step);
2121

2222
#endif /* VIZOUTPUT_H_ */

Tutorial/heat2d/cpp/visualization/VizOutputPrint.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
#include <iomanip>
1414
#include <iostream>
1515
#include <string>
16+
#include <numeric>
1617

1718
#include "VizOutput.h"
1819

19-
void OutputVariable(const adios2::VariableBase *var,
20-
const std::vector<double> data, VizSettings &settings,
20+
void OutputVariable(const adios2::Variable<double> &var,
21+
const std::vector<double> &data, VizSettings &settings,
2122
const int step)
2223
{
2324
// void printDataStep(double *xy, T *size, T *offset, int rank, int step)
2425
std::ofstream myfile;
25-
std::string filename = var->m_Name + ".txt";
26+
std::string filename = var.Name() + ".txt";
2627
if (step == 0)
2728
{
2829
myfile.open(filename);
@@ -32,26 +33,26 @@ void OutputVariable(const adios2::VariableBase *var,
3233
myfile.open(filename, std::ios::app);
3334
}
3435
const double *buf = data.data();
35-
uint64_t nelems = var->TotalSize();
36-
myfile << "size=" << var->m_Shape[0] << "x" << var->m_Shape[1]
36+
uint64_t nelems = std::accumulate(var.Count().begin(), var.Count().end(), var.Sizeof(), std::multiplies<size_t>());
37+
myfile << "size=" << var.Shape()[0] << "x" << var.Shape()[1]
3738
<< " step=" << step << std::endl;
3839

39-
myfile << " time row columns 0 ..." << var->m_Shape[1] - 1 << std::endl;
40+
myfile << " time row columns 0 ..." << var.Shape()[1] - 1 << std::endl;
4041
myfile << " ";
41-
for (int j = 0; j < var->m_Shape[1]; j++)
42+
for (int j = 0; j < var.Shape()[1]; j++)
4243
{
4344
myfile << std::setw(9) << j;
4445
}
4546
myfile << std::endl;
4647
myfile << "------------------------------------------------------------"
4748
"--\n";
48-
for (int i = 0; i < var->m_Shape[0]; i++)
49+
for (int i = 0; i < var.Shape()[0]; i++)
4950
{
5051
myfile << std::setw(5) << step << std::setw(5) << i;
51-
for (int j = 0; j < var->m_Shape[1]; j++)
52+
for (int j = 0; j < var.Shape()[1]; j++)
5253
{
5354
myfile << std::setw(9) << std::setprecision(4)
54-
<< buf[i * var->m_Shape[1] + j];
55+
<< buf[i * var.Shape()[1] + j];
5556
}
5657
myfile << std::endl;
5758
}

Tutorial/heat2d/cpp/visualization/VizOutputVtkm.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void Render2D(const vtkm::cont::DataSet &ds, const std::string &fieldNm,
7070
view.SaveAs(settings.outputfile);
7171
}
7272

73-
bool RenderVariable2D(const adios2::VariableBase *var, const void *buff,
73+
bool RenderVariable2D(const adios2::Variable<double> &var, const void *buff,
7474
const VizSettings &settings)
7575
{
7676
/*
@@ -86,9 +86,9 @@ bool RenderVariable2D(const adios2::VariableBase *var, const void *buff,
8686
*/
8787

8888
// Create the dataset from the variables
89-
vtkm::Vec<float, 2> origin(var->m_Start[1], var->m_Start[0]);
89+
vtkm::Vec<float, 2> origin(var.Start()[1], var.Start()[0]);
9090
vtkm::Vec<float, 2> spacing(1, 1);
91-
vtkm::Id2 dims(var->m_Count[1], var->m_Count[0]); // SET DIMS
91+
vtkm::Id2 dims(var.Count()[1], var.Count()[0]); // SET DIMS
9292

9393
vtkm::cont::DataSetBuilderUniform dsb;
9494
vtkm::cont::DataSet ds = dsb.Create(dims, origin, spacing);
@@ -99,19 +99,19 @@ bool RenderVariable2D(const adios2::VariableBase *var, const void *buff,
9999
vtkm::Id numPoints = dims[0] * dims[1];
100100

101101
vtkm::cont::DataSetFieldAdd dsf;
102-
dsf.AddPointField(ds, var->m_Name, varBuff, numPoints);
102+
dsf.AddPointField(ds, var.Name(), varBuff, numPoints);
103103
//ds.PrintSummary(std::cout);
104104

105-
Render2D(ds, var->m_Name, vtkm::rendering::ColorTable("temperature"),
105+
Render2D(ds, var.Name(), vtkm::rendering::ColorTable("temperature"),
106106
settings);
107107

108108
return true;
109109
}
110110

111-
void OutputVariable(const adios2::VariableBase *var,
112-
const std::vector<double> data, VizSettings &settings,
111+
void OutputVariable(const adios2::Variable<double> &var,
112+
const std::vector<double> &data, VizSettings &settings,
113113
const int step)
114114
{
115-
settings.outputfile = var->m_Name + "." + std::to_string(step) + ".pnm";
115+
settings.outputfile = var.Name() + "." + std::to_string(step) + ".pnm";
116116
RenderVariable2D(var, data.data(), settings);
117117
}

Tutorial/heat2d/cpp/visualization/heatVisualization.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <vector>
1717
#include <chrono>
1818
#include <thread>
19+
#include <numeric>
1920

2021
#include "VizOutput.h"
2122
#include "VizSettings.h"
@@ -65,19 +66,19 @@ int main(int argc, char *argv[])
6566
// Define method for engine creation
6667
// 1. Get method def from config file or define new one
6768

68-
adios2::IO &inIO = ad.DeclareIO("VizInput");
69+
adios2::IO inIO = ad.DeclareIO("VizInput");
6970

7071
if (!rank)
7172
{
72-
std::cout << "Using " << inIO.m_EngineType << " engine for input" << std::endl;
73+
// std::cout << "Using " << inIO.m_EngineType << " engine for input" << std::endl;
7374
}
7475

75-
adios2::Engine &reader = inIO.Open(
76+
adios2::Engine reader = inIO.Open(
7677
settings.inputfile, adios2::Mode::Read, MPI_COMM_SELF);
7778
reader.FixedSchedule(); // a promise here that we don't change the read pattern over steps
7879

7980
std::vector<double> Tin;
80-
adios2::Variable<double> *vTin = nullptr;
81+
adios2::Variable<double> vTin;
8182
bool firstStep = true;
8283
int step = 0;
8384

@@ -106,18 +107,18 @@ int main(int argc, char *argv[])
106107
{
107108
if (rank == 0)
108109
{
109-
std::cout << "gndx = " << vTin->m_Shape[0]
110+
std::cout << "gndx = " << vTin.Shape()[0]
110111
<< std::endl;
111-
std::cout << "gndy = " << vTin->m_Shape[1]
112+
std::cout << "gndy = " << vTin.Shape()[1]
112113
<< std::endl;
113114
}
114-
Tin.resize(vTin->TotalSize());
115+
Tin.resize(std::accumulate(vTin.Count().begin(), vTin.Count().end(), vTin.Sizeof(), std::multiplies<size_t>()));
115116
}
116117

117118
// Create a 2D selection for the subset
118-
vTin->SetSelection(
119-
adios2::Box<adios2::Dims>({0, 0}, vTin->m_Shape));
120-
reader.Get<double>(*vTin, Tin.data());
119+
vTin.SetSelection(
120+
adios2::Box<adios2::Dims>({0, 0}, vTin.Shape()));
121+
reader.Get<double>(vTin, Tin.data());
121122
reader.EndStep();
122123

123124
std::cout << "Visualization step " << step

0 commit comments

Comments
 (0)