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: Mon, 30 Jul 2018 21:54:35 -0400 (EDT)

branch: comparing_stored_objects_by_key
commit 012f127cb5e159d0e03ff4195fb70b85c40417a9
Author: aa <address@hidden>
Date:   Tue Jul 31 00:19:06 2018 +0200

    - search_stored_object_on_all_threads
     - equal method for static keys
---
 src/dal_static_stored_objects.cc       | 20 ++++++++++++++++++++
 src/getfem/dal_static_stored_objects.h | 29 +++++++++++++++++++++--------
 2 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/src/dal_static_stored_objects.cc b/src/dal_static_stored_objects.cc
index 67445b0..fef41c6 100644
--- a/src/dal_static_stored_objects.cc
+++ b/src/dal_static_stored_objects.cc
@@ -191,6 +191,26 @@ static bool dal_static_stored_tab_valid__ = true;
     return 0;
   }
 
+  pstatic_stored_object 
search_stored_object_on_all_threads(pstatic_stored_object_key k)
+  {
+    auto& stored_objects = singleton<stored_object_tab>::instance();
+    if (dal_static_stored_tab_valid__) {
+      auto p = stored_objects.search_stored_object(k);
+      if (p) return p;
+      else if (num_threads() > 1){
+        for(size_t thread = 0; thread < getfem::num_threads(); thread++)
+        {
+          if (thread == this_thread()) continue;
+          auto& other_objects = singleton<stored_object_tab>::instance(thread);
+          p = other_objects.search_stored_object(k);
+          if (p) return p;
+        }
+      }
+      return nullptr;
+    }
+    return nullptr;
+  }
+
   std::pair<stored_object_tab::iterator, stored_object_tab::iterator> 
iterators_of_object(
     pstatic_stored_object o)
   {
diff --git a/src/getfem/dal_static_stored_objects.h 
b/src/getfem/dal_static_stored_objects.h
index f8acb95..ce5b547 100644
--- a/src/getfem/dal_static_stored_objects.h
+++ b/src/getfem/dal_static_stored_objects.h
@@ -127,9 +127,8 @@ namespace dal {
 
   class static_stored_object_key {
   protected :
-    virtual bool compare(const static_stored_object_key &) const {
-      GMM_ASSERT1(false, "This method should not be called");
-    }
+    virtual bool compare(const static_stored_object_key &) const = 0;
+    virtual bool equal(const static_stored_object_key &) const = 0;
 
   public :
     bool operator < (const static_stored_object_key &o) const {
@@ -139,18 +138,30 @@ namespace dal {
       return compare(o);
     }
 
-    virtual ~static_stored_object_key() {}
+    bool operator == (const static_stored_object_key &o) const {
+      if (typeid(o)!=typeid(*this)) return false;
+      return equal(o);
+    }
 
-  };
+    bool operator != (const static_stored_object_key &o) const {
+      return !(*this == o);
+    }
 
+    virtual ~static_stored_object_key() {}
+  };
 
   template <typename var_type>
   class simple_key : virtual public static_stored_object_key {
     var_type a;
   public :
-    virtual bool compare(const static_stored_object_key &oo) const {
-      const simple_key &o = dynamic_cast<const simple_key &>(oo);
-      return (a < o.a);
+     bool compare(const static_stored_object_key &oo) const override {
+      auto &o = dynamic_cast<const simple_key &>(oo);
+      return a < o.a;
+    }
+
+    bool equal(const static_stored_object_key &oo) const override {
+      auto &o = dynamic_cast<const simple_key &>(oo);
+      return a == o.a;
     }
     simple_key(var_type aa) : a(aa) {}
   };
@@ -208,6 +219,8 @@ namespace dal {
   /** Gives a pointer to an object from a key pointer. */
   pstatic_stored_object search_stored_object(pstatic_stored_object_key k);
 
+  pstatic_stored_object 
search_stored_object_on_all_threads(pstatic_stored_object_key k);
+
   /** Test if an object is stored*/
   bool exists_stored_object(pstatic_stored_object o);
 



reply via email to

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