]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Move initialization of import_indices_plain_dev into a separate function
authorBruno Turcksin <bruno.turcksin@gmail.com>
Fri, 8 Feb 2019 14:44:36 +0000 (14:44 +0000)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Tue, 12 Feb 2019 01:32:30 +0000 (01:32 +0000)
include/deal.II/base/partitioner.h
include/deal.II/base/partitioner.templates.h
source/base/partitioner.cu

index 2c0db0955f331a2c96b8bba146a10b785cfdee4f..c98454dcbec5a2eebda685dfcc75fdac86f516a4 100644 (file)
@@ -571,6 +571,13 @@ namespace Utilities
                      << " elements for this partitioner.");
 
     private:
+      /**
+       * Initialize import_indices_plain_dev from import_indices_data. This
+       * function is only used when using CUDA-aware MPI.
+       */
+      void
+      initialize_import_indices_plain_dev() const;
+
       /**
        * The global size of the vector over all processors
        */
index 582034a7bc354319f2b474c86ccb471dffb0066d..48432cfcbc5f087f39d677953b2efad5a8897096 100644 (file)
@@ -105,47 +105,9 @@ namespace Utilities
       // performance reasons as this can significantly decrease the number of
       // kernel launched. The indices are expanded the first time the function
       // is called.
-      if (std::is_same<MemorySpaceType, MemorySpace::CUDA>::value)
-        {
-          if (import_indices_plain_dev.size() == 0)
-            {
-              import_indices_plain_dev.reserve(n_import_targets);
-              for (unsigned int i = 0; i < n_import_targets; i++)
-                {
-                  // Expand the indices on the host
-                  std::vector<std::pair<unsigned int, unsigned int>>::
-                    const_iterator my_imports =
-                                     import_indices_data.begin() +
-                                     import_indices_chunks_by_rank_data[i],
-                                   end_my_imports =
-                                     import_indices_data.begin() +
-                                     import_indices_chunks_by_rank_data[i + 1];
-                  std::vector<unsigned int> import_indices_plain_host;
-                  for (; my_imports != end_my_imports; ++my_imports)
-                    {
-                      const unsigned int chunk_size =
-                        my_imports->second - my_imports->first;
-                      for (unsigned int j = 0; j < chunk_size; ++j)
-                        import_indices_plain_host.push_back(my_imports->first +
-                                                            j);
-                    }
-
-                  // Move the indices to the device
-                  import_indices_plain_dev.emplace_back(std::make_pair(
-                    std::unique_ptr<unsigned int[], void (*)(unsigned int *)>(
-                      nullptr,
-                      Utilities::CUDA::delete_device_data<unsigned int>),
-                    import_indices_plain_host.size()));
-
-                  import_indices_plain_dev[i].first.reset(
-                    Utilities::CUDA::allocate_device_data<unsigned int>(
-                      import_indices_plain_dev[i].second));
-                  Utilities::CUDA::copy_to_dev(
-                    import_indices_plain_host,
-                    import_indices_plain_dev[i].first.get());
-                }
-            }
-        }
+      if ((std::is_same<MemorySpaceType, MemorySpace::CUDA>::value) &&
+          (import_indices_plain_dev.size() == 0))
+        initialize_import_indices_plain_dev();
 #    endif
 
       for (unsigned int i = 0; i < n_import_targets; i++)
index ed02193e891403ece946f0efcf29a8fe609d175f..4788e7571d01b695e8abffe8368d98f7da8169b8 100644 (file)
 
 DEAL_II_NAMESPACE_OPEN
 
+
+
+namespace Utilities
+{
+  namespace MPI
+  {
+    void
+    Partitioner::initialize_import_indices_plain_dev() const
+    {
+      const unsigned int n_import_targets = import_targets_data.size();
+      import_indices_plain_dev.reserve(n_import_targets);
+      for (unsigned int i = 0; i < n_import_targets; i++)
+        {
+          // Expand the indices on the host
+          std::vector<std::pair<unsigned int, unsigned int>>::const_iterator
+            my_imports = import_indices_data.begin() +
+                         import_indices_chunks_by_rank_data[i],
+            end_my_imports = import_indices_data.begin() +
+                             import_indices_chunks_by_rank_data[i + 1];
+          std::vector<unsigned int> import_indices_plain_host;
+          for (; my_imports != end_my_imports; ++my_imports)
+            {
+              const unsigned int chunk_size =
+                my_imports->second - my_imports->first;
+              for (unsigned int j = 0; j < chunk_size; ++j)
+                import_indices_plain_host.push_back(my_imports->first + j);
+            }
+
+          // Move the indices to the device
+          import_indices_plain_dev.emplace_back(std::make_pair(
+            std::unique_ptr<unsigned int[], void (*)(unsigned int *)>(
+              nullptr, Utilities::CUDA::delete_device_data<unsigned int>),
+            import_indices_plain_host.size()));
+
+          import_indices_plain_dev[i].first.reset(
+            Utilities::CUDA::allocate_device_data<unsigned int>(
+              import_indices_plain_dev[i].second));
+          Utilities::CUDA::copy_to_dev(import_indices_plain_host,
+                                       import_indices_plain_dev[i].first.get());
+        }
+    }
+  } // namespace MPI
+} // namespace Utilities
+
 // explicit instantiations from .templates.h file
 #include "partitioner.cuda.inst"
 

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.