]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Also make parallel::Vector::val a std::unique_ptr.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 20 Oct 2017 15:57:46 +0000 (09:57 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 20 Oct 2017 16:13:50 +0000 (10:13 -0600)
include/deal.II/lac/la_parallel_vector.h
include/deal.II/lac/la_parallel_vector.templates.h

index 60ff2f77c45851fc3d2b633463462e0cb6fc51c0..6777f8d8c6e7cc70bb25377375304795b805bbab 100644 (file)
@@ -1083,7 +1083,7 @@ namespace LinearAlgebra
       /**
        * Pointer to the array of local elements of this vector.
        */
-      Number         *val;
+      std::unique_ptr<Number[]> val;
 
       /**
        * For parallel loops with TBB, this member variable stores the affinity
@@ -1263,7 +1263,7 @@ namespace LinearAlgebra
     typename Vector<Number>::iterator
     Vector<Number>::begin ()
     {
-      return val;
+      return val.get();
     }
 
 
@@ -1273,7 +1273,7 @@ namespace LinearAlgebra
     typename Vector<Number>::const_iterator
     Vector<Number>::begin () const
     {
-      return val;
+      return val.get();
     }
 
 
@@ -1283,7 +1283,7 @@ namespace LinearAlgebra
     typename Vector<Number>::iterator
     Vector<Number>::end ()
     {
-      return val+partitioner->local_size();
+      return val.get()+partitioner->local_size();
     }
 
 
@@ -1293,7 +1293,7 @@ namespace LinearAlgebra
     typename Vector<Number>::const_iterator
     Vector<Number>::end () const
     {
-      return val+partitioner->local_size();
+      return val.get()+partitioner->local_size();
     }
 
 
index 7543f0d7c9a41ae6f95936ca90eeba4f29aa5bf6..cbc8a6c145c254a5052700207751f486d2a085bf 100644 (file)
@@ -64,18 +64,16 @@ namespace LinearAlgebra
         {
           Assert (((allocated_size > 0 && val != nullptr) ||
                    val == nullptr), ExcInternalError());
-          if (val != nullptr)
-            free(val);
 
-          Utilities::System::posix_memalign ((void **)&val, 64, sizeof(Number)*new_alloc_size);
+          Number *new_val;
+          Utilities::System::posix_memalign ((void **)&new_val, 64, sizeof(Number)*new_alloc_size);
+          val.reset (new_val);
 
           allocated_size = new_alloc_size;
         }
       else if (new_alloc_size == 0)
         {
-          if (val != nullptr)
-            free(val);
-          val = nullptr;
+          val.reset();
           allocated_size = 0;
         }
       thread_loop_partitioner.reset(new ::dealii::parallel::internal::TBBPartitioner());
@@ -228,7 +226,7 @@ namespace LinearAlgebra
       const size_type this_size = local_size();
       if (this_size>0)
         {
-          dealii::internal::VectorOperations::Vector_copy<Number,Number> copier(v.val, val);
+          dealii::internal::VectorOperations::Vector_copy<Number,Number> copier(v.val.get(), val.get());
           internal::VectorOperations::parallel_for(copier, 0, partitioner->local_size(),
                                                    thread_loop_partitioner);
         }
@@ -365,7 +363,7 @@ namespace LinearAlgebra
       const size_type this_size = local_size();
       if (this_size>0)
         {
-          dealii::internal::VectorOperations::Vector_copy<Number,Number2> copier(c.val, val);
+          dealii::internal::VectorOperations::Vector_copy<Number,Number2> copier(c.val.get(), val.get());
           internal::VectorOperations::parallel_for(copier, 0, this_size,
                                                    thread_loop_partitioner);
         }
@@ -524,7 +522,7 @@ namespace LinearAlgebra
 
       partitioner->import_from_ghosted_array_start
       (operation, counter,
-       ArrayView<Number>(val + partitioner->local_size(),partitioner->n_ghost_indices()),
+       ArrayView<Number>(val.get() + partitioner->local_size(),partitioner->n_ghost_indices()),
        ArrayView<Number>(import_data.get(), partitioner->n_import_indices()),
        compress_requests);
 #endif
@@ -549,8 +547,8 @@ namespace LinearAlgebra
       partitioner->import_from_ghosted_array_finish
       (operation,
        ArrayView<const Number>(import_data.get(), partitioner->n_import_indices()),
-       ArrayView<Number>(val, partitioner->local_size()),
-       ArrayView<Number>(val + partitioner->local_size(),partitioner->n_ghost_indices()),
+       ArrayView<Number>(val.get(), partitioner->local_size()),
+       ArrayView<Number>(val.get() + partitioner->local_size(),partitioner->n_ghost_indices()),
        compress_requests);
 
       vector_is_ghosted = false;
@@ -579,9 +577,9 @@ namespace LinearAlgebra
 
       partitioner->export_to_ghosted_array_start
       (counter,
-       ArrayView<const Number>(val, partitioner->local_size()),
+       ArrayView<const Number>(val.get(), partitioner->local_size()),
        ArrayView<Number>(import_data.get(), partitioner->n_import_indices()),
-       ArrayView<Number>(val + partitioner->local_size(),partitioner->n_ghost_indices()),
+       ArrayView<Number>(val.get() + partitioner->local_size(),partitioner->n_ghost_indices()),
        update_ghost_values_requests);
 
 #else
@@ -607,7 +605,7 @@ namespace LinearAlgebra
           Threads::Mutex::ScopedLock lock (mutex);
 
           partitioner->export_to_ghosted_array_finish
-          (ArrayView<Number>(val + partitioner->local_size(),partitioner->n_ghost_indices()),
+          (ArrayView<Number>(val.get() + partitioner->local_size(),partitioner->n_ghost_indices()),
            update_ghost_values_requests);
         }
 #endif
@@ -724,7 +722,7 @@ namespace LinearAlgebra
       const size_type this_size = local_size();
       if (this_size>0)
         {
-          internal::VectorOperations::Vector_set<Number> setter(s, val);
+          internal::VectorOperations::Vector_set<Number> setter(s, val.get());
 
           internal::VectorOperations::parallel_for(setter, 0, this_size,
                                                    thread_loop_partitioner);
@@ -765,7 +763,7 @@ namespace LinearAlgebra
 
       AssertDimension (local_size(), v.local_size());
 
-      internal::VectorOperations::Vectorization_add_v<Number> vector_add(val, v.val);
+      internal::VectorOperations::Vectorization_add_v<Number> vector_add(val.get(), v.val.get());
       internal::VectorOperations::parallel_for(vector_add, 0, partitioner->local_size(),
                                                thread_loop_partitioner);
 
@@ -788,7 +786,7 @@ namespace LinearAlgebra
 
       AssertDimension (local_size(), v.local_size());
 
-      internal::VectorOperations::Vectorization_subtract_v<Number> vector_subtract(val, v.val);
+      internal::VectorOperations::Vectorization_subtract_v<Number> vector_subtract(val.get(), v.val.get());
       internal::VectorOperations::parallel_for(vector_subtract, 0, partitioner->local_size(),
                                                thread_loop_partitioner);
 
@@ -806,7 +804,7 @@ namespace LinearAlgebra
     {
       AssertIsFinite(a);
 
-      internal::VectorOperations::Vectorization_add_factor<Number> vector_add(val, a);
+      internal::VectorOperations::Vectorization_add_factor<Number> vector_add(val.get(), a);
       internal::VectorOperations::parallel_for(vector_add, 0, partitioner->local_size(),
                                                thread_loop_partitioner);
 
@@ -829,7 +827,7 @@ namespace LinearAlgebra
       AssertIsFinite(a);
       AssertDimension (local_size(), v.local_size());
 
-      internal::VectorOperations::Vectorization_add_av<Number> vector_add(val, v.val, a);
+      internal::VectorOperations::Vectorization_add_av<Number> vector_add(val.get(), v.val.get(), a);
       internal::VectorOperations::parallel_for(vector_add, 0, partitioner->local_size(),
                                                thread_loop_partitioner);
 
@@ -860,8 +858,8 @@ namespace LinearAlgebra
       AssertDimension (local_size(), v.local_size());
       AssertDimension (local_size(), w.local_size());
 
-      internal::VectorOperations::Vectorization_add_avpbw<Number> vector_add(val, v.val,
-          w.val, a, b);
+      internal::VectorOperations::Vectorization_add_avpbw<Number> vector_add(val.get(), v.val.get(),
+          w.val.get(), a, b);
       internal::VectorOperations::parallel_for(vector_add, 0, partitioner->local_size(),
                                                thread_loop_partitioner);
 
@@ -893,7 +891,7 @@ namespace LinearAlgebra
       AssertIsFinite(x);
       AssertDimension (local_size(), v.local_size());
 
-      internal::VectorOperations::Vectorization_sadd_xv<Number> vector_sadd(val, v.val, x);
+      internal::VectorOperations::Vectorization_sadd_xv<Number> vector_sadd(val.get(), v.val.get(), x);
       internal::VectorOperations::parallel_for(vector_sadd, 0, partitioner->local_size(),
                                                thread_loop_partitioner);
 
@@ -918,7 +916,7 @@ namespace LinearAlgebra
       AssertIsFinite(a);
       AssertDimension (local_size(), v.local_size());
 
-      internal::VectorOperations::Vectorization_sadd_xav<Number> vector_sadd(val, v.val, a, x);
+      internal::VectorOperations::Vectorization_sadd_xav<Number> vector_sadd(val.get(), v.val.get(), a, x);
       internal::VectorOperations::parallel_for(vector_sadd, 0, partitioner->local_size(),
                                                thread_loop_partitioner);
 
@@ -943,7 +941,7 @@ namespace LinearAlgebra
       AssertDimension (local_size(), v.local_size());
       AssertDimension (local_size(), w.local_size());
 
-      internal::VectorOperations::Vectorization_sadd_xavbw<Number> vector_sadd(val, v.val, w.val,
+      internal::VectorOperations::Vectorization_sadd_xavbw<Number> vector_sadd(val.get(), v.val.get(), w.val.get(),
           x, a, b);
       internal::VectorOperations::parallel_for(vector_sadd, 0, partitioner->local_size(),
                                                thread_loop_partitioner);
@@ -959,7 +957,7 @@ namespace LinearAlgebra
     Vector<Number>::operator *= (const Number factor)
     {
       AssertIsFinite(factor);
-      internal::VectorOperations::Vectorization_multiply_factor<Number> vector_multiply(val,
+      internal::VectorOperations::Vectorization_multiply_factor<Number> vector_multiply(val.get(),
           factor);
 
       internal::VectorOperations::parallel_for(vector_multiply, 0, partitioner->local_size(),
@@ -994,7 +992,7 @@ namespace LinearAlgebra
 
       AssertDimension (local_size(), v.local_size());
 
-      internal::VectorOperations::Vectorization_scale<Number> vector_scale(val, v.val);
+      internal::VectorOperations::Vectorization_scale<Number> vector_scale(val.get(), v.val.get());
       internal::VectorOperations::parallel_for(vector_scale, 0, partitioner->local_size(),
                                                thread_loop_partitioner);
 
@@ -1017,7 +1015,7 @@ namespace LinearAlgebra
       AssertIsFinite(a);
       AssertDimension (local_size(), v.local_size());
 
-      internal::VectorOperations::Vectorization_equ_au<Number> vector_equ(val, v.val, a);
+      internal::VectorOperations::Vectorization_equ_au<Number> vector_equ(val.get(), v.val.get(), a);
       internal::VectorOperations::parallel_for(vector_equ, 0, partitioner->local_size(),
                                                thread_loop_partitioner);
 
@@ -1040,8 +1038,8 @@ namespace LinearAlgebra
       AssertDimension (local_size(), v.local_size());
       AssertDimension (local_size(), w.local_size());
 
-      internal::VectorOperations::Vectorization_equ_aubv<Number> vector_equ(val, v.val,
-          w.val, a, b);
+      internal::VectorOperations::Vectorization_equ_aubv<Number> vector_equ(val.get(), v.val.get(),
+          w.val.get(), a, b);
       internal::VectorOperations::parallel_for(vector_equ, 0, partitioner->local_size(),
                                                thread_loop_partitioner);
 
@@ -1094,7 +1092,7 @@ namespace LinearAlgebra
       AssertDimension (partitioner->local_size(), v.partitioner->local_size());
 
       Number sum;
-      internal::VectorOperations::Dot<Number,Number2> dot(val, v.val);
+      internal::VectorOperations::Dot<Number,Number2> dot(val.get(), v.val.get());
       internal::VectorOperations::parallel_reduce (dot, 0, partitioner->local_size(), sum,
                                                    thread_loop_partitioner);
       AssertIsFinite(sum);
@@ -1128,7 +1126,7 @@ namespace LinearAlgebra
     Vector<Number>::norm_sqr_local () const
     {
       real_type sum;
-      internal::VectorOperations::Norm2<Number,real_type> norm2(val);
+      internal::VectorOperations::Norm2<Number,real_type> norm2(val.get());
       internal::VectorOperations::parallel_reduce (norm2, 0, partitioner->local_size(), sum,
                                                    thread_loop_partitioner);
       AssertIsFinite(sum);
@@ -1148,7 +1146,7 @@ namespace LinearAlgebra
         return Number();
 
       Number sum;
-      internal::VectorOperations::MeanValue<Number> mean(val);
+      internal::VectorOperations::MeanValue<Number> mean(val.get());
       internal::VectorOperations::parallel_reduce (mean, 0, partitioner->local_size(), sum,
                                                    thread_loop_partitioner);
 
@@ -1178,7 +1176,7 @@ namespace LinearAlgebra
     Vector<Number>::l1_norm_local () const
     {
       real_type sum;
-      internal::VectorOperations::Norm1<Number, real_type> norm1(val);
+      internal::VectorOperations::Norm1<Number, real_type> norm1(val.get());
       internal::VectorOperations::parallel_reduce (norm1, 0, partitioner->local_size(), sum,
                                                    thread_loop_partitioner);
 
@@ -1220,7 +1218,7 @@ namespace LinearAlgebra
     Vector<Number>::lp_norm_local (const real_type p) const
     {
       real_type sum;
-      internal::VectorOperations::NormP<Number, real_type> normp(val, p);
+      internal::VectorOperations::NormP<Number, real_type> normp(val.get(), p);
       internal::VectorOperations::parallel_reduce (normp, 0, partitioner->local_size(), sum,
                                                    thread_loop_partitioner);
       return std::pow(sum, 1./p);
@@ -1284,7 +1282,7 @@ namespace LinearAlgebra
       AssertDimension (vec_size, w.local_size());
 
       Number sum;
-      internal::VectorOperations::AddAndDot<Number> adder(this->val, v.val, w.val, a);
+      internal::VectorOperations::AddAndDot<Number> adder(this->val.get(), v.val.get(), w.val.get(), a);
       internal::VectorOperations::parallel_reduce (adder, 0, vec_size, sum, thread_loop_partitioner);
       AssertIsFinite(sum);
       return sum;

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.