From: Wolfgang Bangerth Date: Fri, 20 Oct 2017 15:57:46 +0000 (-0600) Subject: Also make parallel::Vector::val a std::unique_ptr. X-Git-Tag: v9.0.0-rc1~911^2~4 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ec6b6d33c92528072bc80405a62b9b933e429ee;p=dealii.git Also make parallel::Vector::val a std::unique_ptr. --- diff --git a/include/deal.II/lac/la_parallel_vector.h b/include/deal.II/lac/la_parallel_vector.h index 60ff2f77c4..6777f8d8c6 100644 --- a/include/deal.II/lac/la_parallel_vector.h +++ b/include/deal.II/lac/la_parallel_vector.h @@ -1083,7 +1083,7 @@ namespace LinearAlgebra /** * Pointer to the array of local elements of this vector. */ - Number *val; + std::unique_ptr val; /** * For parallel loops with TBB, this member variable stores the affinity @@ -1263,7 +1263,7 @@ namespace LinearAlgebra typename Vector::iterator Vector::begin () { - return val; + return val.get(); } @@ -1273,7 +1273,7 @@ namespace LinearAlgebra typename Vector::const_iterator Vector::begin () const { - return val; + return val.get(); } @@ -1283,7 +1283,7 @@ namespace LinearAlgebra typename Vector::iterator Vector::end () { - return val+partitioner->local_size(); + return val.get()+partitioner->local_size(); } @@ -1293,7 +1293,7 @@ namespace LinearAlgebra typename Vector::const_iterator Vector::end () const { - return val+partitioner->local_size(); + return val.get()+partitioner->local_size(); } diff --git a/include/deal.II/lac/la_parallel_vector.templates.h b/include/deal.II/lac/la_parallel_vector.templates.h index 7543f0d7c9..cbc8a6c145 100644 --- a/include/deal.II/lac/la_parallel_vector.templates.h +++ b/include/deal.II/lac/la_parallel_vector.templates.h @@ -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 copier(v.val, val); + dealii::internal::VectorOperations::Vector_copy 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 copier(c.val, val); + dealii::internal::VectorOperations::Vector_copy 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(val + partitioner->local_size(),partitioner->n_ghost_indices()), + ArrayView(val.get() + partitioner->local_size(),partitioner->n_ghost_indices()), ArrayView(import_data.get(), partitioner->n_import_indices()), compress_requests); #endif @@ -549,8 +547,8 @@ namespace LinearAlgebra partitioner->import_from_ghosted_array_finish (operation, ArrayView(import_data.get(), partitioner->n_import_indices()), - ArrayView(val, partitioner->local_size()), - ArrayView(val + partitioner->local_size(),partitioner->n_ghost_indices()), + ArrayView(val.get(), partitioner->local_size()), + ArrayView(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(val, partitioner->local_size()), + ArrayView(val.get(), partitioner->local_size()), ArrayView(import_data.get(), partitioner->n_import_indices()), - ArrayView(val + partitioner->local_size(),partitioner->n_ghost_indices()), + ArrayView(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(val + partitioner->local_size(),partitioner->n_ghost_indices()), + (ArrayView(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 setter(s, val); + internal::VectorOperations::Vector_set 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 vector_add(val, v.val); + internal::VectorOperations::Vectorization_add_v 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 vector_subtract(val, v.val); + internal::VectorOperations::Vectorization_subtract_v 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 vector_add(val, a); + internal::VectorOperations::Vectorization_add_factor 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 vector_add(val, v.val, a); + internal::VectorOperations::Vectorization_add_av 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 vector_add(val, v.val, - w.val, a, b); + internal::VectorOperations::Vectorization_add_avpbw 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 vector_sadd(val, v.val, x); + internal::VectorOperations::Vectorization_sadd_xv 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 vector_sadd(val, v.val, a, x); + internal::VectorOperations::Vectorization_sadd_xav 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 vector_sadd(val, v.val, w.val, + internal::VectorOperations::Vectorization_sadd_xavbw 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::operator *= (const Number factor) { AssertIsFinite(factor); - internal::VectorOperations::Vectorization_multiply_factor vector_multiply(val, + internal::VectorOperations::Vectorization_multiply_factor 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 vector_scale(val, v.val); + internal::VectorOperations::Vectorization_scale 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 vector_equ(val, v.val, a); + internal::VectorOperations::Vectorization_equ_au 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 vector_equ(val, v.val, - w.val, a, b); + internal::VectorOperations::Vectorization_equ_aubv 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 dot(val, v.val); + internal::VectorOperations::Dot 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::norm_sqr_local () const { real_type sum; - internal::VectorOperations::Norm2 norm2(val); + internal::VectorOperations::Norm2 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 mean(val); + internal::VectorOperations::MeanValue mean(val.get()); internal::VectorOperations::parallel_reduce (mean, 0, partitioner->local_size(), sum, thread_loop_partitioner); @@ -1178,7 +1176,7 @@ namespace LinearAlgebra Vector::l1_norm_local () const { real_type sum; - internal::VectorOperations::Norm1 norm1(val); + internal::VectorOperations::Norm1 norm1(val.get()); internal::VectorOperations::parallel_reduce (norm1, 0, partitioner->local_size(), sum, thread_loop_partitioner); @@ -1220,7 +1218,7 @@ namespace LinearAlgebra Vector::lp_norm_local (const real_type p) const { real_type sum; - internal::VectorOperations::NormP normp(val, p); + internal::VectorOperations::NormP 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 adder(this->val, v.val, w.val, a); + internal::VectorOperations::AddAndDot 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;