I have to use MPI API for send/receive matrices in my programs. To send a matrix I used the below syntax:
MPI_Send(matrix, ...) <- USE THIS
MPI_Send(&matrix, ...)
MPI_Send(&matrix[0][0], ...)
Similar to the last one, but untested: MPI_Send(&matrix[0],....
I saw in different examples the use of the above and I wonder if there is a difference between them or is any one going to cause errors on big data? I'm asking because I've heard a person who knows a little bit of HPC talking about using only the first syntax (enumerated above) but I didn't have time to ask him why and I cannot find the reason on the Internet, or I don't know where to look. All of the above works just find on little examples that I compiled but I have only 2 cores on my processor so I may not be able to see the problem.
I my understanding those examples point to the same memory address so what will be the problem ? Is there a MPI API related issue?
Thanks in advance
All the matrix references in your question point to the same address, albeit with different types. MPI_Send
takes a void*
, so it looses the type anyway. So all calls are practically equivalent.
If the type of matrix is changed from a 2D array to a pointer, then the above are no longer equivalent. E.g., if matrix is an int*
, only the first and last option both compile and produce the required address. Therefore, I too would recommend using the first option - it's safer should the type of matrix changes.