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