Skip to content

Commit 960c2ad

Browse files
committed
PackInfo MPI buffer alignment bugfix
1 parent 8ea7111 commit 960c2ad

8 files changed

Lines changed: 28 additions & 8 deletions

src/walberla_bridge/src/lattice_boltzmann/generated_kernels/PackInfoPdfDoublePrecision.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "core/cell/CellInterval.h"
2525
#include "stencil/Directions.h"
2626

27+
#include <cstddef>
28+
2729
#if (defined WALBERLA_CXX_COMPILER_IS_GNU) || (defined WALBERLA_CXX_COMPILER_IS_CLANG)
2830
#pragma GCC diagnostic push
2931
#pragma GCC diagnostic ignored "-Wfloat-equal"
@@ -519,6 +521,7 @@ static FUNC_PREFIX void unpack_NE(double *RESTRICT const _data_buffer, double *R
519521
} // namespace internal_unpack_NE
520522

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

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

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

898902
auto pdfs = block->getData<field::GhostLayerField<double, 19>>(pdfsID);

src/walberla_bridge/src/lattice_boltzmann/generated_kernels/PackInfoPdfDoublePrecision.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class PackInfoPdfDoublePrecision
5454
void unpackData(IBlock *receiver, stencil::Direction dir,
5555
mpi::RecvBuffer &buffer) {
5656
const auto dataSize = size(dir, receiver);
57-
unpack(dir, buffer.skip(dataSize), receiver);
57+
unpack(dir, buffer.skip(dataSize + sizeof(double)), receiver);
5858
}
5959

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

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

src/walberla_bridge/src/lattice_boltzmann/generated_kernels/PackInfoPdfSinglePrecision.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "core/cell/CellInterval.h"
2525
#include "stencil/Directions.h"
2626

27+
#include <cstddef>
28+
2729
#if (defined WALBERLA_CXX_COMPILER_IS_GNU) || (defined WALBERLA_CXX_COMPILER_IS_CLANG)
2830
#pragma GCC diagnostic push
2931
#pragma GCC diagnostic ignored "-Wfloat-equal"
@@ -519,6 +521,7 @@ static FUNC_PREFIX void unpack_NE(float *RESTRICT const _data_buffer, float *RES
519521
} // namespace internal_unpack_NE
520522

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

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

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

898902
auto pdfs = block->getData<field::GhostLayerField<float, 19>>(pdfsID);

src/walberla_bridge/src/lattice_boltzmann/generated_kernels/PackInfoPdfSinglePrecision.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class PackInfoPdfSinglePrecision
5454
void unpackData(IBlock *receiver, stencil::Direction dir,
5555
mpi::RecvBuffer &buffer) {
5656
const auto dataSize = size(dir, receiver);
57-
unpack(dir, buffer.skip(dataSize), receiver);
57+
unpack(dir, buffer.skip(dataSize + sizeof(float)), receiver);
5858
}
5959

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

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

src/walberla_bridge/src/lattice_boltzmann/generated_kernels/PackInfoVecDoublePrecision.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "core/cell/CellInterval.h"
2525
#include "stencil/Directions.h"
2626

27+
#include <cstddef>
28+
2729
#if (defined WALBERLA_CXX_COMPILER_IS_GNU) || (defined WALBERLA_CXX_COMPILER_IS_CLANG)
2830
#pragma GCC diagnostic push
2931
#pragma GCC diagnostic ignored "-Wfloat-equal"
@@ -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
6769
} // namespace internal_1ccccad4ca561e07a0934cadb07d0fc1
6870

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

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

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

124128
auto field = block->getData<field::GhostLayerField<double, 3>>(fieldID);

src/walberla_bridge/src/lattice_boltzmann/generated_kernels/PackInfoVecDoublePrecision.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class PackInfoVecDoublePrecision
5454
void unpackData(IBlock *receiver, stencil::Direction dir,
5555
mpi::RecvBuffer &buffer) {
5656
const auto dataSize = size(dir, receiver);
57-
unpack(dir, buffer.skip(dataSize), receiver);
57+
unpack(dir, buffer.skip(dataSize + sizeof(double)), receiver);
5858
}
5959

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

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

src/walberla_bridge/src/lattice_boltzmann/generated_kernels/PackInfoVecSinglePrecision.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "core/cell/CellInterval.h"
2525
#include "stencil/Directions.h"
2626

27+
#include <cstddef>
28+
2729
#if (defined WALBERLA_CXX_COMPILER_IS_GNU) || (defined WALBERLA_CXX_COMPILER_IS_CLANG)
2830
#pragma GCC diagnostic push
2931
#pragma GCC diagnostic ignored "-Wfloat-equal"
@@ -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
6769
} // namespace internal_1ccccad4ca561e07a0934cadb07d0fc1
6870

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

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

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

124128
auto field = block->getData<field::GhostLayerField<float, 3>>(fieldID);

src/walberla_bridge/src/lattice_boltzmann/generated_kernels/PackInfoVecSinglePrecision.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class PackInfoVecSinglePrecision
5454
void unpackData(IBlock *receiver, stencil::Direction dir,
5555
mpi::RecvBuffer &buffer) {
5656
const auto dataSize = size(dir, receiver);
57-
unpack(dir, buffer.skip(dataSize), receiver);
57+
unpack(dir, buffer.skip(dataSize + sizeof(float)), receiver);
5858
}
5959

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

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

0 commit comments

Comments
 (0)