Hello everyone,
I am new to MPI in C, and i am trying to scatter the rows in a 2D array of char, do some computations and after gather the 2D array again. Let's say that i use 4 processes:
I declare the global array and the local array here:
char global[20][3];
char local[5][3];
int my_rank;
int p;
and after i initialize mpi and scatter:
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &p);
MPI_Scatter(global, 15, MPI_CHAR, local, 15, MPI_CHAR, 0, MPI_COMM_WORLD);
And that works just fine.
But what if the user gives the size of the arrays, and i malloc the arrays ?
char **global;
global = (char **)malloc(20*sizeof(char*));
for(int i=0;i<3;i++)
global = (char *)malloc(3*sizeof(char));
char **local;
local = (char **)malloc(5*sizeof(char*));
for(int i=0;i<3;i++)
local = (char *)malloc(3*sizeof(char));