[Getfem-commits] [getfem-commits] branch devel-logari81-gcc9-openmp updated: Fix compilation warnings and reduce code duplication

2020-05-22 Thread Konstantinos Poulios via Getfem-commits
This is an automated email from the git hooks/post-receive script.

logari81 pushed a commit to branch devel-logari81-gcc9-openmp
in repository getfem.

The following commit(s) were added to refs/heads/devel-logari81-gcc9-openmp by 
this push:
 new b63998e  Fix compilation warnings and reduce code duplication
b63998e is described below

commit b63998e72d5d508542797b769a160f13402e4467
Author: Konstantinos Poulios 
AuthorDate: Fri May 22 22:16:16 2020 +0200

Fix compilation warnings and reduce code duplication
---
 src/getfem/bgeot_small_vector.h | 253 +---
 1 file changed, 108 insertions(+), 145 deletions(-)

diff --git a/src/getfem/bgeot_small_vector.h b/src/getfem/bgeot_small_vector.h
index 3a7ec80..e0aa95a 100644
--- a/src/getfem/bgeot_small_vector.h
+++ b/src/getfem/bgeot_small_vector.h
@@ -44,7 +44,7 @@
 # define SVEC_ASSERT(x) assert(x)
 #else
 # define SVEC_ASSERT(x)
