1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
int main(int argc, char *argv[])
{
int num_procs, myrank;
MPI_Init(&argc, &argv);
MPI_Status status;
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
if (myrank==0)
{
vector<vector<int> >
v{ { 1, 2 },
{ 3 },
{ 4, 5, 6 },
{ 7, 8, 9, 10 } };
FlattenVector iter(v);
for (int i_proc=0;i_proc<num_procs;i+proc++){
MPI_Send(iter.next, 10, MPI_INT, i_proc, 0, MPI_COMM_WORLD);
}
}
else
{
int a[10];
MPI_Recv(a.data(), 10, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
}
}
| |