getfem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Getfem-commits] (no subject)


From: Andriy Andreykiv
Subject: [Getfem-commits] (no subject)
Date: Wed, 26 Dec 2018 10:50:58 -0500 (EST)

branch: consistent_partitioning_for_open_mp
commit f217241b036404d43fe3c5cdef47a10546546354
Author: andrico <address@hidden>
Date:   Wed Dec 26 16:50:36 2018 +0100

    fixing segmentation fault caused by the fact that omp_distribute for 
singletons was destroyed before the objects from it were deleted. Fixed by 
creating it dynamically and deleting only when its content was emptied
---
 src/getfem/dal_singleton.h | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/getfem/dal_singleton.h b/src/getfem/dal_singleton.h
index 282cb5d..891c00f 100644
--- a/src/getfem/dal_singleton.h
+++ b/src/getfem/dal_singleton.h
@@ -80,24 +80,24 @@ namespace dal {
   template <typename T, int LEV>
   class singleton_instance : public singleton_instance_base {
 
-    static getfem::omp_distribute<T*>& omp_distro() {
-      static auto instance = getfem::omp_distribute<T*>{};
-      return instance;
+    static getfem::omp_distribute<T*>*& omp_distro_pointer() {
+      static auto pointer = new getfem::omp_distribute<T*>{};
+      return pointer;
     }
 
     static T*& instance_pointer() {
-      return omp_distro().thrd_cast();
+      return omp_distro_pointer()->thrd_cast();
     }
 
     static T*& instance_pointer(size_t ithread) {
-      return omp_distro()(ithread);
+      return (*omp_distro_pointer())(ithread);
     }
 
   public:
 
     /**Instance from thread ithread*/
     inline static T& instance(size_t ithread) {
-      omp_distro().on_thread_update();
+      omp_distro_pointer()->on_thread_update();
       T*& tinstance_ = instance_pointer(ithread);
       if (!tinstance_) {
         tinstance_ = new T();
@@ -113,11 +113,11 @@ namespace dal {
     }
 
     inline static size_type num_threads() {
-      return omp_distro().num_threads();
+      return omp_distro_pointer()->num_threads();
     }
 
     inline static size_type this_thread() {
-      return omp_distro().this_thread();
+      return omp_distro_pointer()->this_thread();
     }
 
     int level() const override {
@@ -125,12 +125,16 @@ namespace dal {
     }
 
     ~singleton_instance() {
-      for(size_t i = 0; i != omp_distro().num_threads(); ++i) {
-        if(omp_distro()(i)){
-          delete omp_distro()(i);
-          omp_distro()(i) = nullptr;
+      if (!omp_distro_pointer()) return;
+      for(size_t i = 0; i != omp_distro_pointer()->num_threads(); ++i) {
+        auto &p_singleton = (*omp_distro_pointer())(i);
+        if(p_singleton){
+          delete p_singleton;
+          p_singleton = nullptr;
         }
       }
+      delete omp_distro_pointer();
+      omp_distro_pointer() = nullptr;
     }
   };
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]