Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MPI_Allreduce on structure of doubles. Portable?

29 views
Skip to first unread message

jaco...@gmail.com

unread,
Feb 5, 2013, 11:30:41 AM2/5/13
to
Hello,


Consider something like this:

---

typedef struct TS {
double a,b,c;
} S;

...
S x,y;
...
MPI_Allreduce(&x, &y, 3, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);

---

Is the above code completely portable (without using MPI_Type_struct and all)?

Thanks!
JS

Georg Bisseling

unread,
Jul 7, 2013, 5:03:49 AM7/7/13
to
Since I am 5 months late with the answer this is just for the records, I'm
afraid.

Since any ANSI C compiler must be able to pack doubles tight in arrays it
will pack doubles tight in structs too. And of course we expect the
struct's address to be the same as the first field's. If these assumptions
are not met, then we are not talking about an implementation of ANSI C as
I understood it.

So under all forseeable and sane conditions the code is portable. If not,
then it is a fault in the target of the port. ;-)

BUT: you may start all the hassle of defining your MPI datatypes just to
free your mind when laying out your data structures.

Another way to think about it: when you need binary serialization for you
data structures to store them in files you may consider abusing this
serialization for messages.

ciao
Georg
0 new messages