From 11f53f27049e24d4bbc0fea604754e6756affb1e Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 2 May 2024 23:20:47 +0200 Subject: [PATCH] Some cleanup and checks --- libsrc/core/ng_mpi.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libsrc/core/ng_mpi.cpp b/libsrc/core/ng_mpi.cpp index 5646347b..590961ec 100644 --- a/libsrc/core/ng_mpi.cpp +++ b/libsrc/core/ng_mpi.cpp @@ -16,6 +16,9 @@ namespace ngcore { // return static_cast(t); // } +static_assert(sizeof(MPI_Status) <= sizeof(NG_MPI_Status), "Size mismatch"); +static_assert(alignof(MPI_Status) <= alignof(NG_MPI_Status), "Size mismatch"); + int mpi2ng(int v) { return v; } void* mpi2ng(void*p) { return p; } @@ -42,11 +45,13 @@ T cast_ng2mpi(uintptr_t* t) { MPI_Comm ng2mpi(NG_MPI_Comm c) { static_assert(sizeof(MPI_Comm) <= sizeof(c.value), "Size mismatch"); + static_assert(alignof(MPI_Comm) <= alignof(NG_MPI_Comm), "Size mismatch"); return cast_ng2mpi(c.value); } MPI_Group ng2mpi(NG_MPI_Group c) { static_assert(sizeof(MPI_Group) <= sizeof(c.value), "Size mismatch"); + static_assert(alignof(MPI_Group) <= alignof(NG_MPI_Group), "Size mismatch"); return cast_ng2mpi(c.value); } @@ -54,7 +59,7 @@ MPI_Comm* ng2mpi(NG_MPI_Comm* c) { return cast_ng2mpi(&c->value); } MPI_Group* ng2mpi(NG_MPI_Group* c) { return cast_ng2mpi(&c->value); } MPI_Datatype* ng2mpi(NG_MPI_Datatype* c) { return cast_ng2mpi(&c->value); } MPI_Request* ng2mpi(NG_MPI_Request* c) { return cast_ng2mpi(&c->value); } -MPI_Status* ng2mpi(NG_MPI_Status* c) { return cast_ng2mpi(&c->data[0]); } +MPI_Status* ng2mpi(NG_MPI_Status* c) { return reinterpret_cast(c); } MPI_Datatype ng2mpi(NG_MPI_Datatype c) { static_assert(sizeof(MPI_Datatype) <= sizeof(c.value), "Size mismatch"); @@ -66,10 +71,6 @@ MPI_Request ng2mpi(NG_MPI_Request c) { return cast_ng2mpi(c.value); } -MPI_Status* ng2mpi(NG_MPI_Status c) { - return cast_ng2mpi(&c.data[0]); -} - void* ng2mpi(void* c) { return c; } char* ng2mpi(char* c) { return c; } char*** ng2mpi(char*** c) { return c; }