From 8c9a23aaa68774c145c7ac4de9f03bd80042266f Mon Sep 17 00:00:00 2001
From: Norbert Podhorszki <pnorbert@ornl.gov>
Date: Fri, 28 Apr 2017 16:51:56 -0400
Subject: [PATCH] Rename VarDim to IrregularDim, change values of IrregularDim
 and JoinedDim

---
 .../groupless/multistep/reader_allsteps.cpp   | 64 +++++++++++++++----
 .../groupless/multistep/writer_multistep.cpp  | 17 +++--
 source/adios2/ADIOSTypes.h                    |  4 +-
 source/adios2/engine/adios1/ADIOS1Reader.h    | 12 ++++
 source/adios2/engine/adios1/ADIOS1Writer.cpp  |  2 +-
 5 files changed, 77 insertions(+), 22 deletions(-)

diff --git a/examples/groupless/multistep/reader_allsteps.cpp b/examples/groupless/multistep/reader_allsteps.cpp
index 935d298c8..5f4bda072 100644
--- a/examples/groupless/multistep/reader_allsteps.cpp
+++ b/examples/groupless/multistep/reader_allsteps.cpp
@@ -33,6 +33,17 @@ void Delete2DArray(T **ptr)
     delete[] ptr;
 }
 
+template <class T>
+void Print1DArray(T *ptr, int nElems, std::string name)
+{
+    std::cout << name << " = { ";
+    for (int i = 0; i < nElems; i++)
+    {
+        std::cout << ptr[i] << " ";
+    }
+    std::cout << "}\n";
+}
+
 template <class T>
 void Print2DArray(T **ptr, int nRows, int nCols, std::string name)
 {
@@ -69,7 +80,7 @@ int main(int argc, char *argv[])
     std::vector<int> ProcessID;
     // 3. Global array, global dimensions, local dimensions and offsets are
     // constant over time
-    std::vector<double> GlobalArrayFixedDims;
+    // std::vector<double> GlobalArrayFixedDims;
 
     // 4. Local array, local dimensions are
     // constant over time (but different across processors here)
@@ -140,13 +151,20 @@ int main(int argc, char *argv[])
         // ? How do we make a selection for an arbitrary list of steps ?
         vNY->SetStepSelection(0, vNY->GetNSteps());
         bpReader->Read<unsigned int>(*vNY, Nys.data());
+        Print1DArray(Nys.data(), Nys.size(), "NY");
 
-        std::cout << "NY = { ";
-        for (const auto &it : Nys)
+        /* ProcessID */
+        adios::Variable<int> *vProcessID =
+            bpReader->InquireVariableInt("ProcessID");
+        if (vProcessID->m_Shape[0] != Nwriters)
         {
-            std::cout << it << " ";
+            std::cout << "ERROR: Unexpected array size of ProcessID = "
+                      << vProcessID->m_Shape[0] << " != # of writers"
+                      << std::endl;
         }
-        std::cout << "}\n";
+        ProcessID.resize(vProcessID->m_Shape[0]);
+        bpReader->Read<int>(*vProcessID, ProcessID.data());
+        Print1DArray(ProcessID.data(), ProcessID.size(), "ProcessID");
 
         /* Nparts */
         // Nparts local scalar is presented as a 1D array of Nwriters
@@ -163,8 +181,8 @@ int main(int argc, char *argv[])
 
         /* GlobalArrayFixedDims */
         // inquiry about a variable, whose name we know
-        std::shared_ptr<adios::Variable<void *>> vGlobalArrayFixedDims =
-            bpReader->InquireVariable("GlobalArrayFixedDims");
+        adios::Variable<double> *vGlobalArrayFixedDims =
+            bpReader->InquireVariableDouble("GlobalArrayFixedDims");
 
         if (vGlobalArrayFixedDims == nullptr)
             throw std::ios_base::failure(
@@ -178,17 +196,39 @@ int main(int argc, char *argv[])
         std::size_t start = rank * count;
         if (rank == nproc - 1)
         {
-            count = gdim - (count * gdim);
+            count = gdim - (count * (nproc - 1));
         }
 
-        GlobalArrayFixedDims.resize(count);
+        double **GlobalArrayFixedDims =
+            Make2DArray<double>(vGlobalArrayFixedDims->GetNSteps(), count);
 
         // Make a 1D selection to describe the local dimensions of the variable
         // we READ and its offsets in the global spaces
         vGlobalArrayFixedDims->SetSelection({start}, {count});
-        bpReader->ScheduleRead<void>(vGlobalArrayFixedDims,
-                                     GlobalArrayFixedDims.data());
-        bpReader->PerformReads(adios::PerformReadMode::BLOCKINGREAD);
+        vGlobalArrayFixedDims->SetStepSelection(
+            0, vGlobalArrayFixedDims->GetNSteps());
+        bpReader->Read<double>(*vGlobalArrayFixedDims, GlobalArrayFixedDims[0]);
+        Print2DArray(GlobalArrayFixedDims, vGlobalArrayFixedDims->GetNSteps(),
+                     count, "GlobalArrayFixedDims");
+
+        /* LocalArrayFixedDims2D */
+        // inquiry about a variable, whose name we know
+        adios::Variable<float> *vLocalArrayFixedDims2D =
+            bpReader->InquireVariableFloat("LocalArrayFixedDims2D");
+        if (vLocalArrayFixedDims2D->m_Shape[1] != adios::IrregularDim)
+        {
+            throw std::ios_base::failure(
+                "Unexpected condition: LocalArrayFixedDims2D array's fast "
+                "dimension is supposed to be adios::IrregularDim indicating an "
+                "Irregular array\n");
+        }
+
+        /* LocalArrayFixedDims1D */
+        // inquiry about a variable, whose name we know
+        adios::Variable<float> *vLocalArrayFixedDims1D =
+            bpReader->InquireVariableFloat("LocalArrayFixedDims1D");
+        std::cout << "LocalArrayFixedDims1D ["
+                  << vLocalArrayFixedDims1D->m_Shape[0] << "]" << std::endl;
 
 // overloaded Read from Derived
 #if 0
diff --git a/examples/groupless/multistep/writer_multistep.cpp b/examples/groupless/multistep/writer_multistep.cpp
index 6f98f599d..60fb1722c 100644
--- a/examples/groupless/multistep/writer_multistep.cpp
+++ b/examples/groupless/multistep/writer_multistep.cpp
@@ -37,10 +37,7 @@ int main(int argc, char *argv[])
     // 3. Global array, global dimensions, local dimensions and offsets are
     // constant over time
     std::vector<double> GlobalArrayFixedDims(Nx);
-    for (int i = 0; i < Nx; i++)
-    {
-        GlobalArrayFixedDims[i] = rank * Nx + (double)i;
-    }
+
     // 4. Local array, local dimensions are
     // constant over time (but different across processors here)
     std::vector<float> LocalArrayFixedDims(nproc - rank + 1, rank);
@@ -81,7 +78,7 @@ int main(int argc, char *argv[])
         // offset in the slow dimension
         adios::Variable<float> &varLocalArrayFixedDims2D =
             adios.DefineVariable<float>("LocalArrayFixedDims2D",
-                                        {nproc, adios::VarDim}, {rank, 0},
+                                        {nproc, adios::IrregularDim}, {rank, 0},
                                         {1, LocalArrayFixedDims.size()});
         // 4.b. Joined array, a 1D array, with global dimension and offsets
         // calculated at read time
@@ -107,8 +104,8 @@ int main(int argc, char *argv[])
         // Want to see this at reading as an irregular 2D array with rank
         // serving as
         // offset in the slow dimension
-        adios::Variable<float> &varIrregularArray =
-            adios.DefineVariable<float>("Irregular", {nproc, adios::VarDim});
+        adios::Variable<float> &varIrregularArray = adios.DefineVariable<float>(
+            "Irregular", {nproc, adios::IrregularDim});
 
         // add transform to variable in group...not executed (just testing API)
         // adios::Transform bzip2 = adios::transform::BZIP2();
@@ -143,6 +140,12 @@ int main(int argc, char *argv[])
 
         for (int step = 0; step < NSTEPS; step++)
         {
+            for (int i = 0; i < Nx; i++)
+            {
+                GlobalArrayFixedDims[i] =
+                    step * Nx * nproc * 1.0 + rank * Nx * 1.0 + (double)i;
+            }
+
             // Create and fill the arrays whose dimensions change over time
             Ny = Nx + step;
             GlobalArray.reserve(Ny);
diff --git a/source/adios2/ADIOSTypes.h b/source/adios2/ADIOSTypes.h
index 89144a834..0f211aa9d 100644
--- a/source/adios2/ADIOSTypes.h
+++ b/source/adios2/ADIOSTypes.h
@@ -115,8 +115,8 @@ struct TypeInfo<T, typename std::enable_if<std::is_same<
 };
 
 const size_t UnknownDim = 0;
-const size_t JoinedDim = SIZE_MAX;
-const size_t VarDim = JoinedDim - 1;
+const size_t JoinedDim = SIZE_MAX - 1;
+const size_t IrregularDim = JoinedDim - 1;
 const bool ConstantShape = true;
 
 enum class Verbose
diff --git a/source/adios2/engine/adios1/ADIOS1Reader.h b/source/adios2/engine/adios1/ADIOS1Reader.h
index 15f6ce742..3cfe5b82c 100644
--- a/source/adios2/engine/adios1/ADIOS1Reader.h
+++ b/source/adios2/engine/adios1/ADIOS1Reader.h
@@ -183,6 +183,18 @@ private:
             if (vi->ndim > 0)
             {
                 Dims gdims = Uint64ArrayToSizetVector(vi->ndim, vi->dims);
+                if (gdims[0] == JoinedDim)
+                {
+                    adios_inq_var_blockinfo(m_fh, vi);
+                    size_t joined_size = 0;
+                    // TODO: This just looks at the first step. What's with
+                    // arrays changing over time?
+                    for (int i = 0; i < *vi->nblocks; i++)
+                    {
+                        joined_size += vi->blockinfo[i].count[0];
+                    }
+                    gdims[0] = joined_size;
+                }
                 var = &m_ADIOS.DefineArray<T>(name, gdims);
             }
             else /* scalar variable */
diff --git a/source/adios2/engine/adios1/ADIOS1Writer.cpp b/source/adios2/engine/adios1/ADIOS1Writer.cpp
index 801adcb7c..3c94ea768 100644
--- a/source/adios2/engine/adios1/ADIOS1Writer.cpp
+++ b/source/adios2/engine/adios1/ADIOS1Writer.cpp
@@ -108,7 +108,7 @@ static std::string DimsToCSV_LocalAware(const std::vector<std::size_t> &dims)
     for (const auto dim : dims)
     {
         dimsCSV += std::to_string(dim) + ",";
-        if (dim == JoinedDim || dim == VarDim)
+        if (dim == JoinedDim || dim == IrregularDim)
             localVar = true;
     }
 
-- 
GitLab