MPI_Gather 2D array

N ist 4, so istN_glob. Es ist zufällig von der gleichen Größe.p ist 4.

Hier ist ein kleiner Teil des Codes:

float **global_grid;
float **gridPtr; 
lengthSubN = N/pSqrt;
subN = lengthSubN + 2;
grid = allocate2D(grid, subN, subN);
..
MPI_Type_contiguous(lengthSubN, MPI_FLOAT, &rowType);
MPI_Type_commit(&rowType);
..
gridPtr = grid;
..
MPI_Barrier(MPI_COMM_WORLD);
if(id == 0) {
    global_grid = allocate2D(global_grid, N_glob, N_glob);
}
MPI_Barrier(MPI_COMM_WORLD);
MPI_Gather(&(gridPtr[0][0]), 1, rowType,
           &(global_grid[0][0]), 1, rowType, 0, MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
if(id == 0)
    print(global_grid, N_glob, N_glob);

wo ich habep Submatrizen und ich versuche, sie alle im Root-Prozess zu sammeln, wo die globale Matrix auf sie wartet. Allerdings wird es nur einen Fehler auslösen, irgendwelche Ideen?

Ich erhalte einen Seg-Fehler:

SCHLECHTE BEENDIGUNG EINES IHRES ANWENDUNGSPROZESSES PID 29058 LÄUFT UNTER LINUX16 EXIT-CODE: 139 IHRE ANWENDUNG MIT DEM EXIT-STRING BEENDET: Segmentierungsfehler (Signal 11)

BEARBEITEN

Ich habe diese Frage gefundenMPI_Gather segmentation fault und ich initialisierteglobal_grid zu NULL, aber kein Glück. Wenn ich es jedoch tue:

//if(id == 0) {
    global_grid = allocate2D(global_grid, N_glob, N_glob);
//}

then alles funktioniert. Aber sollte die globale Matrix nicht nur im Root-Prozess leben?

EDIT_2:

Wenn ich mache

if(id == 0) {
    global_grid = allocate2D(global_grid, N_glob, N_glob);
} else {
    global_grid = NULL;
}

then es wird hier abstürzen:

MPI_Gather(&gridPtr[0][0], 1, rowType,
                global_grid[0], 1, rowType, 0, MPI_COMM_WORLD);

Antworten auf die Frage(2)

Ihre Antwort auf die Frage