@@ -60,7 +60,12 @@ template <typename Tile = Tensor<double>, typename Policy = DensePolicy>
60
60
class DistArray : public madness ::archive::ParallelSerializableObject {
61
61
public:
62
62
typedef TiledArray::detail::ArrayImpl<Tile, Policy>
63
- impl_type; // /< The type of the PIMPL
63
+ impl_type; // /< The type of the implementation object
64
+ using pimpl_type =
65
+ std::shared_ptr<impl_type>; // /< shared_ptr to implementation object
66
+ using const_pimpl_type =
67
+ std::shared_ptr<const impl_type>; // /< shared_ptr to const implementation
68
+ // /< object
64
69
typedef typename impl_type::policy_type policy_type; // /< Policy type
65
70
66
71
// / Type used to hold the components of the tensors in the array. For
@@ -132,7 +137,7 @@ class DistArray : public madness::archive::ParallelSerializableObject {
132
137
std::is_same_v<std::decay_t <Value>, value_type>;
133
138
134
139
private:
135
- std::shared_ptr<impl_type> pimpl_; // /< Array implementation pointer
140
+ pimpl_type pimpl_; // /< managed ptr to Array implementation
136
141
bool defer_deleter_to_next_fence_ =
137
142
false ; // /< if true, the impl object is scheduled to be destroyed in the
138
143
// /< next fence
@@ -202,11 +207,12 @@ class DistArray : public madness::archive::ParallelSerializableObject {
202
207
203
208
// / \param world The world where the array will live.
204
209
// / \param trange The tiled range object that will be used to set the array
205
- // / tiling. \param shape The array shape that defines zero and non-zero tiles
210
+ // / tiling.
211
+ // / \param shape The array shape that defines zero and non-zero tiles
206
212
// / \param pmap The tile index -> process map
207
- static std::shared_ptr<impl_type> init (
208
- World& world, const trange_type& trange, const shape_type& shape,
209
- std::shared_ptr<const pmap_interface> pmap) {
213
+ static pimpl_type init (World& world, const trange_type& trange,
214
+ const shape_type& shape,
215
+ std::shared_ptr<const pmap_interface> pmap) {
210
216
// User level validation of input
211
217
212
218
if (!pmap) {
@@ -239,8 +245,7 @@ class DistArray : public madness::archive::ParallelSerializableObject {
239
245
" not equal to "
240
246
" the tiles range." );
241
247
242
- return std::shared_ptr<impl_type>(new impl_type (world, trange, shape, pmap),
243
- lazy_deleter);
248
+ return pimpl_type (new impl_type (world, trange, shape, pmap), lazy_deleter);
244
249
}
245
250
246
251
public:
@@ -441,6 +446,14 @@ class DistArray : public madness::archive::ParallelSerializableObject {
441
446
*this = foreach<Tile>(other, std::forward<Op>(op));
442
447
}
443
448
449
+ // / PIMPL "constructor"
450
+
451
+ // / "Constructs" an array from a shared_ptr to its implementation object.
452
+ // / Since the implementation object already exists, this is a "shallow" ctor,
453
+ // / in other words this object will refer to an already existing
454
+ // / (possibly shared) implementation
455
+ DistArray (pimpl_type pimpl) : pimpl_(std::move(pimpl)) {}
456
+
444
457
// / Destructor
445
458
446
459
// / This is a distributed lazy destructor. The object will only be deleted
@@ -481,12 +494,12 @@ class DistArray : public madness::archive::ParallelSerializableObject {
481
494
// / Accessor for the (shared_ptr to) implementation object
482
495
483
496
// / \return std::shared_ptr to the const implementation object
484
- std::shared_ptr< const impl_type> pimpl () const { return pimpl_; }
497
+ const_pimpl_type pimpl () const { return pimpl_; }
485
498
486
499
// / Accessor for the (shared_ptr to) implementation object
487
500
488
501
// / \return std::shared_ptr to the nonconst implementation object
489
- std::shared_ptr<impl_type> pimpl () { return pimpl_; }
502
+ pimpl_type pimpl () { return pimpl_; }
490
503
491
504
// / Accessor for the (weak_ptr to) implementation object
492
505
0 commit comments