Tech Programing


Is there a way to have a stdarray the same size as MPI_Comm_size?

1 min read

I have a program where I am trying to gather up a set of data into an std::array however I cannot get this to work when the size of my array is set to the value of the world size. I get the following error:

MPITests.cpp:16:21: error: the value of ‘size’ is not usable in a constant expression
   16 |     std::array<int, size> gatheredRanks2;
      |                     ^~~~

here is a section of the relevant code:

int rank, size;

MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

std::array<int, size> gatheredRanks2;

If I simply set the value of this size to a number the program works.
Is there a workaround for this?

Source link



發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *