next up previous
Next: Heterogeneous computing with MPI Up: Scattering particles Previous: Creating the datatype

Skeleton code for scattering


Skeleton Code

struct Pstruct {double x[3]; double v[3]; int k;}
          bigbuf[1000], particle[100];
int ierr, nprocs, root=0, p, sum, npart;
int displ[10], n[10];
MPI_Comm comm;
MPI_Data_type Ptype;

CREATE PARTICLE DATATYPE

ierr = MPI_Comm_size (comm, &nprocs);
sum = 0;
for (p=0; p<nprocs; p++){
   displ[p] = sum;
   sum += n[p];}

ierr = MPI_Scatter (n, 1, MPI_Int, &npart,
                    1, MPI_Int, root, comm);
ierr = MPI_Scatterv (bigbuf, n, displ, Ptype,
                     particle, npart, Ptype, 
                     root, comm)



David W Walker
Mon Jan 20 11:10:22 GMT 1997