Discussion:
MPI_Allreduce on structure of doubles. Portable?
(too old to reply)
j***@gmail.com
2013-02-05 16:30:41 UTC
Permalink
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
2013-07-07 09:03:49 UTC
Permalink
Post by j***@gmail.com
Hello,
---
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
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

Loading...