{"action":"created","issue":{"url":"https://api.github.com/repos/ValeevGroup/tiledarray/issues/50","labels_url":"https://api.github.com/repos/ValeevGroup/tiledarray/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/ValeevGroup/tiledarray/issues/50/comments","events_url":"https://api.github.com/repos/ValeevGroup/tiledarray/issues/50/events","html_url":"https://github.com/ValeevGroup/tiledarray/issues/50","id":119109478,"number":50,"title":"complicated expression with Lazy tensor fails.","user":{"login":"shiozaki","id":1324578,"avatar_url":"https://avatars.githubusercontent.com/u/1324578?v=3","gravatar_id":"","url":"https://api.github.com/users/shiozaki","html_url":"https://github.com/shiozaki","followers_url":"https://api.github.com/users/shiozaki/followers","following_url":"https://api.github.com/users/shiozaki/following{/other_user}","gists_url":"https://api.github.com/users/shiozaki/gists{/gist_id}","starred_url":"https://api.github.com/users/shiozaki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shiozaki/subscriptions","organizations_url":"https://api.github.com/users/shiozaki/orgs","repos_url":"https://api.github.com/users/shiozaki/repos","events_url":"https://api.github.com/users/shiozaki/events{/privacy}","received_events_url":"https://api.github.com/users/shiozaki/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-11-26T23:14:48Z","updated_at":"2015-11-27T05:05:32Z","closed_at":null,"body":"The same example with lazy tensor fails. If we break up the expression (see if blocks), it works. **The error occurs only when >1 MPI processes are used**. The error message is:\r\n```\r\n[shiozaki@zinc src]$ mpirun -n 2 ./a.out \r\nMADNESS runtime initialized with 31 threads in the pool and affinity -1 -1 -1\r\n!! ERROR TiledArray: The Array has not been initialized, likely reason: it was default constructed and used.\r\n```\r\nHere is the complete program:\r\n```\r\n#include <tiledarray.h> // for TiledArray library\r\nclass Gen {\r\n  public:\r\n    Gen() { }\r\n    template <typename Index> double operator()(const Index& i) { return 1.0; }\r\n};\r\n\r\ntemplate<typename DataType, int N, typename Gen>\r\nclass LazyTensor {\r\n  private:\r\n    TiledArray::Array<DataType, N, LazyTensor>* owner_;\r\n    std::array<size_t, N> index_;\r\n    Gen* gen_;\r\n\r\n  public:\r\n    using value_type = DataType;\r\n    using eval_type = TiledArray::Tensor<DataType>;\r\n    using range_type = typename eval_type::range_type;\r\n\r\n    template <typename Archive>\r\n    void serialize(Archive& ar) {\r\n//    assert(false);\r\n    }\r\n\r\n  public:\r\n    LazyTensor(TiledArray::Array<DataType, N, LazyTensor>* o, const std::array<size_t, N>& i, Gen* gen)\r\n     : owner_(o), index_(i), gen_(gen) {\r\n    }\r\n\r\n    LazyTensor(const LazyTensor& other) : owner_(other.owner_), index_(other.index_), gen_(other.gen_) { }\r\n    LazyTensor() { }\r\n\r\n    LazyTensor& operator=(const LazyTensor& other) {\r\n      owner_ = other.owner_;\r\n      index_ = other.index_;\r\n      gen_   = other.gen_;\r\n      return *this;\r\n    }\r\n\r\n    operator eval_type () const {\r\n      eval_type tile(owner_->trange().make_tile_range(index_));\r\n      auto* ptr = tile.data();\r\n      for (auto& i : tile.range())\r\n        *ptr++ = (*gen_)(i);\r\n      return tile;\r\n    }\r\n};\r\n\r\n\r\nnamespace TA = TiledArray;\r\n\r\nint main(int argc, char** argv) {\r\n  // Initialize runtime\r\n  madness::World& world = madness::initialize(argc, argv);\r\n\r\n  // Construct tile boundary vector\r\n  std::vector<std::size_t> tile_boundaries;\r\n  for(std::size_t i = 0; i <= 16; i += 4)\r\n    tile_boundaries.push_back(i);\r\n\r\n  // Construct a set of TiledRange1's\r\n  std::vector<TiledArray::TiledRange1>\r\n    ranges(4, TiledArray::TiledRange1(tile_boundaries.begin(), tile_boundaries.end()));\r\n  std::vector<TiledArray::TiledRange1>\r\n    ranges3(3, TiledArray::TiledRange1(tile_boundaries.begin(), tile_boundaries.end()));\r\n\r\n\r\n  // Construct the 2D TiledRange\r\n  TA::TiledRange trange(ranges.begin(), ranges.end());\r\n  TA::TiledRange trange3(ranges3.begin(), ranges3.end());\r\n\r\n  // Construct array objects.\r\n  TA::Array<double, 4> a(world, trange);\r\n  TA::Array<double, 4> b(world, trange);\r\n  TA::Array<double, 3> c(world, trange3);\r\n\r\n  using Lazy = LazyTensor<double,3,Gen>;\r\n  TA::Array<double, 3, Lazy> d(world, trange3);\r\n  Gen gen;\r\n  for (auto& t : d.trange().tiles())\r\n    if (d.is_local(t)) {\r\n      std::array<size_t, 3> index;\r\n      std::copy(t.begin(), t.end(), index.begin());\r\n      madness::Future<typename TA::Array<double, 3, Lazy>::value_type> tile(Lazy(&d, index, &gen));\r\n      d.set(t, tile);\r\n    }\r\n\r\n\r\n  // Initialize a and b.\r\n  a.fill_local(0.0);\r\n  b.fill_local(0.0);\r\n  c.fill_local(0.0);\r\n\r\n#if 1\r\n  // THIS FAILS\r\n  a(\"x6,a3,x5,a1\") = b(\"x0,a1,x2,a3\") * c(\"o4,x0,x2\") * d(\"a1,a3,o4\") * c(\"o4,x5,x6\");\r\n#else\r\n  // THIS WORKS\r\n  TA::Array<double, 3> tmp1(world, trange3);\r\n  TA::Array<double, 3> tmp2(world, trange3);\r\n  tmp1(\"a1,a3,o4\") = b(\"x0,a1,x2,a3\") * c(\"o4,x0,x2\");\r\n  tmp2(\"a1,a3,o4\") = tmp1(\"a1,a3,o4\") * d(\"a1,a3,o4\");\r\n  a(\"x6,a3,x5,a1\") = tmp2(\"a1,a3,o4\") * c(\"o4,x5,x6\");\r\n#endif\r\n\r\n  // Wait for all the computation to complete before exiting\r\n  world.gop.fence();\r\n\r\n  madness::finalize();\r\n  return 0;\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/ValeevGroup/tiledarray/issues/comments/160044519","html_url":"https://github.com/ValeevGroup/tiledarray/issues/50#issuecomment-160044519","issue_url":"https://api.github.com/repos/ValeevGroup/tiledarray/issues/50","id":160044519,"user":{"login":"shiozaki","id":1324578,"avatar_url":"https://avatars.githubusercontent.com/u/1324578?v=3","gravatar_id":"","url":"https://api.github.com/users/shiozaki","html_url":"https://github.com/shiozaki","followers_url":"https://api.github.com/users/shiozaki/followers","following_url":"https://api.github.com/users/shiozaki/following{/other_user}","gists_url":"https://api.github.com/users/shiozaki/gists{/gist_id}","starred_url":"https://api.github.com/users/shiozaki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shiozaki/subscriptions","organizations_url":"https://api.github.com/users/shiozaki/orgs","repos_url":"https://api.github.com/users/shiozaki/repos","events_url":"https://api.github.com/users/shiozaki/events{/privacy}","received_events_url":"https://api.github.com/users/shiozaki/received_events","type":"User","site_admin":false},"created_at":"2015-11-27T05:05:32Z","updated_at":"2015-11-27T05:05:32Z","body":"@justusc Since I gave you a complete code, can you give me a complete code that works? Please note that \"return 1.0\" (line 5) is actually more complicated in the actual code."}}