Ich habe 4 Dateipfade in der global_filetable und ich versuche zu jedem Prozess 2 Pfaden zu streuen.MPI - streuen Dateipfade zu Prozessen
Der Prozess 0 richtige 2 Wege, aber es ist etwas seltsam in dem Prozess 1 (null) ...
EDIT: Hier ist der vollständige Code:
#include <stdio.h>
#include <limits.h> // PATH_MAX
#include <mpi.h>
int main(int argc, char *argv[])
{
char** global_filetable = (char**)malloc(4 * PATH_MAX * sizeof(char));
for(int i = 0; i < 4; ++i) {
global_filetable[i] = (char*)malloc(PATH_MAX *sizeof(char));
strncpy (filetable[i], "/path/", PATH_MAX);
}
/*for(int i = 0; i < 4; ++i) {
printf("%s\n", global_filetable[i]);
}*/
int rank, size;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
char** local_filetable = (char**)malloc(2 * PATH_MAX * sizeof(char));
MPI_Scatter(global_filetable, 2*PATH_MAX, MPI_CHAR, local_filetable, 2*PATH_MAX , MPI_CHAR, 0, MPI_COMM_WORLD);
{
/* now all processors print their local data: */
for (int p = 0; p < size; ++p) {
if (rank == p) {
printf("Local process on rank %d is:\n", rank);
for (int i = 0; i < 2; i++) {
printf("path: %s\n", local_filetable[i]);
}
}
MPI_Barrier(MPI_COMM_WORLD);
}
}
MPI_Finalize();
return 0;
}
Ausgang:
Local process on rank 0 is:
path: /path/
path: /path/
Local process on rank 1 is:
path: (null)
path: (null)
Haben Sie eine Idee, warum ich diese Nullen habe?
Das hat nichts mit * blöd * zu tun, aber alles mit verständigen Zeigern, Zeigern auf Zeigern, dynamischer Speicherzuordnung und statischen 2D-Arrays. Verstehst du jetzt, warum es vorher nicht funktioniert hat und jetzt funktioniert? – Zulan