I am implementing matrix multiplication using MPI_Scatter and MPI_Gather. My code works fine if the number of processes divides evenly into the number of matrix rows,columns. However, it crashes on MPI_Gather when they do not divide evenly. This makes sense because MPI_Gather is expecting a certain amount from each process and will not receive that much from the last process. Is there a way to make this work? I looked into MPI_Gatherv, but I don't want spaces between the data - I just want it to receive less than the amount for the last process.
Currently, I am using MPI_Scatter to send each process the amount of:
ceil(N/size)
where size is the number of processes I am using and N is the number of rows and columns in the matrices. The last process will not receive as much data as the others. I am making sure to stop doing the multiplication when I reach the end of the data in the last process. I could change this scatter+multiplication part if there is no way to change my MPI_Gather call. Any help is appreciated.