tags:

views:

119

answers:

3

Hello Everybody,

I got stuck in a programming task. I want the elements of my stl vector to be placed in a

contiguous memory to send it with MPI_Send() routine.

here is an example:

class Tem
{

//...
private: 
 vector<double> lenghtVector (4500);//this gives a compilation error but I need to have a fixed sized vector

};

how can I have a vector with a serial memory of should I do something else?

Thanks. Kindest Regards.

SRec

+2  A: 

The elements of a vector are stored contiguously according to C++ Standard (23.2.4/1). To resize it you could use appropriate constructor in the initializer list of Tem class.:

class Tem
{
  Tem() : lenghtVector(4500) {};
private: 
 vector<double> lenghtVector;
};
Kirill V. Lyadvinsky
Well thank you Krill,Can I state the following ? Providing I do not exceed the initial length of the vector I can guarantee that the elements are held in contiguous. is it true?Regards
SRec0
Elements of a vector are stored contiguously all the time. Using `resize` or any other functions of `std::vector` will not change this rule.
Kirill V. Lyadvinsky
A: 

nevermind (question was changed while answering)

eddie
+1  A: 

vector will do what you want, as the data is guaranteed to be contiguous. Use &(v[0]) to get a pointer that you can pass to MPI_Send().

If you don't need the dynamic sizing of vector, you might want to look at the Boost Array class. The size is fixed at compile time, but it is an STL compatible container, so you get begin(), end(), size(), etc.

KeithB