I am under the impression that one of the (perhaps implicit) requirements of
the C++ STL is that std::vectors are stored in contiguous memory. So the
below code should work with all conformant C++ compilers.
Vince Virgilio
> -----Original Message-----
> From: Vishal Sahay [mailto:vsahay_at_[hidden]]
> Sent: Tuesday, April 22, 2003 9:17 PM
> To: sbcair; General LAM/MPI mailing list
> Subject: Re: LAM: MPI datatypes
>
>
> It is possible to send STL vector<double> in the manner shown
> in the second code.
>
> The traditional C way of doing it would be:
>
> void
> foo(int array_len)
> {
> double *a;
> a = malloc(sizeof(double) * array_len);
>
> /* do some work on a */
>
> MPI_Send(a, array_len, MPI_DOUBLE, dest, tag, comm);
> }
>
> Using STL vectors, the code would be:
>
> void
> foo(int array_len)
> {
> vector<double> a;
>
> /* do some work on a */
>
> MPI_Send(&a[0], array_len, MPI_DOUBLE, dest, tag, comm);
> }
>
> This may not necessarily work with all compilers, but so far
> has worked for most of them. Note that this seems to work
> only for STL vectors and not STL lists or other STL stuffs.
>
> Infact it would work for vector<T> where T is just any common
> datatypes or a simple struct.
>
> Hope this helps...
>
> -Vishal Sahay
> ===================================================================
> (Graduate Student, CS Dept. Open Systems Lab
> Indiana University, Bloomington) Make Today A LAM/MPI Day :)
> http://cs.indiana.edu/~vsahay http://www.lam-mpi.org
> ===================================================================
************************************
If this email is not intended for you, or you are not responsible for the
delivery of this message to the addressee, please note that this message may
contain ITT Privileged/Proprietary Information. In such a case, you may not
copy or deliver this message to anyone. You should destroy this message and
kindly notify the sender by reply email. Information contained in this
message that does not relate to the business of ITT is neither endorsed by
nor attributable to ITT.
************************************
|