I am dealing with parallelizing Conways' Game of Life using MPI (in c++). I have to read a (very large) matrix from input, then scatter it in slices row-wise, and then process every slice in parallel. The idea I am following is to let only one process deal with the I/O stuff. In particular, process 0 read from file and saves the initial datas into a say RxC matrix, to be scattered among the process in (R/P)xC "slice matrices". Now, when I perform the routine MPI_Scatter, the compiler complaints because the "big matrix" is allocated only in the first process. To make things work I have to allocate the big matrix in all the process, even if those remains blank. Is this ordinary, or I am doing something wrong? Is there a way to avoid allocating a blank, useless matrix for every process? Thank you guys!
You don't need to allocate the "big matrix" everywhere, but MPI_SCATTER does require that you allocate some memory on all of the ranks.
If you are going to scatter your data like this:
Before scatter:
rank 0 - 1 2 3 4
After scatter:
rank 0 - 1
rank 1 - 2
rank 2 - 3
rank 3 - 4
You need to allocate space for one int on each rank (as opposed to all 4).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With