I am sending a 2D array over MPI and for this to work correctly the array needs to be contiguously allocated in memory.
I am allocating it as follows:
int **array;
array = malloc(size1 * sizeof( *(array) );
for (int k = 0; k < size1; k++)
array[k] = malloc(size2 * sizeof(**(array));
Then I would like to use:
MPI_Send(array, size1*size2, MPI_INT, target_pe, tag, MPI_COMM_WORLD);
How can I ensure the array is allocated contiguously?
Currently I am trying this:
for (int k = 0; k < size1; k++)
MPI_Send(array[k], size2, MPI_INT, target_pe, tag, MPI_COMM_WORLD);
which leads to a seg fault later in an unrelated part of the program. However if I send the elements 1 by 1 it works.