]> https://gitweb.dealii.org/ - dealii.git/commitdiff
base/mpi.cc: remove superfluous explicit instantiations of template variable
authorMatthias Maier <tamiko@43-1.org>
Thu, 15 Feb 2024 21:54:36 +0000 (15:54 -0600)
committerMatthias Maier <tamiko@43-1.org>
Thu, 15 Feb 2024 21:54:36 +0000 (15:54 -0600)
The `mpi.h` header already contains:
```
template <typename T>
const MPI_Datatype mpi_type_id_for_type = /* implementation detail */;
```
Meaning, the variable is known fully after including the header.
Furthermore, the `const` qualifier marks the (template) variable as
`static`. I.e., it has internal linkage.

Thus, we must not explicitly instantiate the variables (suggesting
"extern" linkage in all but the `mpi.cc` compilation unit). This
apparently not an issue with OpenMPI because `MPI_Datatype` is a
complex data structure. But it is an issue with mpich where
`MPI_Datatype` is a simple `int` - leading to a segmentation fault when
during program startup.

source/base/mpi.cc

index 39f9b92f87f0bd9ce3588ee16d3a4e0ad3207a61..95aa3021e1f25cc5bfcd1a071c2ebb55320409ba 100644 (file)
@@ -99,26 +99,6 @@ namespace Utilities
 
   namespace MPI
   {
-#ifdef DEAL_II_WITH_MPI
-    // Provide definitions of template variables for all valid instantiations.
-    template const MPI_Datatype mpi_type_id_for_type<bool>;
-    template const MPI_Datatype mpi_type_id_for_type<char>;
-    template const MPI_Datatype mpi_type_id_for_type<signed char>;
-    template const MPI_Datatype mpi_type_id_for_type<short>;
-    template const MPI_Datatype mpi_type_id_for_type<int>;
-    template const MPI_Datatype mpi_type_id_for_type<long int>;
-    template const MPI_Datatype mpi_type_id_for_type<unsigned char>;
-    template const MPI_Datatype mpi_type_id_for_type<unsigned short>;
-    template const MPI_Datatype mpi_type_id_for_type<unsigned long int>;
-    template const MPI_Datatype mpi_type_id_for_type<unsigned long long int>;
-    template const MPI_Datatype mpi_type_id_for_type<float>;
-    template const MPI_Datatype mpi_type_id_for_type<double>;
-    template const MPI_Datatype mpi_type_id_for_type<long double>;
-    template const MPI_Datatype mpi_type_id_for_type<std::complex<float>>;
-    template const MPI_Datatype mpi_type_id_for_type<std::complex<double>>;
-#endif
-
-
     MinMaxAvg
     min_max_avg(const double my_value, const MPI_Comm mpi_communicator)
     {

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.