Julien Dehos il y a 7 ans
Parent
commit
61b2ece1e7
2 fichiers modifiés avec 25 ajouts et 20 suppressions
  1. 13 11
      laplacien_mpi_1.cpp
  2. 12 9
      laplacien_mpi_2.cpp

+ 13 - 11
laplacien_mpi_1.cpp

@@ -9,15 +9,16 @@ int main(int argc, char ** argv)
 {
     // init MPI
     MPI_Init(&argc, &argv);
-    int nbNodes;
-    MPI_Comm_size(MPI_COMM_WORLD, &nbNodes);
-    int iNode;
-    MPI_Comm_rank(MPI_COMM_WORLD, &iNode);
+    int worldSize;
+    MPI_Comm_size(MPI_COMM_WORLD, &worldSize);
+    int worldRank;
+    MPI_Comm_rank(MPI_COMM_WORLD, &worldRank);
+    double t0 = MPI_Wtime();
 
     // read image (master node)
     image_t data0;
     int width, height;
-    if (iNode == 0)  
+    if (worldRank == 0)  
     {
         std::string readError = readPgm("backloop.pgm", width, height, data0);
         if (readError != "")
@@ -31,14 +32,14 @@ int main(int argc, char ** argv)
     MPI_Bcast(&width, 1, MPI_INT, 0, MPI_COMM_WORLD);
     MPI_Bcast(&height, 1, MPI_INT, 0, MPI_COMM_WORLD);
 
-    int heightN = (height+nbNodes-1) / nbNodes;
+    int heightN = (height+worldSize-1) / worldSize;
     int sizeN = heightN * width;
-    int height2 = heightN * nbNodes;
+    int height2 = heightN * worldSize;
     int size2 = height2 * width;
 
-    // ensure height of data is a multiple of nbNodes (master node)
+    // ensure height of data is a multiple of worldSize (master node)
     image_t data1(size2);
-    if (iNode == 0)
+    if (worldRank == 0)
     {
         std::copy_n(data0.begin(), width*height, data1.begin());
     }
@@ -59,10 +60,11 @@ int main(int argc, char ** argv)
             0, MPI_COMM_WORLD);
 
     // write output image (master node)
-    if (iNode == 0)
+    if (worldRank == 0)
     {
         writePgm("output_1.pgm", width, height, data2);
-        std::cout << "walltime = " << MPI_Wtime() << std::endl;
+        double t1 = MPI_Wtime();
+        std::cout << "walltime = " << t1 - t0 << std::endl;
     }
 
     MPI_Finalize();

+ 12 - 9
laplacien_mpi_2.cpp

@@ -9,13 +9,15 @@ int main(int argc, char ** argv)
 {
     // init MPI
     MPI_Init(&argc, &argv);
-    int nbNodes;
-    MPI_Comm_size(MPI_COMM_WORLD, &nbNodes);
-    int iNode;
-    MPI_Comm_rank(MPI_COMM_WORLD, &iNode);
+    int worldSize;
+    MPI_Comm_size(MPI_COMM_WORLD, &worldSize);
+    int worldRank;
+    MPI_Comm_rank(MPI_COMM_WORLD, &worldRank);
 
-    if (iNode == 0)  // master node
+    if (worldRank == 0)  // master node
     {
+        double t0 = MPI_Wtime();
+
         // read image
         image_t data0;
         int width, height;
@@ -25,13 +27,13 @@ int main(int argc, char ** argv)
             std::cout << readError << std::endl;
             exit(-1);
         }
-        int heightN = (height+nbNodes-1) / nbNodes;
+        int heightN = (height+worldSize-1) / worldSize;
         int sizeN = heightN * width;
-        int height2 = heightN * nbNodes;
+        int height2 = heightN * worldSize;
         int size2 = height2 * width;
 
         // copy data0 in data1 
-        // ensure the height of data1 is a multiple of nbNodes
+        // ensure the height of data1 is a multiple of worldSiz
         image_t data1(size2);
         std::copy_n(data0.begin(), width*height, data1.begin());
 
@@ -56,7 +58,8 @@ int main(int argc, char ** argv)
 
         // write output image
         writePgm("output_2.pgm", width, height, data2);
-        std::cout << "walltime = " << MPI_Wtime() << std::endl;
+        double t1 = MPI_Wtime();
+        std::cout << "walltime = " << t1 - t0 << std::endl;
     }
     else  // slave nodes
     {