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>
33 class DistArray;
34 class DensePolicy;
35 class SparsePolicy;
36 
38 
42 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)) continue;
54 
55  // Spawn a task to clone the tiles
56  Future<value_type> tile = world.taskq.add(
57  [](const value_type& tile) -> value_type {
58  using TiledArray::clone;
59  return clone(tile);
60  },
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 #endif // TILEDARRAY_CONVERSIONS_CLONE_H__INCLUDED
void set(const Index &i, InIter first)
Definition: dist_array.h:619
DistArray< Tile, Policy > clone(const DistArray< Tile, Policy > &arg)
Create a deep copy of an array.
Definition: clone.h:43
const trange_type & trange() const
Tiled range accessor.
Definition: dist_array.h:917
Future< value_type > find(const Index &i) const
Find local or remote tile by index.
Definition: dist_array.h:524
const shape_type & shape() const
Shape accessor.
Definition: dist_array.h:1039
Forward declarations.
Definition: dist_array.h:57
World & world() const
World accessor.
Definition: dist_array.h:1007
bool is_zero(const Index &i) const
Check for zero tiles.
Definition: dist_array.h:1137
const std::shared_ptr< pmap_interface > & pmap() const
Process map accessor.
Definition: dist_array.h:1019
An N-dimensional shallow copy wrapper for tile objects.
Definition: tile.h:82