1

i'm trying to send an array of strings to the slaves process in MPI, but i can't figure out how to do it. I have a big array of strings, which i've read from a file, and i need to send parts of this array to the slaves. I'm allocating a new array with some elements from the main one and trying to send this. Here's the send part of the code:

int w = 0;
int division = size / (procs -1);
for(i=1; i<procs; i++){
    //allocating
    char **array1 = (char**) malloc(sizeof(*array1) * division);
    array1[0] = (char*) malloc(sizeof(*array1[0]) * division * buf);
    for(j=1; j<division; j++)
        array1[i] = &(array1[0][i*buf]);

    // filling it up
    for(j=0; j<division; j++)
        array1[j] = array[w++];

    // sending
    MPI_Send(&array1, division[i], MPI_CHAR, i, tag, MPI_COMM_WORLD);

    // clearing memory
    free(array1);
}
printf("%d: All Sent\n", rank);

If i change the send method to something like this

MPI_SEND(&array[0][0] ...)

it works, but i need to send more than one string per process.

bfagundes
  • 95
  • 2
  • 4
  • 16

2 Answers2

1

I am working on a MPI project too, since no one answers this question, I will give my best shot. I think in your implementation, you pass a list of pointers, each pointer pointing a list of char, thus MPI_send essentially sends out a list of addresses of arrays. As a result the data_type "char" won't match or it may only find the first char in each array.

Chong Yue
  • 145
  • 1
  • 3
  • 9
-1

Sequential malloc do not guarantee continuity in memory as far as my experience is concerned.

Your 2D array is not contiguous in memory, and MPI cannot transfer it in the "standard" way.

For clarification on the problem, you may look here:

Sending and receiving 2D array over MPI

sending blocks of 2D array in C using MPI

marco
  • 11
  • 4