I know that in C arithmetic of void pointers is not allowed. However I must find a solution to deal with this issue.
I have a function that sends the first half of an array to rank 0 and the second half to rank 1:
void send_expand_multiple(void * data, MPI_Datatype datatype, int size) {
int my_rank, comm_size, intercomm_size, localSize, factor, dst, iniPart, iniPartBytes, i;
int datatype_size;
MPI_Type_size(datatype, &datatype_size);
int local_size = size / 2;
//Sending the first half
MPI_Send(data, local_size, datatype, dst, 0, comm);
//Sending the second half
int iniPart = local_size;
int iniPartBytes = iniPart * datatype_size;
MPI_Send(((char *) data) + iniPartBytes, local_size, datatype, dst, 1, comm);
}
My solution is based on the principle of "serializing". For the first half, there is no problem, but for the second I have parsed the buffer and moved the pointer iniPartBytes by adding that value.
Finally, the count and the datatype configure the MPI_Send in order to send local_size elements of datatype type.
Is my approach correct?
int local_size = size / 2;
can loose 1 byte in case of odd value – LPs