]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify a loop a bit.
authorWolfgang Bangerth <bangerth@colostate.edu>
Sun, 9 Jan 2022 18:08:27 +0000 (11:08 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sat, 15 Jan 2022 14:24:05 +0000 (07:24 -0700)
include/deal.II/fe/fe_tools_extrapolate.templates.h

index 2d61b259e6fc3acff6d8befa062e51935f2de2e3..d3cb9aba9d5e0fbd1123248b933fef4928341338 100644 (file)
@@ -1169,8 +1169,10 @@ namespace FETools
       std::vector<CellData> &      received_cells) const
     {
       std::vector<std::vector<char>> sendbuffers(cells_to_send.size());
-      std::vector<MPI_Request>       requests(cells_to_send.size());
-      std::vector<unsigned int>      destinations;
+      std::vector<MPI_Request>       requests;
+      requests.reserve(cells_to_send.size());
+
+      std::vector<unsigned int> destinations;
 
       // Protect the communication below:
       static Utilities::MPI::CollectiveMutex      mutex;
@@ -1182,24 +1184,24 @@ namespace FETools
 
       // send data
       std::vector<std::vector<char>>::iterator buffer = sendbuffers.begin();
-      unsigned int                             idx    = 0;
-      for (typename std::vector<CellData>::const_iterator it =
-             cells_to_send.begin();
-           it != cells_to_send.end();
-           ++it, ++idx)
+      for (const auto &cell_to_send : cells_to_send)
         {
-          destinations.push_back(it->receiver);
+          destinations.push_back(cell_to_send.receiver);
+
+          *buffer = cell_to_send.pack_data();
 
-          *buffer        = it->pack_data();
-          const int ierr = MPI_Isend(buffer->data(),
+          MPI_Request request;
+          const int   ierr = MPI_Isend(buffer->data(),
                                      buffer->size(),
                                      MPI_BYTE,
-                                     it->receiver,
+                                     cell_to_send.receiver,
                                      mpi_tag,
                                      communicator,
-                                     &requests[idx]);
+                                     &request);
           AssertThrowMPI(ierr);
 
+          requests.emplace_back(request);
+
           ++buffer;
         }
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.