我讀過關於mpi,我有興趣使用函數MPI_Gather。如何正確使用MPI_Gather?
現在我這樣做,但它不工作:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpi.h>
char *funcion (char *a) {
sprintf(a, "asdfa%u", 2);
}
int main (int argc, char *argv[]) {
MPI_Init(&argc, &argv);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
char *parcial = malloc(5*sizeof(char));
char *total;
if (rank == 0) {
total = malloc(15*sizeof(char));
parcial = "aaaaa";
}
else if (rank == 1) {
parcial = "bbbbb";
}
else if (rank == 2) {
parcial = "ccccc";
}
MPI_Gather(parcial,5,MPI_CHAR,total,15,MPI_CHAR,0,MPI_COMM_WORLD);
if (rank == 0) {
printf("%s",total);
}
MPI_Finalize();
}
除了打印「aaaaabbbbbccccc」的它僅打印「AAAAA」。
我在做什麼錯?
我忘了評論,我與選項-NP 3 – Sergio
執行它。如果你想添加一些問題,只需使用'edit'底部按鈕問題的左邊。 – Zulan