|
@@ -1,5 +1,6 @@
|
|
// mpic++ -std=c++11 -Wall -Wextra -o laplacien_mpi_2.out laplacien_mpi_2.cpp
|
|
// mpic++ -std=c++11 -Wall -Wextra -o laplacien_mpi_2.out laplacien_mpi_2.cpp
|
|
-// mpirun -n 4 ./laplacien_mpi_2.out
|
|
|
|
|
|
+// mpirun -n 4 ./laplacien_mpi_2.out canyon.pgm canyon_mpi_2.pgm
|
|
|
|
+// separate master code and slave code
|
|
|
|
|
|
#include "image.hpp"
|
|
#include "image.hpp"
|
|
#include <algorithm>
|
|
#include <algorithm>
|
|
@@ -14,6 +15,17 @@ int main(int argc, char ** argv)
|
|
int worldRank;
|
|
int worldRank;
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &worldRank);
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &worldRank);
|
|
|
|
|
|
|
|
+ if (argc != 5)
|
|
|
|
+ {
|
|
|
|
+ std::cout << "usage: " << argv[0]
|
|
|
|
+ << " <input> <output> <scaling> <nb fakes>\n";
|
|
|
|
+ exit(-1);
|
|
|
|
+ }
|
|
|
|
+ const char * INPUT = argv[1];
|
|
|
|
+ const char * OUTPUT = argv[2];
|
|
|
|
+ const float SCALING = atof(argv[3]);
|
|
|
|
+ const int NB_FAKES = atoi(argv[4]);
|
|
|
|
+
|
|
if (worldRank == 0) // master node
|
|
if (worldRank == 0) // master node
|
|
{
|
|
{
|
|
double t0 = MPI_Wtime();
|
|
double t0 = MPI_Wtime();
|
|
@@ -21,7 +33,7 @@ int main(int argc, char ** argv)
|
|
// read image
|
|
// read image
|
|
image_t data0;
|
|
image_t data0;
|
|
int width, height;
|
|
int width, height;
|
|
- std::string readError = readPgm("backloop.pgm", width, height, data0);
|
|
|
|
|
|
+ std::string readError = readPgm(INPUT, width, height, data0);
|
|
if (readError != "")
|
|
if (readError != "")
|
|
{
|
|
{
|
|
std::cout << readError << std::endl;
|
|
std::cout << readError << std::endl;
|
|
@@ -48,7 +60,9 @@ int main(int argc, char ** argv)
|
|
0, MPI_COMM_WORLD);
|
|
0, MPI_COMM_WORLD);
|
|
|
|
|
|
// compute master data
|
|
// compute master data
|
|
- image_t nodeResult = computeLaplacian(nodeData, width, heightN, 10.0);
|
|
|
|
|
|
+ image_t nodeResult = computeLaplacian(nodeData, width, heightN, SCALING);
|
|
|
|
+ for (int k=0; k<NB_FAKES; ++k)
|
|
|
|
+ nodeResult = computeLaplacian(nodeData, width, heightN, SCALING);
|
|
|
|
|
|
// receive results from slave nodes
|
|
// receive results from slave nodes
|
|
image_t data2(size2, 0);
|
|
image_t data2(size2, 0);
|
|
@@ -57,9 +71,9 @@ int main(int argc, char ** argv)
|
|
0, MPI_COMM_WORLD);
|
|
0, MPI_COMM_WORLD);
|
|
|
|
|
|
// write output image
|
|
// write output image
|
|
- writePgm("output_2.pgm", width, height, data2);
|
|
|
|
|
|
+ writePgm(OUTPUT, width, height, data2);
|
|
double t1 = MPI_Wtime();
|
|
double t1 = MPI_Wtime();
|
|
- std::cout << "walltime = " << t1 - t0 << std::endl;
|
|
|
|
|
|
+ std::cout << t1 - t0;
|
|
}
|
|
}
|
|
else // slave nodes
|
|
else // slave nodes
|
|
{
|
|
{
|
|
@@ -77,7 +91,9 @@ int main(int argc, char ** argv)
|
|
0, MPI_COMM_WORLD);
|
|
0, MPI_COMM_WORLD);
|
|
|
|
|
|
// compute node data
|
|
// compute node data
|
|
- image_t nodeResult = computeLaplacian(nodeData, width, heightN, 10.0);
|
|
|
|
|
|
+ image_t nodeResult = computeLaplacian(nodeData, width, heightN, SCALING);
|
|
|
|
+ for (int k=0; k<NB_FAKES; ++k)
|
|
|
|
+ nodeResult = computeLaplacian(nodeData, width, heightN, SCALING);
|
|
|
|
|
|
// send results to master node
|
|
// send results to master node
|
|
MPI_Gather(nodeResult.data(), sizeN, MPI_UNSIGNED_CHAR,
|
|
MPI_Gather(nodeResult.data(), sizeN, MPI_UNSIGNED_CHAR,
|