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
===================================================================
On Tue, 22 Apr 2003, sbcair wrote:
# hi!
# i am a new LAM/MPI user..
# i am a student doing Comp Sc engineering..
# as a part of my project i m expected to parallelise a program...
# this prog involves the stl Vectors...i m using a vector of doubles...
# how can i convert it into an mpi datatype...
# can i perform operations on after conversion?
#
# regards,
# smriti.
#
# Get Your Private, Free E-mail from Indiatimes at http://email.indiatimes.com
#
# Buy The Best In BOOKS at http://www.bestsellers.indiatimes.com
#
# Bid for for Air Tickets @ Re.1 on Air Sahara Flights. Just log on to http://airsahara.indiatimes.com and Bid Now!
#
# _______________________________________________
# This list is archived at http://www.lam-mpi.org/MailArchives/lam/
#
|