Nico
2010-01-08 09:14:12 UTC
Hi,
I have an array of the following C structure :
typedef struct
{
int nb;
int nb2[100];
float nb3[340];
float fnb[2][2];
} MyType;
I would like to reduce to all processors some of the members of that
structure, namely 'nb' and 'fnb'.
is the following ok :
// first member to reduce
offsets[0] = 0;
MyTypeMembTypes[0] = MPI_INT;
blockcounts[0] = 1;
// second member to reduce
MPI_Type_extent(MPI_INT, &extent);
offsets[1] = 101 * extent;
MPI_Type_extent(MPI_FLOAT, &extent);
offsets[1] += 340 * extent;
MyTypeMembTypes[1] = MPI_FLOAT;
blockcounts[1] = 2*2;
MPI_Type_struct(2, blockcounts, offsets, MyTypeMembTypes, &MyTypeMPI);
MPI_Type_commit(&MyTypeMPI);
MPI_Op_create((MPI_User_function *)MyTypeSum, 1, &MyOp);
MPI_Allreduce(MPI_IN_PLACE, MyTypeObj, NELEM, MyTypeMPI, MyOp,
MPI_COMM_WORLD);
Thanks
Nico
I have an array of the following C structure :
typedef struct
{
int nb;
int nb2[100];
float nb3[340];
float fnb[2][2];
} MyType;
I would like to reduce to all processors some of the members of that
structure, namely 'nb' and 'fnb'.
is the following ok :
// first member to reduce
offsets[0] = 0;
MyTypeMembTypes[0] = MPI_INT;
blockcounts[0] = 1;
// second member to reduce
MPI_Type_extent(MPI_INT, &extent);
offsets[1] = 101 * extent;
MPI_Type_extent(MPI_FLOAT, &extent);
offsets[1] += 340 * extent;
MyTypeMembTypes[1] = MPI_FLOAT;
blockcounts[1] = 2*2;
MPI_Type_struct(2, blockcounts, offsets, MyTypeMembTypes, &MyTypeMPI);
MPI_Type_commit(&MyTypeMPI);
MPI_Op_create((MPI_User_function *)MyTypeSum, 1, &MyOp);
MPI_Allreduce(MPI_IN_PLACE, MyTypeObj, NELEM, MyTypeMPI, MyOp,
MPI_COMM_WORLD);
Thanks
Nico