]> https://gitweb.dealii.org/ - dealii.git/commitdiff
MPI: move mpi_type_id() out of internal 13367/head
authorTimo Heister <timo.heister@gmail.com>
Sat, 12 Feb 2022 15:10:24 +0000 (10:10 -0500)
committerTimo Heister <timo.heister@gmail.com>
Sat, 12 Feb 2022 15:24:43 +0000 (10:24 -0500)
Move mpi_type_id() into Utilities::MPI because it is useful for projects
using deal.II.

Also introduce a fake template for doxygen.

12 files changed:
include/deal.II/base/mpi.h
include/deal.II/base/mpi.templates.h
include/deal.II/base/mpi_noncontiguous_partitioner.templates.h
include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h
source/base/partitioner.cc
source/base/process_grid.cc
source/distributed/repartitioning_policy_tools.cc
source/distributed/tria_base.cc
source/lac/scalapack.cc
source/matrix_free/vector_data_exchange.cc
tests/mpi/renumber_cuthill_mckee.cc
tests/mpi/renumber_cuthill_mckee_02.cc

index 6c99d8867c51f80613b3e0d8458608daf5cc5eab..bd5c60ed22d84de2a6c06204723acaad95d74722 100644 (file)
@@ -139,6 +139,22 @@ namespace Utilities
    */
   namespace MPI
   {
+#ifdef DOXYGEN
+    /**
+     * Given a pointer to an object of class T, return the matching
+     * `MPI_Datatype` to be used for MPI communication.
+     *
+     * As an example, passing an `int*` to this function returns `MPI_INT`.
+     *
+     * @note In reality, these functions are not template functions templated
+     * on the parameter T, but free standing inline function overloads. This
+     * templated version only exists so that it shows up in the documentation.
+     */
+    template <typename T>
+    MPI_Datatype
+    mpi_type_id(const T *);
+#endif
+
     /**
      * Return the number of MPI processes there exist in the given
      * @ref GlossMPICommunicator "communicator"
@@ -1279,17 +1295,154 @@ namespace Utilities
     compute_set_union(const std::set<T> &set, const MPI_Comm &comm);
 
 
+
 #ifndef DOXYGEN
-    // declaration for an internal function that lives in mpi.templates.h
+
+    /* --------------------------- inline functions ------------------------- */
+
+#  ifdef DEAL_II_WITH_MPI
+    inline MPI_Datatype
+    mpi_type_id(const bool *)
+    {
+#    if DEAL_II_MPI_VERSION_GTE(2, 2)
+      return MPI_CXX_BOOL;
+#    else
+      return MPI_C_BOOL;
+#    endif
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const char *)
+    {
+      return MPI_CHAR;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const signed char *)
+    {
+      return MPI_SIGNED_CHAR;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const short *)
+    {
+      return MPI_SHORT;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const int *)
+    {
+      return MPI_INT;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const long int *)
+    {
+      return MPI_LONG;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const unsigned char *)
+    {
+      return MPI_UNSIGNED_CHAR;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const unsigned short *)
+    {
+      return MPI_UNSIGNED_SHORT;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const unsigned int *)
+    {
+      return MPI_UNSIGNED;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const unsigned long int *)
+    {
+      return MPI_UNSIGNED_LONG;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const unsigned long long int *)
+    {
+      return MPI_UNSIGNED_LONG_LONG;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const float *)
+    {
+      return MPI_FLOAT;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const double *)
+    {
+      return MPI_DOUBLE;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const long double *)
+    {
+      return MPI_LONG_DOUBLE;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const std::complex<float> *)
+    {
+      return MPI_COMPLEX;
+    }
+
+
+
+    inline MPI_Datatype
+    mpi_type_id(const std::complex<double> *)
+    {
+      return MPI_DOUBLE_COMPLEX;
+    }
+#  endif
+
+
     namespace internal
     {
+      // declaration for an internal function that lives in mpi.templates.h
       template <typename T>
       void
       all_reduce(const MPI_Op &            mpi_op,
                  const ArrayView<const T> &values,
                  const MPI_Comm &          mpi_communicator,
                  const ArrayView<T> &      output);
-    }
+    } // namespace internal
 
 
 
