Skip to content

Commit

Permalink
Merge pull request #3882 from vicentebolea/backport-3877
Browse files Browse the repository at this point in the history
Backport 3877 to master
  • Loading branch information
vicentebolea committed Oct 30, 2023
2 parents 14a0a3a + 863aa4e commit 2054006
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
29 changes: 12 additions & 17 deletions source/adios2/toolkit/format/bp5/BP5Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ namespace format
BP5Serializer::BP5Serializer() { Init(); }
BP5Serializer::~BP5Serializer()
{
if (Info.RecList)
if (!Info.RecMap.empty())
{
for (int i = 0; i < Info.RecCount; i++)
for (auto &rec : Info.RecMap)
{
if (Info.RecList[i].OperatorType)
free(Info.RecList[i].OperatorType);
if (rec.second.OperatorType)
free(rec.second.OperatorType);
}
free(Info.RecList);
Info.RecMap.clear();
}
if (Info.MetaFieldCount)
free_FMfield_list(Info.MetaFields);
Expand All @@ -64,7 +64,6 @@ void BP5Serializer::Init()
// Re-init Info to zero
Info = FFSWriterMarshalBase();
Info.RecCount = 0;
Info.RecList = (BP5Serializer::BP5WriterRec)malloc(sizeof(Info.RecList[0]));
Info.MetaFieldCount = 0;
Info.MetaFields = NULL;
Info.LocalFMContext = create_local_FMcontext();
Expand All @@ -82,14 +81,11 @@ void BP5Serializer::Init()
}
BP5Serializer::BP5WriterRec BP5Serializer::LookupWriterRec(void *Key) const
{
for (int i = 0; i < Info.RecCount; i++)
auto it = Info.RecMap.find(Key);
if (it != Info.RecMap.end())
{
if (Info.RecList[i].Key == Key)
{
return &Info.RecList[i];
}
return const_cast<BP5WriterRec>(&(it->second));
}

return NULL;
}

Expand Down Expand Up @@ -424,9 +420,8 @@ BP5Serializer::BP5WriterRec BP5Serializer::CreateWriterRec(void *Variable, const
size_t DimCount)
{
core::VariableBase *VB = static_cast<core::VariableBase *>(Variable);
Info.RecList =
(BP5WriterRec)realloc(Info.RecList, (Info.RecCount + 1) * sizeof(Info.RecList[0]));
BP5WriterRec Rec = &Info.RecList[Info.RecCount];
auto obj = Info.RecMap.insert(std::make_pair(Variable, _BP5WriterRec()));
BP5WriterRec Rec = &obj.first->second;
if (Type == DataType::String)
ElemSize = sizeof(char *);
Rec->Key = Variable;
Expand Down Expand Up @@ -1128,9 +1123,9 @@ BufferV *BP5Serializer::ReinitStepData(BufferV *DataBuffer, bool forceCopyDeferr

void BP5Serializer::CollectFinalShapeValues()
{
for (int i = 0; i < Info.RecCount; i++)
for (auto it : Info.RecMap)
{
BP5WriterRec Rec = &Info.RecList[i];
BP5WriterRec Rec = &it.second;
if (Rec->Shape == ShapeID::GlobalArray)
{
core::VariableBase *VB = static_cast<core::VariableBase *>(Rec->Key);
Expand Down
4 changes: 3 additions & 1 deletion source/adios2/toolkit/format/bp5/BP5Serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#pragma warning(disable : 4250)
#endif

#include <unordered_map>

namespace adios2
{
namespace format
Expand Down Expand Up @@ -156,7 +158,6 @@ class BP5Serializer : virtual public BP5Base
struct FFSWriterMarshalBase
{
int RecCount = 0;
BP5WriterRec RecList = NULL;
FMContext LocalFMContext = {0};
int MetaFieldCount = 0;
FMFieldList MetaFields = NULL;
Expand All @@ -166,6 +167,7 @@ class BP5Serializer : virtual public BP5Base
FMFormat AttributeFormat = NULL;
void *AttributeData = NULL;
int AttributeSize = 0;
std::unordered_map<void *, _BP5WriterRec> RecMap;
};

FMFormat GenericAttributeFormat = NULL;
Expand Down

0 comments on commit 2054006

Please sign in to comment.