TiledArray  0.7.0
clone.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2015 Virginia Tech
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Justus Calvin
19  * Department of Chemistry, Virginia Tech
20  *
21  * clone.h
22  * Nov 29, 2015
23  *
24  */
25 
26 #ifndef TILEDARRAY_CONVERSIONS_CLONE_H__INCLUDED
27 #define TILEDARRAY_CONVERSIONS_CLONE_H__INCLUDED
28 
29 namespace TiledArray {
30 
32  template <typename, typename> class DistArray;
33  class DensePolicy;
34  class SparsePolicy;
35 
37 
41  template <typename Tile, typename Policy>
44  typedef typename DistArray<Tile, Policy>::value_type value_type;
45 
46  World& world = arg.world();
47 
48  // Make an empty result array
49  DistArray<Tile, Policy> result(world, arg.trange(), arg.shape(), arg.pmap());
50 
51  // Iterate over local tiles of arg
52  for(auto index : * arg.pmap()) {
53  if(arg.is_zero(index))
54  continue;
55 
56  // Spawn a task to clone the tiles
57  Future<value_type> tile =
58  world.taskq.add([] (const value_type& tile) -> value_type {
59  using TiledArray::clone;
60  return clone(tile);
61  }, arg.find(index));
62 
63  // Store result tile
64  result.set(index, tile);
65  }
66 
67  return result;
68  }
69 
70 } // namespace TiledArray
71 
72 
73 #endif // TILEDARRAY_CONVERSIONS_CLONE_H__INCLUDED
std::enable_if< detail::is_input_iterator< InIter >::value >::type set(const Index &i, InIter first)
Set a tile and fill it using a sequence.
Definition: dist_array.h:348
Future< value_type > find(const Index &i) const
Find local or remote tile.
Definition: dist_array.h:324
const shape_type & shape() const
Shape accessor.
Definition: dist_array.h:668
const trange_type & trange() const
Tiled range accessor.
Definition: dist_array.h:547
DistArray< Tile, Policy > clone(const DistArray< Tile, Policy > &arg)
Create a deep copy of an array.
Definition: clone.h:43
bool is_zero(const Index &i) const
Check for zero tiles.
Definition: dist_array.h:723
Forward declarations.
Definition: clone.h:32
World & world() const
World accessor.
Definition: dist_array.h:633
An N-dimensional shallow copy wrapper for tile objects.
Definition: tile.h:80
const std::shared_ptr< pmap_interface > & pmap() const
Process map accessor.
Definition: dist_array.h:647