Browse Source

poprawka MPI_Gather -> MPI_Gatherv

master
Piotr Dergun 7 years ago
parent
commit
996dda2e7f
1 changed files with 22 additions and 3 deletions
  1. +22
    -3
      DergunPiotr-WaskoDominik/zad5/gauss_mpi.cpp

+ 22
- 3
DergunPiotr-WaskoDominik/zad5/gauss_mpi.cpp View File

@ -67,7 +67,23 @@ int main(int argc, char *argv[])
buff_max = porcja; // na wypadek, jeżeli jednak ostatni kawałek będzie mniejszy
if (taskid == 0)
img_out.create(/*buff_max*ntasks*/img.rows, img.cols, img.type());
img_out.create(img.rows, img.cols, img.type());
int *chunk_sizes = new int[ntasks];
int *chunk_order = new int[ntasks];
for (i=0; i<ntasks; ++i)
{
//if (i == 0)
chunk_order[i] = (i == 0) ? 0 : chunk_order[i-1] + chunk_sizes[i-1];
chunk_sizes[i] = porcja*img.cols*3;
if (i == ntasks-1)
chunk_sizes[i] = (img.rows - porcja*(ntasks-1))*img.cols*3;
//if (taskid == 0)
// cout << chunk_sizes[i] << endl;
}
MPI::COMM_WORLD.Barrier();
@ -134,14 +150,17 @@ int main(int argc, char *argv[])
}
MPI::COMM_WORLD.Barrier();
if (taskid == 0)
if (taskid == 0 && false)
{
long elapsed = tt.End();
cout << "Time: " << elapsed << " ms" << endl;
}
// zwróć wszystko do programu głównego
MPI::COMM_WORLD.Gather(&img_part_out.data[0], porcja*img.cols*3, MPI::CHAR, &img_out.data[0], porcja*img.cols*3, MPI::CHAR, 0);
cout << porcja << endl;
//MPI::COMM_WORLD.Gather(&img_part_out.data[0], buff_max*img.cols*3, MPI::CHAR, &img_out.data[0], buff_max*img.cols*3, MPI::CHAR, 0);
MPI::COMM_WORLD.Gatherv(&img_part_out.data[0], porcja*img.cols*3, MPI::CHAR, &img_out.data[0], chunk_sizes, chunk_order, MPI::CHAR, 0);
//cout << taskid << endl;
if (taskid == 0)
imwrite(argv[2], img_out);
MPI::Finalize();

Loading…
Cancel
Save