[MOAB-dev] commit/MOAB: danwu: Fixed a bug of HOMME writer, which is only reproducible when localGidVertsOwned.psize() > 1. For parallel write, jik_to_kji() should be replaced with jik_to_kji_stride() to transpose tag format (ncol, lev) back to NC format (lev, ncol). Otherwise, wrong variable values could be written to the output file if localGidVertsOwned.psize() > 1. For existing parallel unit test, localGidVertsOwned.psize() is always 1 (probably due to evenly trivial partition), so this bug was not observed before. This fix will be tested on other partitions where localGidVertsOwned.psize() > 1.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Jun 10 13:52:53 CDT 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/95d1dbc6a764/
Changeset:   95d1dbc6a764
Branch:      master
User:        danwu
Date:        2014-06-10 20:52:30
Summary:     Fixed a bug of HOMME writer, which is only reproducible when localGidVertsOwned.psize() > 1. For parallel write, jik_to_kji() should be replaced with jik_to_kji_stride() to transpose tag format (ncol, lev) back to NC format (lev, ncol). Otherwise, wrong variable values could be written to the output file if localGidVertsOwned.psize() > 1. For existing parallel unit test, localGidVertsOwned.psize() is always 1 (probably due to evenly trivial partition), so this bug was not observed before. This fix will be tested on other partitions where localGidVertsOwned.psize() > 1.

Affected #:  2 files

diff --git a/src/io/NCWriteHOMME.cpp b/src/io/NCWriteHOMME.cpp
index abfe4ff..3dd61c1 100644
--- a/src/io/NCWriteHOMME.cpp
+++ b/src/io/NCWriteHOMME.cpp
@@ -246,9 +246,11 @@ ErrorCode NCWriteHOMME::write_nonset_variables(std::vector<WriteNC::VarData>& vd
       switch (variableData.varDataType) {
         case NC_DOUBLE: {
           std::vector<double> tmpdoubledata(num_local_verts_owned * num_lev);
-          if (num_lev > 1)
+          if (num_lev > 1) {
             // Transpose (ncol, lev) back to (lev, ncol)
-            jik_to_kji(num_local_verts_owned, 1, num_lev, &tmpdoubledata[0], &tag_data[0]);
+            // Note, num_local_verts_owned is not used by jik_to_kji_stride()
+            jik_to_kji_stride(num_local_verts_owned, 1, num_lev, &tmpdoubledata[0], &tag_data[0], localGidVertsOwned);
+          }
 
           size_t indexInDoubleArray = 0;
           size_t ic = 0;

diff --git a/src/io/NCWriteHelper.hpp b/src/io/NCWriteHelper.hpp
index 42425d2..8e817e3 100644
--- a/src/io/NCWriteHelper.hpp
+++ b/src/io/NCWriteHelper.hpp
@@ -44,16 +44,6 @@ protected:
   // Write non-set variables (implemented in child classes)
   virtual ErrorCode write_nonset_variables(std::vector<WriteNC::VarData>& vdatas, std::vector<int>& tstep_nums) = 0;
 
-  template <typename T> void jik_to_kji(size_t ni, size_t nj, size_t nk, T* dest, T* source)
-  {
-    size_t nik = ni * nk, nij = ni * nj;
-    for (std::size_t k = 0; k != nk; k++)
-      for (std::size_t j = 0; j != nj; j++)
-        for (std::size_t i = 0; i != ni; i++)
-          dest[k*nij + j*ni + i] = source[j*nik + i*nk + k];
-  }
-
-protected:
   //! Allow NCWriteHelper to directly access members of WriteNC
   WriteNC* _writeNC;
 
@@ -99,6 +89,15 @@ private:
   //! Implementation of NCWriteHelper::write_nonset_variables()
   virtual ErrorCode write_nonset_variables(std::vector<WriteNC::VarData>& vdatas, std::vector<int>& tstep_nums);
 
+  template <typename T> void jik_to_kji(size_t ni, size_t nj, size_t nk, T* dest, T* source)
+  {
+    size_t nik = ni * nk, nij = ni * nj;
+    for (std::size_t k = 0; k != nk; k++)
+      for (std::size_t j = 0; j != nj; j++)
+        for (std::size_t i = 0; i != ni; i++)
+          dest[k*nij + j*ni + i] = source[j*nik + i*nk + k];
+  }
+
 protected:
   //! Dimensions of my local part of grid
   int lDims[6];
@@ -117,6 +116,25 @@ public:
   virtual ~UcdNCWriteHelper() {}
 
 protected:
+  //! This version takes as input the moab range, from which we actually need just the
+  //! size of each sequence, for a proper transpose of the data
+  template <typename T> void jik_to_kji_stride(size_t , size_t nj, size_t nk, T* dest, T* source, Range& localGid)
+  {
+    std::size_t idxInSource = 0; // Position of the start of the stride
+    // For each subrange, we will transpose a matrix of size
+    // subrange*nj*nk (subrange takes the role of ni)
+    for (Range::pair_iterator pair_iter = localGid.pair_begin();
+        pair_iter != localGid.pair_end(); ++pair_iter) {
+      std::size_t size_range = pair_iter->second - pair_iter->first + 1;
+      std::size_t nik = size_range * nk, nij = size_range * nj;
+      for (std::size_t k = 0; k != nk; k++)
+        for (std::size_t j = 0; j != nj; j++)
+          for (std::size_t i = 0; i != size_range; i++)
+            dest[idxInSource + k*nij + j*size_range + i] = source[idxInSource + j*nik + i*nk + k];
+      idxInSource += (size_range*nj*nk);
+    }
+  }
+
   //! Dimension numbers for nCells, nEdges and nVertices
   int cDim, eDim, vDim;

Repository URL: https://bitbucket.org/fathomteam/moab/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the moab-dev mailing list