Skip to content

Conversation

@zhao-shihan
Copy link
Contributor

@zhao-shihan zhao-shihan commented Jun 17, 2025

I find that allgathering std::array<char, N> (N>=229) will trigger a compile warning with GCC 14.2/13.3/12.4 (but ok for Clang). Here is an example:

#include <mpl/mpl.hpp>

int main() {
  constexpr std::size_t n{229}; // n >= 229 will trigger gcc 14.2 -Wmaybe-uninitialized

  const auto& commWorld{mpl::environment::comm_world()};
  std::array<char, n> a{};
  std::vector<std::array<char, n>> b(commWorld.size());
  commWorld.allgather(a, b.data());

  return EXIT_SUCCESS;
}

And the warning looks like this:

In file included from /home/zhaoshihan/Documents/repos/mpl/mpl/mpl.hpp:51,
                 from /home/zhaoshihan/Documents/repos/mpl/examples/arrays.cc:4:
In member function ‘mpl::struct_layout<S>& mpl::struct_layout<S>::register_struct(const S&) [with S = std::array<char, 256>]’,
    inlined from ‘mpl::struct_builder<std::array<_Tp, _Nm> >::struct_builder() [with T = char; long unsigned int N = 256]’ at /home/zhaoshihan/Documents/repos/mpl/mpl/datatype.hpp:402:30:
/home/zhaoshihan/Documents/repos/mpl/mpl/datatype.hpp:135:22: warning: ‘array’ may be used uninitialized [-Wmaybe-uninitialized]
  135 |       MPI_Get_address(const_cast<S *>(&x), &base_);
      |       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/zhaoshihan/Documents/repos/mpl/mpl/mpl.hpp:5:
/usr/lib/x86_64-linux-gnu/openmpi/include/mpi.h: In constructor ‘mpl::struct_builder<std::array<_Tp, _Nm> >::struct_builder() [with T = char; long unsigned int N = 256]’:
/usr/lib/x86_64-linux-gnu/openmpi/include/mpi.h:1677:20: note: by argument 1 of type ‘const void*’ to ‘int MPI_Get_address(const void*, MPI_Aint*)’ declared here
 1677 | OMPI_DECLSPEC  int MPI_Get_address(const void *location, MPI_Aint *address);
      |                    ^~~~~~~~~~~~~~~
/home/zhaoshihan/Documents/repos/mpl/mpl/datatype.hpp:401:24: note: ‘array’ declared here
  401 |       std::array<T, N> array;
      |                        ^~~~~

The interesting thing is if N<229 the warning is gone.

Nevertheless, I believe we can simply add a value initialization to make GCC happy since this array is just a template here.

@zhao-shihan
Copy link
Contributor Author

I also noticed a unused displs local variables and I removed them.

@rabauke rabauke self-assigned this Oct 17, 2025
@rabauke rabauke merged commit 5450128 into rabauke:master Oct 17, 2025
3 checks passed
@rabauke
Copy link
Owner

rabauke commented Oct 17, 2025

Thanks, looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants