MPI e alocação de array multidimensional em C

Eu estou tentando usar MPI_Scatter, enviando linhas de matriz (que são alocadas dinamicamente), mas enviando apenas uma linha, em outros são lixo. Quando eu uso alocação de memória estática - tudo é bom.

MPI_Init(&argc, &argv);
int **matrix, *matrix_stor, *row,rank, P;
MPI_Comm_size(MPI_COMM_WORLD, &P);
row = new int [P];
for(int i = 0; i < P; i++)
{
    row[i] = 0;
}
matrix = new int *[P];
for(int i = 0; i < P; i ++)
    matrix[i] = new int [P];

//int matrix[4][4], row[4], rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

if (rank == 0){
    for(int i = 0; i < P; i++){
        for(int j = 0; j < P; j++){
            matrix[i][j] = rand()%20;
            cout << matrix[i][j] << " ";
        }
        cout << endl;
    }
}
cout << endl;

MPI_Scatter(&matrix[0][0], P, MPI_INT,&row[0], P, MPI_INT,0,MPI_COMM_WORLD);
for(int i = 0; i < P; i++)
    cout << row[i] << " ";
cout << endl;
free(matrix);
free(row);
MPI_Finalize();
return 0;

E o resultado é:
Matriz de origem:
1 7 14 0
9 4 18 18
2 4 5 5
1 7 1 11
Linhas recebidas:
1 7 14 0
3626672 3626800 0 0
16 1 119 -33686019
-33686019 -572662307 524296 786765

questionAnswers(1)

yourAnswerToTheQuestion