-#endif 
+#endif
 
 namespace bgeot {
 
@@ -54,7 +54,7 @@ namespace bgeot {
 typedef gmm::uint32_type node_id;
 typedef gmm::uint32_type size_type;
 /* number of objects stored in a same block, power of 2 */
-enum { p2_BLOCKSZ = 8, BLOCKSZ = 1<(::operator new(BLOCKSZ*objsz + 
BLOCKSZ)); 
+   clear();
+   data = static_cast(::operator new(BLOCKSZ*objsz + 
BLOCKSZ));
/* first BLOCKSZ bytes are used for reference counting */
memset(data, 0, BLOCKSZ);
//cout << "init block&" << this << " allocated data: " << (void*)data 
<< "\n";
   }
-  void clear() { 
+  void clear() {
//cout << "clear block&" << this << " frees data: " << (void*)data << 
"\n";
-   if (data) { ::operator delete(data); }; 
+   if (data) { ::operator delete(data); };
data = 0; first_unused_chunk = 0; count_unused_chunk = BLOCKSZ;
   }
   unsigned char& refcnt(size_type pos) { return data[pos]; }
   bool empty() const { return data == 0; }
   /* could be smarter .. */
 };
-/* container of all blocks .. a vector ensures fast access to 
+/* container of all blocks .. a vector ensures fast access to
any element (better than deque) */
-std::vector blocks; 
+std::vector blocks;
 /* pointers to free (or partially free) blocks for each object size */
 size_type first_unfilled[OBJ_SIZE_LIMIT];
   public:
@@ -145,17 +145,60 @@ namespace bgeot {
 void insert_block_into_unfilled(block_allocator::size_type bid);
 void remove_block_from_unfilled(block_allocator::size_type bid);
   };
-  
+
   /* common class for all mini_vec, provides access to the common static 
allocator */
   struct APIDECL static_block_allocator {
-/* must be a pointer ... sgi CC is not able to order correctly the 
+/* must be a pointer ... sgi CC is not able to order correctly the
destructors of static variables */
 static block_allocator *palloc;
 static_block_allocator() { if (!palloc) 
palloc=::singleton::instance(); } //new 
block_allocator(); }
   };
-  
-#if !defined GETFEM_HAS_OPENMP
-  /** container for small vectors of POD (Plain Old Data) types. Should be as 
fast as 
+
+#ifdef GETFEM_HAS_OPENMP
+  /**In case of multi-threaded assembly with OpenMP using std::vector derived
+  class for it's thread safety*/
+  template class small_vector : public std::vector
+  {
+  public:
+using typename std::vector::const_iterator;
+using typename std::vector::iterator;
+const_iterator begin() const { return std::vector::begin(); }
+iterator begin() { return std::vector::begin(); }
+const_iterator end() const { return std::vector::end(); }
+iterator end() { return std::vector::end(); }
+
+const_iterator const_begin() const { return std::vector::cbegin(); }
+const_iterator const_end() const { return std::vector::cend(); }
+dim_type size() const { return dim_type(std::vector::size()); }
+
+const small_vector& operator=(const small_vector& other) {
+  std::vector::operator=(other);
+  return *this;
+}
+
+small_vector() : std::vector()  {}
+
+explicit small_vector(size_type n) : std::vector(n) {}
+
+small_vector(const small_vector& v) : std::vector(v) {}
+
+small_vector(const std::vector&  v) : std::vector(v) {}
+
+small_vector(T v1, T v2) : std::vector(2)
+{ (*this)[0] = v1; (*this)[1] = v2; }
+
+small_vector(T v1, T v2, T v3) : std::vector(3)
+{ (*this)[0] = v1; (*this)[1] = v2; (*this)[2] = v3; }
+
+template small_vector(const small_vector& a, UNOP op)
+  : std::vector(a.size())
+{ std::transform(a.begin(), a.end(), begin(), op); }
+
+template small_vector(const small_vector& a, const 
small_vector& b, BINOP op)
+  : std::vector(a.size())
+{ std::transform(a.begin(), a.end(), b.begin(), begin(), op); }
+#else
+  /** container for small vectors of POD (Plain Old Data) types. Should be as 
fast as
   std::vector while beeing smaller and uses copy-on-write. The gain is 
especially
   valuable on 64 bits 

[Getfem-commits] (no subject)

2020-05-22 Thread Konstantinos Poulios via Getfem-commits
branch: devel-logari81-gcc9-openmp
commit efe0d4541f6b972d1c48ad685131f42d68ff56b8
Author: Konstantinos Poulios 
AuthorDate: Fri May 22 12:01:45 2020 +0200

Fix compilation and test errors with --enable-openmp
---
 src/getfem/getfem_omp.h| 5 -
 tests/test_kdtree.cc   | 2 ++
 tests/test_small_vector.cc | 3 ++-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/getfem/getfem_omp.h b/src/getfem/getfem_omp.h
index f8dbaa7..f224ffe 100644
--- a/src/getfem/getfem_omp.h
+++ b/src/getfem/getfem_omp.h
@@ -54,6 +54,9 @@ namespace getfem
   using bgeot::size_type;
 
 #ifdef GETFEM_HAS_OPENMP
+  void parallel_execution(std::function lambda,
+  bool iterate_over_partitions);
+
   //declaring a thread lock, to protect multi-threaded accesses to
   //asserts, traces and warnings. Using a global mutex
   class omp_guard
@@ -486,4 +489,4 @@ namespace getfem
 
   #endif
 
-}  /* end of namespace getfem. */
\ No newline at end of file
+}  /* end of namespace getfem. */
diff --git a/tests/test_kdtree.cc b/tests/test_kdtree.cc
index 331b569..9e29656 100644
--- a/tests/test_kdtree.cc
+++ b/tests/test_kdtree.cc
@@ -115,7 +115,9 @@ void speed_test(unsigned N, unsigned NPT, unsigned nrepeat) 
{
 for (dim_type k = 0; k < N; ++k) 
   pt[k] = gmm::random(double())*2.;
 tree.add_point(pt);
+#ifndef GETFEM_HAS_OPENMP
 assert(pt.refcnt()>1);
+#endif
   }
   t = gmm::uclock_sec();
   cout << "point list built in " << gmm::uclock_sec() - t << " seconds.\n";
diff --git a/tests/test_small_vector.cc b/tests/test_small_vector.cc
index 6aac7f1..7abf61a 100644
--- a/tests/test_small_vector.cc
+++ b/tests/test_small_vector.cc
@@ -779,7 +779,8 @@ namespace getfem {
 //rrun(mv);
 rrun(Sv);
 //rrun(av);
-bgeot::static_block_allocator::palloc->memstats();
+if (bgeot::static_block_allocator::palloc)
+  bgeot::static_block_allocator::palloc->memstats();
 cout << "sizeof(size_type)=" << sizeof(size_type) 
 << ", sizeof(base_node)=" << sizeof(base_node) 
 << ", sizeof(base_small_vector)=" << sizeof(base_small_vector) << "\n";



[Getfem-commits] [getfem-commits] branch devel-logari81-gcc9-openmp created (now efe0d45)

2020-05-22 Thread Konstantinos Poulios via Getfem-commits
logari81 pushed a change to branch devel-logari81-gcc9-openmp.

  at efe0d45  Fix compilation and test errors with --enable-openmp

This branch includes the following new commits:

 new efe0d45  Fix compilation and test errors with --enable-openmp