Skip to content
Snippets Groups Projects
Commit dd7f4712 authored by William F Godoy's avatar William F Godoy
Browse files

Started working on bpthreads branch

Changed adiosTemplates.h and BP1 functions for STL's insert and copy to
a Buffer in sequential mode
parent 1eafa415
No related branches found
No related tags found
1 merge request!51Dataman bugs
...@@ -271,15 +271,15 @@ void MemcpyToBuffer(std::vector<char> &raw, std::size_t &position, ...@@ -271,15 +271,15 @@ void MemcpyToBuffer(std::vector<char> &raw, std::size_t &position,
* @param elements * @param elements
*/ */
template <class T> template <class T>
void CopyToBuffer(std::vector<char> &buffer, const T *source, void InsertToBuffer(std::vector<char> &buffer, const T *source,
const std::size_t elements = 1) noexcept const std::size_t elements = 1) noexcept
{ {
const char *src = reinterpret_cast<const char *>(source); const char *src = reinterpret_cast<const char *>(source);
buffer.insert(buffer.end(), src, src + elements * sizeof(T)); buffer.insert(buffer.end(), src, src + elements * sizeof(T));
} }
/** /**
* Overloaded version to copies data to a specific location in the buffer, * Copies data to a specific location in the buffer,
* doesn't update vec.size() * doesn't update vec.size()
* @param raw * @param raw
* @param position * @param position
...@@ -287,8 +287,9 @@ void CopyToBuffer(std::vector<char> &buffer, const T *source, ...@@ -287,8 +287,9 @@ void CopyToBuffer(std::vector<char> &buffer, const T *source,
* @param elements * @param elements
*/ */
template <class T> template <class T>
void CopyToBuffer(std::vector<char> &buffer, const std::size_t position, void CopyToBufferPosition(std::vector<char> &buffer, const std::size_t position,
const T *source, const std::size_t elements = 1) noexcept const T *source,
const std::size_t elements = 1) noexcept
{ {
const char *src = reinterpret_cast<const char *>(source); const char *src = reinterpret_cast<const char *>(source);
std::copy(src, src + elements * sizeof(T), buffer.begin() + position); std::copy(src, src + elements * sizeof(T), buffer.begin() + position);
......
...@@ -228,19 +228,19 @@ private: ...@@ -228,19 +228,19 @@ private:
WriteNameRecord(variable.m_Name, buffer); // variable name WriteNameRecord(variable.m_Name, buffer); // variable name
buffer.insert(buffer.end(), 2, 0); // skip path buffer.insert(buffer.end(), 2, 0); // skip path
const std::uint8_t dataType = GetDataType<T>(); // dataType const std::uint8_t dataType = GetDataType<T>(); // dataType
CopyToBuffer(buffer, &dataType); InsertToBuffer(buffer, &dataType);
constexpr char no = 'n'; // isDimension constexpr char no = 'n'; // isDimension
CopyToBuffer(buffer, &no); InsertToBuffer(buffer, &no);
// write variable dimensions // write variable dimensions
const std::uint8_t dimensions = variable.m_LocalDimensions.size(); const std::uint8_t dimensions = variable.m_LocalDimensions.size();
CopyToBuffer(buffer, &dimensions); // count InsertToBuffer(buffer, &dimensions); // count
std::uint16_t dimensionsLength = std::uint16_t dimensionsLength =
27 * 27 *
dimensions; // 27 is from 9 bytes for each: var y/n + local, var dimensions; // 27 is from 9 bytes for each: var y/n + local, var
// y/n + global dimension, var y/n + global offset, // y/n + global dimension, var y/n + global offset,
// changed for characteristic // changed for characteristic
CopyToBuffer(buffer, &dimensionsLength); // length InsertToBuffer(buffer, &dimensionsLength); // length
WriteDimensionsRecord(buffer, variable.m_LocalDimensions, WriteDimensionsRecord(buffer, variable.m_LocalDimensions,
variable.m_GlobalDimensions, variable.m_Offsets, variable.m_GlobalDimensions, variable.m_Offsets,
18, true); 18, true);
...@@ -252,7 +252,7 @@ private: ...@@ -252,7 +252,7 @@ private:
const std::uint64_t varLength = buffer.size() - varLengthPosition + const std::uint64_t varLength = buffer.size() - varLengthPosition +
variable.PayLoadSize() - variable.PayLoadSize() -
8; // remove its own size 8; // remove its own size
CopyToBuffer(buffer, varLengthPosition, &varLength); // length CopyToBufferPosition(buffer, varLengthPosition, &varLength); // length
heap.m_DataAbsolutePosition += heap.m_DataAbsolutePosition +=
buffer.size() - varLengthPosition; // update absolute position to be buffer.size() - varLengthPosition; // update absolute position to be
...@@ -276,19 +276,19 @@ private: ...@@ -276,19 +276,19 @@ private:
buffer.insert(buffer.end(), 2, 0); // skip path buffer.insert(buffer.end(), 2, 0); // skip path
const std::uint8_t dataType = GetDataType<T>(); const std::uint8_t dataType = GetDataType<T>();
CopyToBuffer(buffer, &dataType); InsertToBuffer(buffer, &dataType);
// Characteristics Sets Count in Metadata // Characteristics Sets Count in Metadata
index.Count = 1; index.Count = 1;
CopyToBuffer(buffer, &index.Count); InsertToBuffer(buffer, &index.Count);
} }
else // update characteristics sets count else // update characteristics sets count
{ {
const std::size_t characteristicsSetsCountPosition = const std::size_t characteristicsSetsCountPosition =
15 + variable.m_Name.size(); 15 + variable.m_Name.size();
++index.Count; ++index.Count;
CopyToBuffer(buffer, characteristicsSetsCountPosition, CopyToBufferPosition(buffer, characteristicsSetsCountPosition,
&index.Count); // test &index.Count); // test
} }
WriteVariableCharacteristics(variable, stats, buffer); WriteVariableCharacteristics(variable, stats, buffer);
...@@ -310,20 +310,20 @@ private: ...@@ -310,20 +310,20 @@ private:
// DIMENSIONS // DIMENSIONS
std::uint8_t characteristicID = characteristic_dimensions; std::uint8_t characteristicID = characteristic_dimensions;
CopyToBuffer(buffer, &characteristicID); InsertToBuffer(buffer, &characteristicID);
const std::uint8_t dimensions = variable.m_LocalDimensions.size(); const std::uint8_t dimensions = variable.m_LocalDimensions.size();
if (addLength == true) if (addLength == true)
{ {
const std::int16_t lengthOfDimensionsCharacteristic = const std::int16_t lengthOfDimensionsCharacteristic =
24 * dimensions + 24 * dimensions +
3; // 24 = 3 local, global, global offset x 8 bytes/each 3; // 24 = 3 local, global, offset x 8 bytes/each
CopyToBuffer(buffer, &lengthOfDimensionsCharacteristic); InsertToBuffer(buffer, &lengthOfDimensionsCharacteristic);
} }
CopyToBuffer(buffer, &dimensions); // count InsertToBuffer(buffer, &dimensions); // count
const std::uint16_t dimensionsLength = 24 * dimensions; const std::uint16_t dimensionsLength = 24 * dimensions;
CopyToBuffer(buffer, &dimensionsLength); // length InsertToBuffer(buffer, &dimensionsLength); // length
WriteDimensionsRecord(buffer, variable.m_LocalDimensions, WriteDimensionsRecord(buffer, variable.m_LocalDimensions,
variable.m_GlobalDimensions, variable.m_Offsets, variable.m_GlobalDimensions, variable.m_Offsets,
16, addLength); 16, addLength);
...@@ -347,15 +347,15 @@ private: ...@@ -347,15 +347,15 @@ private:
// END OF CHARACTERISTICS // END OF CHARACTERISTICS
// Back to characteristics count and length // Back to characteristics count and length
CopyToBuffer(buffer, characteristicsCountPosition, CopyToBufferPosition(buffer, characteristicsCountPosition,
&characteristicsCounter); // count (1) &characteristicsCounter); // count (1)
const std::uint32_t characteristicsLength = const std::uint32_t characteristicsLength =
buffer.size() - characteristicsCountPosition - 4 - buffer.size() - characteristicsCountPosition - 4 -
1; // remove its own length (4 bytes) + characteristic counter ( 1 1; // remove its own length (4 bytes) + characteristic counter ( 1
// byte // byte
// ) // )
CopyToBuffer(buffer, characteristicsCountPosition + 1, CopyToBufferPosition(buffer, characteristicsCountPosition + 1,
&characteristicsLength); // length &characteristicsLength); // length
} }
/** /**
...@@ -480,12 +480,12 @@ private: ...@@ -480,12 +480,12 @@ private:
const bool addLength = false) const noexcept const bool addLength = false) const noexcept
{ {
const std::uint8_t id = characteristicID; const std::uint8_t id = characteristicID;
CopyToBuffer(buffer, &id); InsertToBuffer(buffer, &id);
if (addLength == true) if (addLength == true)
{ {
const std::uint16_t lengthOfCharacteristic = sizeof(T); // id const std::uint16_t lengthOfCharacteristic = sizeof(T); // id
CopyToBuffer(buffer, &lengthOfCharacteristic); InsertToBuffer(buffer, &lengthOfCharacteristic);
} }
CopyToBuffer(buffer, &value); CopyToBuffer(buffer, &value);
...@@ -521,9 +521,7 @@ private: ...@@ -521,9 +521,7 @@ private:
* @param buffer * @param buffer
*/ */
void FlattenMetadata(BP1MetadataSet &metadataSet, void FlattenMetadata(BP1MetadataSet &metadataSet,
capsule::STLVector &buffer) const capsule::STLVector &buffer) const noexcept;
noexcept; ///< sets the metadata buffer in capsule with indices and
/// minifooter
}; };
} // end namespace format } // end namespace format
......
...@@ -50,13 +50,13 @@ void BP1Writer::WriteProcessGroupIndex( ...@@ -50,13 +50,13 @@ void BP1Writer::WriteProcessGroupIndex(
// write if host language Fortran in metadata and data // write if host language Fortran in metadata and data
const char hostFortran = const char hostFortran =
(isFortran) ? 'y' : 'n'; // if host language is fortran (isFortran) ? 'y' : 'n'; // if host language is fortran
CopyToBuffer(metadataBuffer, &hostFortran); InsertToBuffer(metadataBuffer, &hostFortran);
CopyToBuffer(dataBuffer, &hostFortran); InsertToBuffer(dataBuffer, &hostFortran);
// write name in data // write name in data
WriteNameRecord(name, dataBuffer); WriteNameRecord(name, dataBuffer);
// processID in metadata, // processID in metadata,
CopyToBuffer(metadataBuffer, &processID); InsertToBuffer(metadataBuffer, &processID);
// skip coordination var in data ....what is coordination var? // skip coordination var in data ....what is coordination var?
dataBuffer.insert(dataBuffer.end(), 4, 0); dataBuffer.insert(dataBuffer.end(), 4, 0);
...@@ -66,33 +66,33 @@ void BP1Writer::WriteProcessGroupIndex( ...@@ -66,33 +66,33 @@ void BP1Writer::WriteProcessGroupIndex(
WriteNameRecord(timeStepName, dataBuffer); WriteNameRecord(timeStepName, dataBuffer);
// time step to metadata and data // time step to metadata and data
CopyToBuffer(metadataBuffer, &metadataSet.TimeStep); InsertToBuffer(metadataBuffer, &metadataSet.TimeStep);
CopyToBuffer(dataBuffer, &metadataSet.TimeStep); InsertToBuffer(dataBuffer, &metadataSet.TimeStep);
// offset to pg in data in metadata which is the current absolute position // offset to pg in data in metadata which is the current absolute position
CopyToBuffer(metadataBuffer, reinterpret_cast<std::uint64_t *>( InsertToBuffer(metadataBuffer, reinterpret_cast<std::uint64_t *>(
&heap.m_DataAbsolutePosition)); &heap.m_DataAbsolutePosition));
// Back to writing metadata pg index length (length of group) // Back to writing metadata pg index length (length of group)
const std::uint16_t metadataPGIndexLength = const std::uint16_t metadataPGIndexLength =
metadataBuffer.size() - metadataPGLengthPosition - metadataBuffer.size() - metadataPGLengthPosition -
2; // without length of group record 2; // without length of group record
CopyToBuffer(metadataBuffer, metadataPGLengthPosition, CopyToBufferPosition(metadataBuffer, metadataPGLengthPosition,
&metadataPGIndexLength); &metadataPGIndexLength);
// DONE With metadataBuffer // DONE With metadataBuffer
// here write method in data // here write method in data
const std::vector<std::uint8_t> methodIDs = GetMethodIDs(transports); const std::vector<std::uint8_t> methodIDs = GetMethodIDs(transports);
const std::uint8_t methodsCount = methodIDs.size(); const std::uint8_t methodsCount = methodIDs.size();
CopyToBuffer(dataBuffer, &methodsCount); // count InsertToBuffer(dataBuffer, &methodsCount); // count
const std::uint16_t methodsLength = const std::uint16_t methodsLength =
methodIDs.size() * methodIDs.size() *
3; // methodID (1) + method params length(2), no parameters for now 3; // methodID (1) + method params length(2), no parameters for now
CopyToBuffer(dataBuffer, &methodsLength); // length InsertToBuffer(dataBuffer, &methodsLength); // length
for (const auto methodID : methodIDs) for (const auto methodID : methodIDs)
{ {
CopyToBuffer(dataBuffer, &methodID); // method ID, InsertToBuffer(dataBuffer, &methodID); // method ID,
dataBuffer.insert(dataBuffer.end(), 2, dataBuffer.insert(dataBuffer.end(), 2,
0); // skip method params length = 0 (2 bytes) for now 0); // skip method params length = 0 (2 bytes) for now
} }
...@@ -213,9 +213,9 @@ void BP1Writer::WriteDimensionsRecord( ...@@ -213,9 +213,9 @@ void BP1Writer::WriteDimensionsRecord(
{ {
auto lf_WriteFlaggedDim = [](std::vector<char> &buffer, const char no, auto lf_WriteFlaggedDim = [](std::vector<char> &buffer, const char no,
const std::size_t dimension) { const std::size_t dimension) {
CopyToBuffer(buffer, &no); InsertToBuffer(buffer, &no);
CopyToBuffer(buffer, InsertToBuffer(buffer,
reinterpret_cast<const std::uint64_t *>(&dimension)); reinterpret_cast<const std::uint64_t *>(&dimension));
}; };
// BODY Starts here // BODY Starts here
...@@ -236,8 +236,8 @@ void BP1Writer::WriteDimensionsRecord( ...@@ -236,8 +236,8 @@ void BP1Writer::WriteDimensionsRecord(
{ {
for (const auto &localDimension : localDimensions) for (const auto &localDimension : localDimensions)
{ {
CopyToBuffer(buffer, reinterpret_cast<const std::uint64_t *>( InsertToBuffer(buffer, reinterpret_cast<const std::uint64_t *>(
&localDimension)); &localDimension));
buffer.insert(buffer.end(), skip, 0); buffer.insert(buffer.end(), skip, 0);
} }
} }
...@@ -258,12 +258,12 @@ void BP1Writer::WriteDimensionsRecord( ...@@ -258,12 +258,12 @@ void BP1Writer::WriteDimensionsRecord(
{ {
for (unsigned int d = 0; d < localDimensions.size(); ++d) for (unsigned int d = 0; d < localDimensions.size(); ++d)
{ {
CopyToBuffer(buffer, reinterpret_cast<const std::uint64_t *>( InsertToBuffer(buffer, reinterpret_cast<const std::uint64_t *>(
&localDimensions[d])); &localDimensions[d]));
CopyToBuffer(buffer, reinterpret_cast<const std::uint64_t *>( InsertToBuffer(buffer, reinterpret_cast<const std::uint64_t *>(
&globalDimensions[d])); &globalDimensions[d]));
CopyToBuffer(buffer, reinterpret_cast<const std::uint64_t *>( InsertToBuffer(buffer, reinterpret_cast<const std::uint64_t *>(
&globalOffsets[d])); &globalOffsets[d]));
} }
} }
} }
...@@ -273,8 +273,8 @@ void BP1Writer::WriteNameRecord(const std::string name, ...@@ -273,8 +273,8 @@ void BP1Writer::WriteNameRecord(const std::string name,
std::vector<char> &buffer) const noexcept std::vector<char> &buffer) const noexcept
{ {
const std::uint16_t length = name.length(); const std::uint16_t length = name.length();
CopyToBuffer(buffer, &length); InsertToBuffer(buffer, &length);
CopyToBuffer(buffer, name.c_str(), length); InsertToBuffer(buffer, name.c_str(), length);
} }
BP1Index & BP1Index &
...@@ -299,12 +299,13 @@ void BP1Writer::FlattenData(BP1MetadataSet &metadataSet, ...@@ -299,12 +299,13 @@ void BP1Writer::FlattenData(BP1MetadataSet &metadataSet,
{ {
auto &buffer = heap.m_Data; auto &buffer = heap.m_Data;
// vars count and Length (only for PG) // vars count and Length (only for PG)
CopyToBuffer(buffer, metadataSet.DataPGVarsCountPosition, CopyToBufferPosition(buffer, metadataSet.DataPGVarsCountPosition,
&metadataSet.DataPGVarsCount); &metadataSet.DataPGVarsCount);
const std::uint64_t varsLength = buffer.size() - const std::uint64_t varsLength = buffer.size() -
metadataSet.DataPGVarsCountPosition - 8 - metadataSet.DataPGVarsCountPosition - 8 -
4; // without record itself and vars count 4; // without record itself and vars count
CopyToBuffer(buffer, metadataSet.DataPGVarsCountPosition + 4, &varsLength); CopyToBufferPosition(buffer, metadataSet.DataPGVarsCountPosition + 4,
&varsLength);
// attributes (empty for now) count (4) and length (8) are zero by moving // attributes (empty for now) count (4) and length (8) are zero by moving
// positions in time step zero // positions in time step zero
...@@ -315,7 +316,8 @@ void BP1Writer::FlattenData(BP1MetadataSet &metadataSet, ...@@ -315,7 +316,8 @@ void BP1Writer::FlattenData(BP1MetadataSet &metadataSet,
const std::uint64_t dataPGLength = const std::uint64_t dataPGLength =
buffer.size() - metadataSet.DataPGLengthPosition - buffer.size() - metadataSet.DataPGLengthPosition -
8; // without record itself, 12 due to empty attributes 8; // without record itself, 12 due to empty attributes
CopyToBuffer(buffer, metadataSet.DataPGLengthPosition, &dataPGLength); CopyToBufferPosition(buffer, metadataSet.DataPGLengthPosition,
&dataPGLength);
++metadataSet.TimeStep; ++metadataSet.TimeStep;
metadataSet.DataPGIsOpen = false; metadataSet.DataPGIsOpen = false;
...@@ -334,7 +336,7 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet, ...@@ -334,7 +336,7 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet,
{ {
auto &indexBuffer = indexPair.second.Buffer; auto &indexBuffer = indexPair.second.Buffer;
const std::uint32_t indexLength = indexBuffer.size() - 4; const std::uint32_t indexLength = indexBuffer.size() - 4;
CopyToBuffer(indexBuffer, 0, &indexLength); CopyToBufferPosition(indexBuffer, 0, &indexLength);
length += indexBuffer.size(); // overall length length += indexBuffer.size(); // overall length
} }
...@@ -344,13 +346,13 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet, ...@@ -344,13 +346,13 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet,
[](const std::uint32_t count, const std::uint64_t length, [](const std::uint32_t count, const std::uint64_t length,
const std::unordered_map<std::string, BP1Index> &indices, const std::unordered_map<std::string, BP1Index> &indices,
std::vector<char> &buffer) { std::vector<char> &buffer) {
CopyToBuffer(buffer, &count); InsertToBuffer(buffer, &count);
CopyToBuffer(buffer, &length); InsertToBuffer(buffer, &length);
for (const auto &indexPair : indices) // set each index length for (const auto &indexPair : indices) // set each index length
{ {
const auto &indexBuffer = indexPair.second.Buffer; const auto &indexBuffer = indexPair.second.Buffer;
CopyToBuffer(buffer, indexBuffer.data(), indexBuffer.size()); InsertToBuffer(buffer, indexBuffer.data(), indexBuffer.size());
} }
}; };
...@@ -378,9 +380,9 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet, ...@@ -378,9 +380,9 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet,
// strategy // strategy
// write pg index // write pg index
CopyToBuffer(buffer, &pgCount); InsertToBuffer(buffer, &pgCount);
CopyToBuffer(buffer, &pgLength); InsertToBuffer(buffer, &pgLength);
CopyToBuffer(buffer, metadataSet.PGIndex.Buffer.data(), pgLength); InsertToBuffer(buffer, metadataSet.PGIndex.Buffer.data(), pgLength);
// Vars indices // Vars indices
lf_FlattenIndices(varsCount, varsLength, metadataSet.VarsIndices, buffer); lf_FlattenIndices(varsCount, varsLength, metadataSet.VarsIndices, buffer);
// Attribute indices // Attribute indices
...@@ -393,17 +395,17 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet, ...@@ -393,17 +395,17 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet,
const std::uint64_t offsetAttributeIndex = const std::uint64_t offsetAttributeIndex =
offsetVarsIndex + (varsLength + 12); offsetVarsIndex + (varsLength + 12);
CopyToBuffer(buffer, &offsetPGIndex); InsertToBuffer(buffer, &offsetPGIndex);
CopyToBuffer(buffer, &offsetVarsIndex); InsertToBuffer(buffer, &offsetVarsIndex);
CopyToBuffer(buffer, &offsetAttributeIndex); InsertToBuffer(buffer, &offsetAttributeIndex);
// version // version
if (IsLittleEndian()) if (IsLittleEndian())
{ {
const std::uint8_t endian = 0; const std::uint8_t endian = 0;
CopyToBuffer(buffer, &endian); InsertToBuffer(buffer, &endian);
buffer.insert(buffer.end(), 2, 0); buffer.insert(buffer.end(), 2, 0);
CopyToBuffer(buffer, &m_Version); InsertToBuffer(buffer, &m_Version);
} }
else else
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment