I've read about mpi and I'm interested in using the function MPI_Gather.
Now I'm doing this, but it's not working:
#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();
}
Instead of printing "aaaaabbbbbccccc" it's printing only "aaaaa".
What am I doing wrong?