]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Merge pull request #17425 from tjhei/nvcc-particle-get_prop-hack
authorDaniel Arndt <arndtd@ornl.gov>
Tue, 6 Aug 2024 19:40:42 +0000 (15:40 -0400)
committerDaniel Arndt <arndtd@ornl.gov>
Tue, 6 Aug 2024 20:10:51 +0000 (16:10 -0400)
fix nvcc compilation in particle handler

include/deal.II/particles/particle_accessor.h
include/deal.II/particles/property_pool.h

index 0d0706dfbd48c8513da18880a5e57717ef94ba95..a4ff6dba1a408189ec1408e21c56aded78c8dc3d 100644 (file)
@@ -326,7 +326,21 @@ namespace Particles
      * @return An ArrayView of the properties of this particle.
      */
     ArrayView<double>
-    get_properties();
+    get_properties()
+    {
+      // The implementation is up here inside the class declaration because
+      // NVCC (at least in 12.5 and 12.6) otherwise produce a compile error:
+      //
+      // error: no declaration matches ‘dealii::ArrayView<__remove_cv(const
+      // double)> dealii::Particles::ParticleAccessor<dim,
+      // spacedim>::get_properties()’
+      //
+      // See https://github.com/dealii/dealii/issues/17148
+      Assert(state() == IteratorState::valid, ExcInternalError());
+
+      return property_pool->get_properties(get_handle());
+    }
+
 
     /**
      * Get read-access to properties of this particle.
@@ -840,14 +854,9 @@ namespace Particles
 
 
 
-  template <int dim, int spacedim>
-  inline ArrayView<double>
-  ParticleAccessor<dim, spacedim>::get_properties()
-  {
-    Assert(state() == IteratorState::valid, ExcInternalError());
-
-    return property_pool->get_properties(get_handle());
-  }
+  // template <int dim, int spacedim>
+  // inline ArrayView<double>
+  //   ParticleAccessor<dim, spacedim>::get_properties()
 
 
 
index 5ce9ce3b06bd3929ff19509359db5806a1772414..d8f868d39d4c302035c78a91a44c6651c74defa3 100644 (file)
@@ -202,8 +202,36 @@ namespace Particles
      * Return an ArrayView to the properties that correspond to the given
      * handle @p handle.
      */
-    ArrayView<double>
-    get_properties(const Handle handle);
+    ArrayView<double, dealii::MemorySpace::Host>
+    get_properties(const Handle handle)
+    {
+      // The implementation is up here inside the class declaration because
+      // NVCC (at least in 12.5 and 12.6) otherwise produce a compile error:
+      //
+      // error: no declaration matches ‘dealii::ArrayView<__remove_cv(const
+      // double)> dealii::Particles::PropertyPool<dim,
+      // spacedim>::get_properties(Handle)’
+      //
+      // See https://github.com/dealii/dealii/issues/17148
+
+      const std::vector<double>::size_type data_index =
+        (handle != invalid_handle) ? handle * n_properties : 0;
+
+      // Ideally we would need to assert that 'handle' has not been deallocated
+      // by searching through 'currently_available_handles'. However, this
+      // is expensive and this function is performance critical, so instead
+      // just check against the array range, and rely on the fact
+      // that handles are invalidated when handed over to
+      // deallocate_properties_array().
+      Assert(data_index <= properties.size() - n_properties,
+             ExcMessage(
+               "Invalid property handle. This can happen if the "
+               "handle was duplicated and then one copy was deallocated "
+               "before trying to access the properties."));
+
+      return ArrayView<double>(properties.data() + data_index, n_properties);
+    }
+
 
     /**
      * Reserve the dynamic memory needed for storing the properties of
@@ -455,26 +483,9 @@ namespace Particles
 
 
 
-  template <int dim, int spacedim>
-  inline ArrayView<double>
-  PropertyPool<dim, spacedim>::get_properties(const Handle handle)
-  {
-    const std::vector<double>::size_type data_index =
-      (handle != invalid_handle) ? handle * n_properties : 0;
-
-    // Ideally we would need to assert that 'handle' has not been deallocated
-    // by searching through 'currently_available_handles'. However, this
-    // is expensive and this function is performance critical, so instead
-    // just check against the array range, and rely on the fact
-    // that handles are invalidated when handed over to
-    // deallocate_properties_array().
-    Assert(data_index <= properties.size() - n_properties,
-           ExcMessage("Invalid property handle. This can happen if the "
-                      "handle was duplicated and then one copy was deallocated "
-                      "before trying to access the properties."));
-
-    return ArrayView<double>(properties.data() + data_index, n_properties);
-  }
+  // template <int dim, int spacedim>
+  // inline ArrayView<double, dealii::MemorySpace::Host>
+  //   PropertyPool<dim, spacedim>::get_properties(const Handle handle)
 
 
 

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.