Skip to content

Commit

Permalink
Merge pull request #2568 from JasonRuonanWang/ssc_string
Browse files Browse the repository at this point in the history
fixed a bug in ssc for string variables
  • Loading branch information
JasonRuonanWang authored and Chuck Atkins committed Jan 7, 2021
2 parents 4a65b95 + 95d8b5b commit fe0b464
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 114 deletions.
3 changes: 3 additions & 0 deletions source/adios2/engine/ssc/SscReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class SscReader : public Engine
template <class T>
void GetDeferredCommon(Variable<T> &variable, T *data);

template <class T>
void GetDeferredDeltaCommon(Variable<T> &variable);

void CalculatePosition(ssc::BlockVecVec &mapVec,
ssc::RankPosMap &allOverlapRanks);

Expand Down
190 changes: 76 additions & 114 deletions source/adios2/engine/ssc/SscReader.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -23,82 +23,96 @@ namespace core
namespace engine
{

template <>
void SscReader::GetDeferredCommon(Variable<std::string> &variable,
std::string *data)
template <class T>
void SscReader::GetDeferredDeltaCommon(Variable<T> &variable)
{
TAU_SCOPED_TIMER_FUNC();
variable.SetData(data);

if (m_WriterDefinitionsLocked && m_ReaderSelectionsLocked)
Dims vStart = variable.m_Start;
Dims vCount = variable.m_Count;
Dims vShape = variable.m_Shape;

if (!helper::IsRowMajor(m_IO.m_HostLanguage))
{
if (m_CurrentStep == 0)
{
m_LocalReadPattern.emplace_back();
auto &b = m_LocalReadPattern.back();
b.name = variable.m_Name;
b.count = variable.m_Count;
b.start = variable.m_Start;
b.shape = variable.m_Shape;
b.type = DataType::String;
std::reverse(vStart.begin(), vStart.end());
std::reverse(vCount.begin(), vCount.end());
std::reverse(vShape.begin(), vShape.end());
}

m_LocalReadPatternJson["Variables"].emplace_back();
auto &jref = m_LocalReadPatternJson["Variables"].back();
jref["Name"] = b.name;
jref["Type"] = b.type;
jref["ShapeID"] = variable.m_ShapeID;
jref["Start"] = b.start;
jref["Count"] = b.count;
jref["Shape"] = b.shape;
jref["BufferStart"] = 0;
jref["BufferCount"] = 0;
m_LocalReadPattern.emplace_back();
auto &b = m_LocalReadPattern.back();
b.name = variable.m_Name;
b.count = vCount;
b.start = vStart;
b.shape = vShape;
b.type = helper::GetDataType<T>();

ssc::JsonToBlockVecVec(m_GlobalWritePatternJson,
m_GlobalWritePattern);
m_AllReceivingWriterRanks =
ssc::CalculateOverlap(m_GlobalWritePattern, m_LocalReadPattern);
CalculatePosition(m_GlobalWritePattern, m_AllReceivingWriterRanks);
size_t totalDataSize = 0;
for (auto i : m_AllReceivingWriterRanks)
{
totalDataSize += i.second.second;
}
m_Buffer.resize(totalDataSize);
for (const auto &i : m_AllReceivingWriterRanks)
{
MPI_Win_lock(MPI_LOCK_SHARED, i.first, 0, m_MpiWin);
MPI_Get(m_Buffer.data() + i.second.first,
static_cast<int>(i.second.second), MPI_CHAR, i.first, 0,
static_cast<int>(i.second.second), MPI_CHAR, m_MpiWin);
MPI_Win_unlock(i.first, m_MpiWin);
}
for (const auto &d : b.count)
{
if (d == 0)
{
throw(std::runtime_error(
"SetSelection count dimensions cannot be 0"));
}
}

m_LocalReadPatternJson["Variables"].emplace_back();
auto &jref = m_LocalReadPatternJson["Variables"].back();
jref["Name"] = variable.m_Name;
jref["Type"] = helper::GetDataType<T>();
jref["ShapeID"] = variable.m_ShapeID;
jref["Start"] = vStart;
jref["Count"] = vCount;
jref["Shape"] = vShape;
jref["BufferStart"] = 0;
jref["BufferCount"] = 0;

ssc::JsonToBlockVecVec(m_GlobalWritePatternJson, m_GlobalWritePattern);
size_t oldSize = m_AllReceivingWriterRanks.size();
m_AllReceivingWriterRanks =
ssc::CalculateOverlap(m_GlobalWritePattern, m_LocalReadPattern);
CalculatePosition(m_GlobalWritePattern, m_AllReceivingWriterRanks);
size_t newSize = m_AllReceivingWriterRanks.size();
if (oldSize != newSize)
{
size_t totalDataSize = 0;
for (auto i : m_AllReceivingWriterRanks)
{
totalDataSize += i.second.second;
}
m_Buffer.resize(totalDataSize);
for (const auto &i : m_AllReceivingWriterRanks)
{
for (const auto &b : m_GlobalWritePattern[i.first])
{
if (b.name == variable.m_Name)
{
std::vector<char> str(b.bufferCount);
std::memcpy(str.data(), m_Buffer.data() + b.bufferStart,
b.bufferCount);
*data = std::string(str.begin(), str.end());
}
}
MPI_Win_lock(MPI_LOCK_SHARED, i.first, 0, m_MpiWin);
MPI_Get(m_Buffer.data() + i.second.first,
static_cast<int>(i.second.second), MPI_CHAR, i.first, 0,
static_cast<int>(i.second.second), MPI_CHAR, m_MpiWin);
MPI_Win_unlock(i.first, m_MpiWin);
m_ReceivedRanks.insert(i.first);
}
}
else
}

template <>
void SscReader::GetDeferredCommon(Variable<std::string> &variable,
std::string *data)
{
TAU_SCOPED_TIMER_FUNC();
variable.SetData(data);

if (m_CurrentStep == 0 || m_WriterDefinitionsLocked == false ||
m_ReaderSelectionsLocked == false)
{
GetDeferredDeltaCommon(variable);
}
for (const auto &i : m_AllReceivingWriterRanks)
{
for (const auto &i : m_AllReceivingWriterRanks)
const auto &v = m_GlobalWritePattern[i.first];
for (const auto &b : v)
{
const auto &v = m_GlobalWritePattern[i.first];
for (const auto &b : v)
if (b.name == variable.m_Name)
{
if (b.name == variable.m_Name)
{
*data = std::string(b.value.begin(), b.value.end());
}
*data = std::string(b.value.begin(), b.value.end());
}
}
}
Expand All @@ -108,7 +122,6 @@ template <class T>
void SscReader::GetDeferredCommon(Variable<T> &variable, T *data)
{
TAU_SCOPED_TIMER_FUNC();

variable.SetData(data);

Dims vStart = variable.m_Start;
Expand All @@ -125,58 +138,7 @@ void SscReader::GetDeferredCommon(Variable<T> &variable, T *data)
if (m_CurrentStep == 0 || m_WriterDefinitionsLocked == false ||
m_ReaderSelectionsLocked == false)
{
m_LocalReadPattern.emplace_back();
auto &b = m_LocalReadPattern.back();
b.name = variable.m_Name;
b.count = vCount;
b.start = vStart;
b.shape = vShape;
b.type = helper::GetDataType<T>();

for (const auto &d : b.count)
{
if (d == 0)
{
throw(std::runtime_error(
"SetSelection count dimensions cannot be 0"));
}
}

m_LocalReadPatternJson["Variables"].emplace_back();
auto &jref = m_LocalReadPatternJson["Variables"].back();
jref["Name"] = variable.m_Name;
jref["Type"] = helper::GetDataType<T>();
jref["ShapeID"] = variable.m_ShapeID;
jref["Start"] = vStart;
jref["Count"] = vCount;
jref["Shape"] = vShape;
jref["BufferStart"] = 0;
jref["BufferCount"] = 0;

ssc::JsonToBlockVecVec(m_GlobalWritePatternJson, m_GlobalWritePattern);
size_t oldSize = m_AllReceivingWriterRanks.size();
m_AllReceivingWriterRanks =
ssc::CalculateOverlap(m_GlobalWritePattern, m_LocalReadPattern);
CalculatePosition(m_GlobalWritePattern, m_AllReceivingWriterRanks);
size_t newSize = m_AllReceivingWriterRanks.size();
if (oldSize != newSize)
{
size_t totalDataSize = 0;
for (auto i : m_AllReceivingWriterRanks)
{
totalDataSize += i.second.second;
}
m_Buffer.resize(totalDataSize);
for (const auto &i : m_AllReceivingWriterRanks)
{
MPI_Win_lock(MPI_LOCK_SHARED, i.first, 0, m_MpiWin);
MPI_Get(m_Buffer.data() + i.second.first,
static_cast<int>(i.second.second), MPI_CHAR, i.first, 0,
static_cast<int>(i.second.second), MPI_CHAR, m_MpiWin);
MPI_Win_unlock(i.first, m_MpiWin);
m_ReceivedRanks.insert(i.first);
}
}
GetDeferredDeltaCommon(variable);
}

for (const auto &i : m_AllReceivingWriterRanks)
Expand Down
3 changes: 3 additions & 0 deletions testing/adios2/engine/ssc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ if(ADIOS2_HAVE_MPI)
gtest_add_tests_helper(Base MPI_ONLY Ssc Engine.SSC. "")
SetupTestPipeline(Engine.SSC.SscEngineTest.TestSscBase.MPI "" TRUE)

gtest_add_tests_helper(String MPI_ONLY Ssc Engine.SSC. "")
SetupTestPipeline(Engine.SSC.SscEngineTest.TestSscString.MPI "" TRUE)

gtest_add_tests_helper(BaseUnlocked MPI_ONLY Ssc Engine.SSC. "")
SetupTestPipeline(Engine.SSC.SscEngineTest.TestSscBaseUnlocked.MPI "" TRUE)

Expand Down
Loading

0 comments on commit fe0b464

Please sign in to comment.