Possible Duplicate:
Are std::vector elements guaranteed to be contiguous?
I have come across a technique in which people use a vector in C++ to receive or send data for MPI operations as it is said to store elements contiguously in memory.
However, I remain skeptical of whether this approach would remain robust for a vector of any size, especially when the vector grows to a certain size, where this assumption could break down.
Below is an example of what I am talking about :
MPI_Recv( &partials[0] , partials.size() , mpi_partial , 0,
DALG_ELIMINATE_REQ_MSG ,MPI_COMM_WORLD , &status );
vector
doesn't "randomly spill elements", but the whole thing is relocated if necessary. So whether this usage is safe depends on what you mean by "grows" - if you mean that in future your program will use bigger sizes than it does today, fine. If you mean that you're callingresize
on it while MPI is holding the pointer, not fine. – Maxine