index fe5d640253e3ac01519baf8794792398155cffb4..ab5b455752810b1b9573f00e25c8913c487fb56c 100644 (file)
@@ -39,142 +39,6 @@ namespace Utilities
   {
     namespace internal
     {
-#ifdef DEAL_II_WITH_MPI
-      /**
-       * Return the corresponding MPI data type id for the argument given.
-       */
-      inline MPI_Datatype
-      mpi_type_id(const bool *)
-      {
-#  if DEAL_II_MPI_VERSION_GTE(2, 2)
-        return MPI_CXX_BOOL;
-#  else
-        return MPI_C_BOOL;
-#  endif
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const char *)
-      {
-        return MPI_CHAR;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const signed char *)
-      {
-        return MPI_SIGNED_CHAR;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const short *)
-      {
-        return MPI_SHORT;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const int *)
-      {
-        return MPI_INT;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const long int *)
-      {
-        return MPI_LONG;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const unsigned char *)
-      {
-        return MPI_UNSIGNED_CHAR;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const unsigned short *)
-      {
-        return MPI_UNSIGNED_SHORT;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const unsigned int *)
-      {
-        return MPI_UNSIGNED;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const unsigned long int *)
-      {
-        return MPI_UNSIGNED_LONG;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const unsigned long long int *)
-      {
-        return MPI_UNSIGNED_LONG_LONG;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const float *)
-      {
-        return MPI_FLOAT;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const double *)
-      {
-        return MPI_DOUBLE;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const long double *)
-      {
-        return MPI_LONG_DOUBLE;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const std::complex<float> *)
-      {
-        return MPI_COMPLEX;
-      }
-
-
-
-      inline MPI_Datatype
-      mpi_type_id(const std::complex<double> *)
-      {
-        return MPI_DOUBLE_COMPLEX;
-      }
-#endif
-
-
       template <typename T>
       void
       all_reduce(const MPI_Op &            mpi_op,
@@ -221,7 +85,7 @@ namespace Utilities
                               MPI_IN_PLACE,
                             static_cast<void *>(output.data()),
                             static_cast<int>(values.size()),
-                            internal::mpi_type_id(values.data()),
+                            mpi_type_id(values.data()),
                             mpi_op,
                             mpi_communicator);
             AssertThrowMPI(ierr);
@@ -261,7 +125,7 @@ namespace Utilities
                               MPI_IN_PLACE,
                             static_cast<void *>(output.data()),
                             static_cast<int>(values.size() * 2),
-                            internal::mpi_type_id(static_cast<T *>(nullptr)),
+                            mpi_type_id(static_cast<T *>(nullptr)),
                             mpi_op,
                             mpi_communicator);
             AssertThrowMPI(ierr);
index a12f00b0fa9002acf839b57c88977e1fa6222c75..cb4b6f286c1d5f23a75e4cbb42cf4bb31631cdaf 100644 (file)
@@ -109,7 +109,7 @@ namespace Utilities
           const int ierr =
             MPI_Irecv(buffers.data() + recv_ptr[i],
                       recv_ptr[i + 1] - recv_ptr[i],
-                      Utilities::MPI::internal::mpi_type_id(buffers.data()),
+                      Utilities::MPI::mpi_type_id(buffers.data()),
                       recv_ranks[i],
                       tag,
                       communicator,
@@ -138,7 +138,7 @@ namespace Utilities
           const int ierr =
             MPI_Isend(buffers.data() + send_ptr[i],
                       send_ptr[i + 1] - send_ptr[i],
-                      Utilities::MPI::internal::mpi_type_id(buffers.data()),
+                      Utilities::MPI::mpi_type_id(buffers.data()),
                       send_ranks[i],
                       tag,
                       communicator,
index 576bced433e3ca8e50b7d4d269c412e4b112e211..38aad10c136b12f13960907bbfedf01b5b51859a 100644 (file)
@@ -572,7 +572,7 @@ namespace internal
             const auto ierr_1 = MPI_Isend(
               buffer.data(),
               buffer.size(),
-              Utilities::MPI::internal::mpi_type_id(buffer.data()),
+              Utilities::MPI::mpi_type_id(buffer.data()),
               i.first,
               Utilities::MPI::internal::Tags::fine_dof_handler_view_reinit,
               communicator,
@@ -641,8 +641,7 @@ namespace internal
             int       message_length;
             const int ierr_2 =
               MPI_Get_count(&status,
-                            Utilities::MPI::internal::mpi_type_id(
-                              buffer.data()),
+                            Utilities::MPI::mpi_type_id(buffer.data()),
                             &message_length);
             AssertThrowMPI(ierr_2);
 
@@ -651,7 +650,7 @@ namespace internal
             const int ierr_3 = MPI_Recv(
               buffer.data(),
               buffer.size(),
-              Utilities::MPI::internal::mpi_type_id(buffer.data()),
+              Utilities::MPI::mpi_type_id(buffer.data()),
               status.MPI_SOURCE,
               Utilities::MPI::internal::Tags::fine_dof_handler_view_reinit,
               communicator,
index 4d325cc9058e4bfd23d22e8b102ac01c45ef3c65..f1b87c5d7e716141c925d9cc89015bc8202d77dc 100644 (file)
@@ -76,13 +76,12 @@ namespace Utilities
       types::global_dof_index prefix_sum = 0;
 
 #ifdef DEAL_II_WITH_MPI
-      const int ierr =
-        MPI_Exscan(&local_size,
-                   &prefix_sum,
-                   1,
-                   Utilities::MPI::internal::mpi_type_id(&prefix_sum),
-                   MPI_SUM,
-                   communicator);
+      const int ierr = MPI_Exscan(&local_size,
+                                  &prefix_sum,
+                                  1,
+                                  Utilities::MPI::mpi_type_id(&prefix_sum),
+                                  MPI_SUM,
+                                  communicator);
       AssertThrowMPI(ierr);
 #endif
 
index 18b7905bbc6b48c50f7c5be8c3cf13181244c527..692c5898dddde524c9a8f1087f24e679340fb827 100644 (file)
@@ -247,12 +247,11 @@ namespace Utilities
       Assert(count > 0, ExcInternalError());
       if (mpi_communicator_inactive_with_root != MPI_COMM_NULL)
         {
-          const int ierr =
-            MPI_Bcast(value,
-                      count,
-                      Utilities::MPI::internal::mpi_type_id(value),
-                      0 /*from root*/,
-                      mpi_communicator_inactive_with_root);
+          const int ierr = MPI_Bcast(value,
+                                     count,
+                                     Utilities::MPI::mpi_type_id(value),
+                                     0 /*from root*/,
+                                     mpi_communicator_inactive_with_root);
           AssertThrowMPI(ierr);
         }
     }
index 135c8abbb6b9a320d6ae81eb2eeaed52945dda64..e4a7e0c8d46e029b53b7dc3e012cae8e7f06acec 100644 (file)
@@ -89,7 +89,7 @@ namespace RepartitioningPolicyTools
     const int ierr = MPI_Exscan(&process_has_active_locally_owned_cells,
                                 &offset,
                                 1,
-                                Utilities::MPI::internal::mpi_type_id(
+                                Utilities::MPI::mpi_type_id(
                                   &process_has_active_locally_owned_cells),
                                 MPI_SUM,
                                 comm);
@@ -308,13 +308,12 @@ namespace RepartitioningPolicyTools
     // determine partial sum of weights of this process
     uint64_t process_local_weight_offset = 0;
 
-    int ierr =
-      MPI_Exscan(&process_local_weight,
-                 &process_local_weight_offset,
-                 1,
-                 Utilities::MPI::internal::mpi_type_id(&process_local_weight),
-                 MPI_SUM,
-                 tria->get_communicator());
+    int ierr = MPI_Exscan(&process_local_weight,
+                          &process_local_weight_offset,
+                          1,
+                          Utilities::MPI::mpi_type_id(&process_local_weight),
+                          MPI_SUM,
+                          tria->get_communicator());
     AssertThrowMPI(ierr);
 
     // total weight of all processes
@@ -322,7 +321,7 @@ namespace RepartitioningPolicyTools
 
     ierr = MPI_Bcast(&total_weight,
                      1,
-                     Utilities::MPI::internal::mpi_type_id(&total_weight),
+                     Utilities::MPI::mpi_type_id(&total_weight),
                      n_subdomains - 1,
                      mpi_communicator);
     AssertThrowMPI(ierr);
index 94a82a4c88393dff78f2615cfe4f07fb238a3f87..18736bd4f28dd70bcf3e8c139035de03a4a3f2e5 100644 (file)
@@ -427,7 +427,7 @@ namespace parallel
       MPI_Exscan(&n_locally_owned_cells,
                  &cell_index,
                  1,
-                 Utilities::MPI::internal::mpi_type_id(&n_locally_owned_cells),
+                 Utilities::MPI::mpi_type_id(&n_locally_owned_cells),
                  MPI_SUM,
                  this->mpi_communicator);
     AssertThrowMPI(ierr);
@@ -493,13 +493,13 @@ namespace parallel
         std::vector<types::global_cell_index> cell_index(
           this->n_global_levels(), 0);
 
-        int ierr = MPI_Exscan(n_locally_owned_cells.data(),
-                              cell_index.data(),
-                              this->n_global_levels(),
-                              Utilities::MPI::internal::mpi_type_id(
-                                n_locally_owned_cells.data()),
-                              MPI_SUM,
-                              this->mpi_communicator);
+        int ierr =
+          MPI_Exscan(n_locally_owned_cells.data(),
+                     cell_index.data(),
+                     this->n_global_levels(),
+                     Utilities::MPI::mpi_type_id(n_locally_owned_cells.data()),
+                     MPI_SUM,
+                     this->mpi_communicator);
         AssertThrowMPI(ierr);
 
         // 3) determine global number of "active" cells on each level
@@ -509,12 +509,11 @@ namespace parallel
         for (unsigned int l = 0; l < this->n_global_levels(); ++l)
           n_cells_level[l] = n_locally_owned_cells[l] + cell_index[l];
 
-        ierr =
-          MPI_Bcast(n_cells_level.data(),
-                    this->n_global_levels(),
-                    Utilities::MPI::internal::mpi_type_id(n_cells_level.data()),
-                    this->n_subdomains - 1,
-                    this->mpi_communicator);
+        ierr = MPI_Bcast(n_cells_level.data(),
+                         this->n_global_levels(),
+                         Utilities::MPI::mpi_type_id(n_cells_level.data()),
+                         this->n_subdomains - 1,
+                         this->mpi_communicator);
         AssertThrowMPI(ierr);
 
         // 4) give global indices to locally-owned cells on level and mark
index 3ac33789b676297aa7128daf5f39bad68eac7821..84465baeb8c49da2c553050c415d8ad2174eed7c 100644 (file)
@@ -184,14 +184,14 @@ ScaLAPACKMatrix<NumberType>::ScaLAPACKMatrix(
     }
   int ierr = MPI_Bcast(&n_rows,
                        1,
-                       Utilities::MPI::internal::mpi_type_id(&n_rows),
+                       Utilities::MPI::mpi_type_id(&n_rows),
                        0 /*from root*/,
                        process_grid->mpi_communicator);
   AssertThrowMPI(ierr);
 
   ierr = MPI_Bcast(&n_columns,
                    1,
-                   Utilities::MPI::internal::mpi_type_id(&n_columns),
+                   Utilities::MPI::mpi_type_id(&n_columns),
                    0 /*from root*/,
                    process_grid->mpi_communicator);
   AssertThrowMPI(ierr);
index c8adede572d96238b270e7bb72d24b383b56ee9c..afb8ab83bb27664dfbb55d82e740f803dc362df6 100644 (file)
@@ -896,7 +896,7 @@ namespace internal
             const int ierr =
               MPI_Irecv(buffer.data() + ghost_targets_data[i][1] + offset,
                         ghost_targets_data[i][2],
-                        Utilities::MPI::internal::mpi_type_id(buffer.data()),
+                        Utilities::MPI::mpi_type_id(buffer.data()),
                         ghost_targets_data[i][0],
                         communication_channel + 1,
                         comm,
@@ -920,7 +920,7 @@ namespace internal
             const int ierr =
               MPI_Isend(temporary_storage.data() + import_targets_data[i][1],
                         import_targets_data[i][2],
-                        Utilities::MPI::internal::mpi_type_id(data_this.data()),
+                        Utilities::MPI::mpi_type_id(data_this.data()),
                         import_targets_data[i][0],
                         communication_channel + 1,
                         comm,
@@ -1173,7 +1173,7 @@ namespace internal
             const int ierr =
               MPI_Isend(buffer.data() + ghost_targets_data[i][1],
                         ghost_targets_data[i][2],
-                        Utilities::MPI::internal::mpi_type_id(buffer.data()),
+                        Utilities::MPI::mpi_type_id(buffer.data()),
                         ghost_targets_data[i][0],
                         communication_channel + 0,
                         comm,
@@ -1184,15 +1184,16 @@ namespace internal
 
         for (unsigned int i = 0; i < import_targets_data.size(); ++i)
           {
-            const int ierr = MPI_Irecv(
-              temporary_storage.data() + import_targets_data[i][1],
-              import_targets_data[i][2],
-              Utilities::MPI::internal::mpi_type_id(temporary_storage.data()),
-              import_targets_data[i][0],
-              communication_channel + 0,
-              comm,
-              requests.data() + sm_ghost_ranks.size() + sm_import_ranks.size() +
-                ghost_targets_data.size() + i);
+            const int ierr =
+              MPI_Irecv(temporary_storage.data() + import_targets_data[i][1],
+                        import_targets_data[i][2],
+                        Utilities::MPI::mpi_type_id(temporary_storage.data()),
+                        import_targets_data[i][0],
+                        communication_channel + 0,
+                        comm,
+                        requests.data() + sm_ghost_ranks.size() +
+                          sm_import_ranks.size() + ghost_targets_data.size() +
+                          i);
             AssertThrowMPI(ierr);
           }
 #endif
index 83c506f7c039c824f641cd44d44caa594e9b8bc3..750c664a85d72fc1853a6255397fd89e12613fdc 100644 (file)
@@ -119,16 +119,14 @@ test()
           if (myid == i)
             MPI_Send(&renumbering[0],
                      renumbering.size(),
-                     Utilities::MPI::internal::mpi_type_id(
-                       &complete_renumbering[0]),
+                     Utilities::MPI::mpi_type_id(&complete_renumbering[0]),
                      0,
                      i,
                      MPI_COMM_WORLD);
           else if (myid == 0)
             MPI_Recv(&complete_renumbering[offset],
                      dofs_per_proc[i].n_elements(),
-                     Utilities::MPI::internal::mpi_type_id(
-                       &complete_renumbering[0]),
+                     Utilities::MPI::mpi_type_id(&complete_renumbering[0]),
                      i,
                      i,
                      MPI_COMM_WORLD,
index 140359098975e436b0c1190f5b5b3351b068fbc9..5e2a5b215da7579d6bb4161eaf0ab42f5229b64b 100644 (file)
@@ -85,16 +85,14 @@ test()
       if (myid == i)
         MPI_Send(&renumbering[0],
                  renumbering.size(),
-                 Utilities::MPI::internal::mpi_type_id(
-                   &complete_renumbering[0]),
+                 Utilities::MPI::mpi_type_id(&complete_renumbering[0]),
                  0,
                  i,
                  MPI_COMM_WORLD);
       else if (myid == 0)
         MPI_Recv(&complete_renumbering[offset],
                  locally_owned_dofs_per_processor[i].n_elements(),
-                 Utilities::MPI::internal::mpi_type_id(
-                   &complete_renumbering[0]),
+                 Utilities::MPI::mpi_type_id(&complete_renumbering[0]),
                  i,
                  i,
                  MPI_COMM_WORLD,

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.