Skip to content

Commit

Permalink
PackInfo MPI buffer alignment bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad authored and RudolfWeeber committed Oct 15, 2024
1 parent 733068d commit 9a0f986
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "core/cell/CellInterval.h"
#include "stencil/Directions.h"

#include <cstddef>

#if (defined WALBERLA_CXX_COMPILER_IS_GNU) || (defined WALBERLA_CXX_COMPILER_IS_CLANG)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
Expand Down Expand Up @@ -519,6 +521,7 @@ static FUNC_PREFIX void unpack_NE(double *RESTRICT const _data_buffer, double *R
} // namespace internal_unpack_NE

void PackInfoPdfDoublePrecision::pack(Direction dir, unsigned char *byte_buffer, IBlock *block) const {
byte_buffer += sizeof(double) - (reinterpret_cast<std::size_t>(byte_buffer) - (reinterpret_cast<std::size_t>(byte_buffer) / sizeof(double)) * sizeof(double));
double *buffer = reinterpret_cast<double *>(byte_buffer);

auto pdfs = block->getData<field::GhostLayerField<double, 19>>(pdfsID);
Expand Down Expand Up @@ -893,6 +896,7 @@ void PackInfoPdfDoublePrecision::pack(Direction dir, unsigned char *byte_buffer,
}

void PackInfoPdfDoublePrecision::unpack(Direction dir, unsigned char *byte_buffer, IBlock *block) const {
byte_buffer += sizeof(double) - (reinterpret_cast<std::size_t>(byte_buffer) - (reinterpret_cast<std::size_t>(byte_buffer) / sizeof(double)) * sizeof(double));
double *buffer = reinterpret_cast<double *>(byte_buffer);

auto pdfs = block->getData<field::GhostLayerField<double, 19>>(pdfsID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PackInfoPdfDoublePrecision
void unpackData(IBlock *receiver, stencil::Direction dir,
mpi::RecvBuffer &buffer) {
const auto dataSize = size(dir, receiver);
unpack(dir, buffer.skip(dataSize), receiver);
unpack(dir, buffer.skip(dataSize + sizeof(double)), receiver);
}

void communicateLocal(const IBlock *sender, IBlock *receiver,
Expand All @@ -68,7 +68,8 @@ class PackInfoPdfDoublePrecision
void packDataImpl(const IBlock *sender, stencil::Direction dir,
mpi::SendBuffer &outBuffer) const {
const auto dataSize = size(dir, sender);
pack(dir, outBuffer.forward(dataSize), const_cast<IBlock *>(sender));
pack(dir, outBuffer.forward(dataSize + sizeof(double)),
const_cast<IBlock *>(sender));
}

void pack(stencil::Direction dir, unsigned char *buffer, IBlock *block) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "core/cell/CellInterval.h"
#include "stencil/Directions.h"

#include <cstddef>

#if (defined WALBERLA_CXX_COMPILER_IS_GNU) || (defined WALBERLA_CXX_COMPILER_IS_CLANG)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
Expand Down Expand Up @@ -519,6 +521,7 @@ static FUNC_PREFIX void unpack_NE(float *RESTRICT const _data_buffer, float *RES
} // namespace internal_unpack_NE

void PackInfoPdfSinglePrecision::pack(Direction dir, unsigned char *byte_buffer, IBlock *block) const {
byte_buffer += sizeof(float) - (reinterpret_cast<std::size_t>(byte_buffer) - (reinterpret_cast<std::size_t>(byte_buffer) / sizeof(float)) * sizeof(float));
float *buffer = reinterpret_cast<float *>(byte_buffer);

auto pdfs = block->getData<field::GhostLayerField<float, 19>>(pdfsID);
Expand Down Expand Up @@ -893,6 +896,7 @@ void PackInfoPdfSinglePrecision::pack(Direction dir, unsigned char *byte_buffer,
}

void PackInfoPdfSinglePrecision::unpack(Direction dir, unsigned char *byte_buffer, IBlock *block) const {
byte_buffer += sizeof(float) - (reinterpret_cast<std::size_t>(byte_buffer) - (reinterpret_cast<std::size_t>(byte_buffer) / sizeof(float)) * sizeof(float));
float *buffer = reinterpret_cast<float *>(byte_buffer);

auto pdfs = block->getData<field::GhostLayerField<float, 19>>(pdfsID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PackInfoPdfSinglePrecision
void unpackData(IBlock *receiver, stencil::Direction dir,
mpi::RecvBuffer &buffer) {
const auto dataSize = size(dir, receiver);
unpack(dir, buffer.skip(dataSize), receiver);
unpack(dir, buffer.skip(dataSize + sizeof(float)), receiver);
}

void communicateLocal(const IBlock *sender, IBlock *receiver,
Expand All @@ -68,7 +68,8 @@ class PackInfoPdfSinglePrecision
void packDataImpl(const IBlock *sender, stencil::Direction dir,
mpi::SendBuffer &outBuffer) const {
const auto dataSize = size(dir, sender);
pack(dir, outBuffer.forward(dataSize), const_cast<IBlock *>(sender));
pack(dir, outBuffer.forward(dataSize + sizeof(float)),
const_cast<IBlock *>(sender));
}

void pack(stencil::Direction dir, unsigned char *buffer, IBlock *block) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "core/cell/CellInterval.h"
#include "stencil/Directions.h"

#include <cstddef>

#if (defined WALBERLA_CXX_COMPILER_IS_GNU) || (defined WALBERLA_CXX_COMPILER_IS_CLANG)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
Expand Down Expand Up @@ -67,6 +69,7 @@ static FUNC_PREFIX void unpack_SW_BW_W_TW_NW_BS_S_TS_B_C_T_BN_N_TN_SE_BE_E_TE_NE
} // namespace internal_1ccccad4ca561e07a0934cadb07d0fc1

void PackInfoVecDoublePrecision::pack(Direction dir, unsigned char *byte_buffer, IBlock *block) const {
byte_buffer += sizeof(double) - (reinterpret_cast<std::size_t>(byte_buffer) - (reinterpret_cast<std::size_t>(byte_buffer) / sizeof(double)) * sizeof(double));
double *buffer = reinterpret_cast<double *>(byte_buffer);

auto field = block->getData<field::GhostLayerField<double, 3>>(fieldID);
Expand Down Expand Up @@ -119,6 +122,7 @@ void PackInfoVecDoublePrecision::pack(Direction dir, unsigned char *byte_buffer,
}

void PackInfoVecDoublePrecision::unpack(Direction dir, unsigned char *byte_buffer, IBlock *block) const {
byte_buffer += sizeof(double) - (reinterpret_cast<std::size_t>(byte_buffer) - (reinterpret_cast<std::size_t>(byte_buffer) / sizeof(double)) * sizeof(double));
double *buffer = reinterpret_cast<double *>(byte_buffer);

auto field = block->getData<field::GhostLayerField<double, 3>>(fieldID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PackInfoVecDoublePrecision
void unpackData(IBlock *receiver, stencil::Direction dir,
mpi::RecvBuffer &buffer) {
const auto dataSize = size(dir, receiver);
unpack(dir, buffer.skip(dataSize), receiver);
unpack(dir, buffer.skip(dataSize + sizeof(double)), receiver);
}

void communicateLocal(const IBlock *sender, IBlock *receiver,
Expand All @@ -68,7 +68,8 @@ class PackInfoVecDoublePrecision
void packDataImpl(const IBlock *sender, stencil::Direction dir,
mpi::SendBuffer &outBuffer) const {
const auto dataSize = size(dir, sender);
pack(dir, outBuffer.forward(dataSize), const_cast<IBlock *>(sender));
pack(dir, outBuffer.forward(dataSize + sizeof(double)),
const_cast<IBlock *>(sender));
}

void pack(stencil::Direction dir, unsigned char *buffer, IBlock *block) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "core/cell/CellInterval.h"
#include "stencil/Directions.h"

#include <cstddef>

#if (defined WALBERLA_CXX_COMPILER_IS_GNU) || (defined WALBERLA_CXX_COMPILER_IS_CLANG)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
Expand Down Expand Up @@ -67,6 +69,7 @@ static FUNC_PREFIX void unpack_SW_BW_W_TW_NW_BS_S_TS_B_C_T_BN_N_TN_SE_BE_E_TE_NE
} // namespace internal_1ccccad4ca561e07a0934cadb07d0fc1

void PackInfoVecSinglePrecision::pack(Direction dir, unsigned char *byte_buffer, IBlock *block) const {
byte_buffer += sizeof(float) - (reinterpret_cast<std::size_t>(byte_buffer) - (reinterpret_cast<std::size_t>(byte_buffer) / sizeof(float)) * sizeof(float));
float *buffer = reinterpret_cast<float *>(byte_buffer);

auto field = block->getData<field::GhostLayerField<float, 3>>(fieldID);
Expand Down Expand Up @@ -119,6 +122,7 @@ void PackInfoVecSinglePrecision::pack(Direction dir, unsigned char *byte_buffer,
}

void PackInfoVecSinglePrecision::unpack(Direction dir, unsigned char *byte_buffer, IBlock *block) const {
byte_buffer += sizeof(float) - (reinterpret_cast<std::size_t>(byte_buffer) - (reinterpret_cast<std::size_t>(byte_buffer) / sizeof(float)) * sizeof(float));
float *buffer = reinterpret_cast<float *>(byte_buffer);

auto field = block->getData<field::GhostLayerField<float, 3>>(fieldID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PackInfoVecSinglePrecision
void unpackData(IBlock *receiver, stencil::Direction dir,
mpi::RecvBuffer &buffer) {
const auto dataSize = size(dir, receiver);
unpack(dir, buffer.skip(dataSize), receiver);
unpack(dir, buffer.skip(dataSize + sizeof(float)), receiver);
}

void communicateLocal(const IBlock *sender, IBlock *receiver,
Expand All @@ -68,7 +68,8 @@ class PackInfoVecSinglePrecision
void packDataImpl(const IBlock *sender, stencil::Direction dir,
mpi::SendBuffer &outBuffer) const {
const auto dataSize = size(dir, sender);
pack(dir, outBuffer.forward(dataSize), const_cast<IBlock *>(sender));
pack(dir, outBuffer.forward(dataSize + sizeof(float)),
const_cast<IBlock *>(sender));
}

void pack(stencil::Direction dir, unsigned char *buffer, IBlock *block) const;
Expand Down

0 comments on commit 9a0f986

Please sign in to comment.