33#ifndef MADNESS_MRA_VMRA_H__INCLUDED
34#define MADNESS_MRA_VMRA_H__INCLUDED
134 template <
typename T, std::
size_t NDIM>
138 if (std::any_of(
v.begin(),
v.end(), [](
const Function<T,NDIM>&
f) {return not f.is_initialized();})) {
141 TreeState state=
v[0].get_impl()->get_tree_state();
142 for (
const auto&
f :
v) {
149 template <
typename T, std::
size_t NDIM>
162 template <
typename T, std::
size_t NDIM>
171 template <
typename T, std::
size_t NDIM>
177 template <
typename T, std::
size_t NDIM>
186 template <
typename T, std::
size_t NDIM>
196 template <
typename T, std::
size_t NDIM>
199 for (
const auto&
f : vf)
f.refine(
false);
206 template <
typename T, std::
size_t NDIM>
212 std::vector<FunctionImpl<T,NDIM>*> v_ptr;
215 for (
unsigned int i=0; i<vf.size(); ++i) {
216 if (vf[i].is_initialized()) v_ptr.push_back(vf[i].
get_impl().get());
220 std::sort(v_ptr.begin(),v_ptr.end());
221 typename std::vector<FunctionImpl<T, NDIM>*>::iterator it;
222 it = std::unique(v_ptr.begin(), v_ptr.end());
225 std::vector< Tensor<T> >
c(v_ptr.size());
226 v_ptr[0]->refine_to_common_level(v_ptr,
c, key0);
227 if (fence) v_ptr[0]->world.gop.fence();
229 for (
unsigned int i=0; i<vf.size(); i++) vf[i].
verify_tree();
233 template <
typename T, std::
size_t NDIM>
243 template <
typename T, std::
size_t NDIM>
256 template <
typename T, std::
size_t NDIM>
259 const bool fence=
true) {
261 if (
v.size()==0)
return v;
266 for (
const auto&
f :
v)
267 if (
f.is_initialized()) {
276 auto change_initial_to_intermediate =[](
const std::vector<Function<T,NDIM>>&
v,
281 if (
f.is_initialized() and
f.get_impl()->get_tree_state()==initialstate) {
282 f.change_tree_state(intermediatestate,
false);
316 template<
typename T, std::
size_t NDIM>
328 print(
"ensure_tree_state_respecting_fence failed");
329 throw std::runtime_error(
"ensure_tree_state_respecting_fence failed");
335 template <
typename T, std::
size_t NDIM>
347 vv.truncate(tol,
false);
356 template <
typename T, std::
size_t NDIM>
358 double tol=0.0,
bool fence=
true) {
359 if (
v.size()>0)
truncate(
v[0].world(),
v,tol,fence);
366 template <
typename T, std::
size_t NDIM>
368 double thresh=0.0,
bool fence=
true) {
369 if (
v.size()==0)
return v;
370 for (
auto& vv :
v) vv.reduce_rank(
thresh,
false);
371 if (fence)
v[0].world().gop.fence();
381 template <
typename T, std::
size_t NDIM>
388 for (
const auto&
D :
grad)
389 for (
const auto&
f :
v)
D->stage_halo(
f.get_impl().get(),
false);
396 template <
typename T, std::
size_t NDIM>
399 for (
const auto&
f :
v)
f.get_impl()->halo_clear();
403 template <
typename T, std::
size_t NDIM>
404 std::vector< Function<T,NDIM> >
411 std::vector< Function<T,NDIM> > df(
v.size());
412 for (
unsigned int i=0; i<
v.size(); ++i) {
413 df[i] =
D(
v[i],
false);
420 template <
typename T, std::
size_t NDIM>
421 std::vector< Function<T,NDIM> >
423 std::vector< Function<T,NDIM> > r(n);
424 for (
int i=0; i<n; ++i) {
430 print(
"zero_functions_tree_state: unknown tree state");
431 throw std::runtime_error(
"zero_functions_tree_state: unknown tree state");
441 template <
typename T, std::
size_t NDIM>
442 std::vector< Function<T,NDIM> >
444 return zero_functions_tree_state<T,NDIM>(world,n,
reconstructed,fence);
448 template <
typename T, std::
size_t NDIM>
449 std::vector< Function<T,NDIM> >
451 return zero_functions_tree_state<T,NDIM>(world,n,
compressed,fence);
455 template <
typename T, std::
size_t NDIM>
456 std::vector< Function<T,NDIM> >
459 return zero_functions_tree_state<T,NDIM>(world,n,state,fence);
465 template<
typename T, std::
size_t NDIM>
467 if (vf_in.size()==0)
return std::vector<Function<T,NDIM>>();
468 World& world=vf_in.front().world();
469 auto vf=
copy(world,vf_in);
471 if (vf.size()==1)
return copy(world,vf_in);
476 for (
int i=0; i<s.dim(0); ++i)
Q(i,i) += 1.5;
483 for (
int i=0; i<
Q.dim(0); ++i)
484 for (
int j=0; j<i; ++j)
500 template <
typename T, std::
size_t NDIM>
504 double lindep = 1
e-12) {
505 if(
v.empty())
return v;
507 World& world =
v.front().world();
508 const size_t n =
v.
size();
513 lindep *= s(s.size() - 1);
516 int rank = 0, nlindep = 0;
517 for(
size_t i = 0; i < n; ++i) {
518 const auto s_i = s(i);
519 s(i) = 1.0 / sqrt(s_i);
520 (s_i > lindep) ? rank++ : nlindep++;
526 if (world.
rank() == 0)
527 print(
"WARNING: linear dependencies detected in ", nlindep,
528 " functions, rank = ", rank);
534 for(
size_t i = 0; i < n; ++i){
535 for(
size_t j = 0; j < n; ++j){
536 U(i, j) = U(i, j) * s(j);
548 template <
typename T, std::
size_t NDIM>
550 double lindep = 1
e-12){
551 if(
v.empty())
return v;
562 template <
typename T, std::
size_t NDIM>
566 double lindep = 1
e-12) {
567 if(
v.empty())
return v;
569 World& world =
v.front().world();
570 const size_t n =
v.
size();
575 lindep *= s(s.size() - 1);
578 size_t rank = 0, nlindep = 0;
579 for(
size_t i = 0; i < n; ++i) {
580 const auto s_i = s(i);
582 s(i) = 1.0 / sqrt(s_i);
592 if (world.
rank() == 0)
593 print(
"Linear dependencies detected: removed ", nlindep,
594 " functions, rank = ", rank);
595 U = U(
_,
Slice(nlindep, -1));
596 s = s(
Slice(nlindep, -1));
600 for(
size_t i = 0; i < n; ++i){
601 for(
size_t j = 0; j < rank; ++j){
602 U(i, j) = U(i, j) * s(j);
612 template <
typename T, std::
size_t NDIM>
614 double lindep = 1
e-12){
615 if(
v.empty())
return v;
625 template <
typename T, std::
size_t NDIM>
630 if (
v.empty())
return v;
638 World& world=
v.front().world();
646 template <
typename T, std::
size_t NDIM>
648 if(
v.empty())
return v;
650 World& world=
v.front().world();
662 template <
typename T, std::
size_t NDIM>
677 std::vector<Function<T,NDIM> > pv(rank);
687 World& world=
v.front().world();
695 template <
typename T, std::
size_t NDIM>
705 template <
typename T, std::
size_t NDIM>
711 World& world=
v.front().world();
717 template <
typename T, std::
size_t NDIM>
719 std::vector<Function<T,NDIM> >
v=lhs;
720 for (std::size_t i = 0; i < rhs.size(); ++i)
v.push_back(rhs[i]);
724 template <
typename T, std::
size_t NDIM>
726 std::vector<Function<T,NDIM> >result;
727 for(
const auto& x:vv) result=
append(result,x);
731 template<
typename T, std::
size_t NDIM>
733 std::vector<std::shared_ptr<FunctionImpl<T,NDIM>>> result;
734 for (
auto&
f :
v) result.push_back(
f.get_impl());
738 template<
typename T, std::
size_t NDIM>
741 for (std::size_t i=0; i<vimpl.size(); ++i)
v[i].
set_impl(vimpl[i]);
744 template<
typename T, std::
size_t NDIM>
746 std::vector<Function<T,NDIM>>
v(vimpl.size());
747 for (std::size_t i=0; i<vimpl.size(); ++i)
v[i].
set_impl(vimpl[i]);
756 template <
typename T,
typename R, std::
size_t NDIM>
769 std::vector< Function<resultT,NDIM> > vc = zero_functions_compressed<resultT,NDIM>(world,
m);
772 for (
int i=0; i<
m; ++i) {
773 for (
int j=0; j<n; ++j) {
774 if (
c(j,i) !=
R(0.0)) vc[i].gaxpy(resultT(1.0),
v[j],resultT(
c(j,i)),
false);
785 template <
typename T,
typename R, std::
size_t NDIM>
801 vv.get_impl()->get_tree_state()==
reconstructed,
"trees have to be reconstructed in transform_reconstructed");
803 std::vector< Function<resultT,NDIM> > result = zero_functions<resultT,NDIM>(world,
m);
805 for (
int i=0; i<
m; ++i) {
807 for (
int j=0; j<n; ++j) {
808 if (
c(j,i) !=
R(0.0))
v[j].get_impl()->accumulate_trees(*(result[i].
get_impl()),resultT(
c(j,i)),
true);
816 for (
auto& r : result) r.get_impl()->finalize_sum();
824 template <
typename L,
typename R, std::
size_t NDIM>
827 const Tensor<R>&
c,
double tol,
bool fence=
true) {
832 = zero_functions_compressed<TENSOR_RESULT_TYPE(L,R),NDIM>(world,
c.dim(1));
835 vresult[0].vtransform(
v,
c, vresult, tol, fence);
839 template <
typename T,
typename R, std::
size_t NDIM>
855 c.copy_to_replicated(tmp);
858 std::vector< Function<resultT,NDIM> > vc = zero_functions_compressed<resultT,NDIM>(world,
m);
861 for (
int i=0; i<
m; ++i) {
862 for (
int j=0; j<n; ++j) {
863 if (tmp(j,i) !=
R(0.0)) vc[i].gaxpy(1.0,
v[j],tmp(j,i),
false);
873 template <
typename T,
typename Q, std::
size_t NDIM>
876 const std::vector<Q>& factors,
879 for (
unsigned int i=0; i<
v.size(); ++i)
v[i].
scale(factors[i],
false);
884 template <
typename T,
typename Q, std::
size_t NDIM>
890 for (
unsigned int i=0; i<
v.size(); ++i)
v[i].
scale(factor,
false);
908 template <
typename T, std::
size_t NDIM>
910 if (
v.size()==0)
return;
912 return (not f.is_initialized()) or f.get_impl()->has_summable_coefficients();}))
915 [](
const Function<T,NDIM>&
f) {return f.is_initialized() and f.is_on_demand();}),
916 "norm2/norm2s are not defined for an on-demand function; materialize it first");
926 template <
typename T, std::
size_t NDIM>
930 std::vector<double> norms(
v.size());
931 if (
v.size()==0)
return norms;
933 for (
unsigned int i=0; i<
v.size(); ++i) norms[i] =
v[i].norm2sq_local();
934 world.
gop.
sum(&norms[0], norms.size());
935 for (
unsigned int i=0; i<
v.size(); ++i) norms[i] = sqrt(norms[i]);
943 template <
typename T, std::
size_t NDIM>
947 if (
v.size()==0)
return norms;
949 for (
unsigned int i = 0; i <
v.size(); ++i) norms[i] =
v[i].norm2sq_local();
951 for (
unsigned int i = 0; i <
v.size(); ++i) norms[i] = sqrt(norms[i]);
960 template <
typename T, std::
size_t NDIM>
963 if (
v.size()==0)
return 0.0;
965 std::vector<double> norms(
v.size());
966 for (
unsigned int i=0; i<
v.size(); ++i) norms[i] =
v[i].norm2sq_local();
967 world.
gop.
sum(&norms[0], norms.size());
968 for (
unsigned int i=1; i<
v.size(); ++i) norms[0] += norms[i];
970 return sqrt(norms[0]);
1016 template <
typename T, std::
size_t NDIM>
1024 const int64_t n =
A.coldim();
1025 const int64_t
m =
A.rowdim();
1029 const int ichunk = 1000;
1030 const int jchunk = 1000;
1031 for (int64_t ilo=0; ilo<n; ilo+=ichunk) {
1032 int64_t ihi = std::min(ilo + ichunk, n);
1033 std::vector< Function<T,NDIM> > ivec(
f.begin()+ilo,
f.begin()+ihi);
1034 for (int64_t jlo=0; jlo<
m; jlo+=jchunk) {
1035 int64_t jhi = std::min(jlo + jchunk,
m);
1036 std::vector< Function<T,NDIM> > jvec(
g.begin()+jlo,
g.begin()+jhi);
1039 A.copy_from_replicated_patch(ilo, ihi - 1, jlo, jhi - 1,
P);
1050 template <
typename T,
typename R, std::
size_t NDIM>
1057 auto tensor_type = [](
const std::vector<Function<T,NDIM>>&
v) {
1058 return v.front().get_impl()->get_tensor_type();
1064 std::vector<const FunctionImpl<T,NDIM>*> left(
f.size());
1065 std::vector<const FunctionImpl<R,NDIM>*> right(
g.size());
1066 for (
unsigned int i=0; i<
f.size(); i++) left[i] =
f[i].
get_impl().get();
1067 for (
unsigned int i=0; i<
g.size(); i++) right[i]=
g[i].
get_impl().get();
1082 template <
typename T,
typename R, std::
size_t NDIM>
1088 long n=
f.size(),
m=
g.size();
1094 if ((
void*)(&
f) != (
void*)(&
g))
compress(world,
g);
1096 for (
long i=0; i<n; ++i) {
1098 if (sym) jtop = i+1;
1099 for (
long j=0; j<jtop; ++j) {
1100 r(i,j) =
f[i].inner_local(
g[j]);
1101 if (sym) r(j,i) =
conj(r(i,j));
1126 template <
typename T,
typename R, std::
size_t NDIM>
1131 long n=
f.size(),
m=
g.size();
1136 auto tensor_type = [](
const std::vector<Function<T,NDIM>>&
v) {
1137 return v.front().get_impl()->get_tensor_type();
1143 for (
long i=0; i<n; ++i) r(i) =
f[i].inner_local(
g[i]);
1155 template <
typename T,
typename R, std::
size_t NDIM>
1163 auto tensor_type = [](
const std::vector<Function<T,NDIM>>&
v) {
1164 return v.front().get_impl()->get_tensor_type();
1167 f.change_tree_state(operating_state,
false);
1171 for (
long i=0; i<n; ++i) {
1172 r(i) =
f.inner_local(
g[i]);
1183 template <
typename T,
typename R, std::
size_t NDIM>
1187 if(
f.empty())
return 0.0;
1188 else return inner(
f[0].world(),
f,
g).sum();
1193 template <
typename T,
typename R, std::
size_t NDIM>
1201 a.make_redundant(
false);
1225 template <
typename T,
typename R, std::
size_t NDIM>
1232 bool do_make_redundant=
true) {
1234 if (do_make_redundant) {
1239 print(
"could not respect fence in mul_sparse");
1240 a.make_redundant(
false);
1244 }
else if (!
v.empty()) {
1246 "mul_sparse: left input must be redundant when do_make_redundant=false");
1248 "mul_sparse: right inputs must be redundant when do_make_redundant=false");
1272 template <
typename T,
typename R, std::
size_t NDIM>
1279 bool do_make_redundant=
true) {
1281 if (do_make_redundant) {
1286 print(
"could not respect fence in mul_sparse");
1293 for (
unsigned int i=0; i<
a.size(); ++i) {
1314 template <
typename T,
typename R, std::
size_t NDIM>
1321 bool symm =
false) {
1328 std::vector<std::vector<Function<R,NDIM> > >result(
f.size());
1329 std::vector<Function<R,NDIM>> g_i;
1330 for (int64_t i=
f.size()-1; i>=0; --i) {
1332 result[i]=
vmulXX(
f[i],
g, tol,
false);
1334 if (g_i.empty()) g_i =
g;
1336 result[i]=
vmulXX(
f[i], g_i, tol,
false);
1344 template <
typename T, std::
size_t NDIM>
1350 for (
unsigned int i=0; i<
v.size(); ++i) {
1351 v[i].norm_tree(
false);
1357 template <
typename T,
typename R, std::
size_t NDIM>
1363 bool do_make_redundant=
true) {
1365 if (do_make_redundant) {
1370 print(
"could not respect fence in mul");
1377 for (
unsigned int i=0; i<
a.size(); ++i) {
1378 q[i] =
mul(
a[i],
b[i],
false,
false);
1391 template<
typename T, std::
size_t NDIM, std::
size_t LDIM>
1396 std::vector<Function<T,NDIM> > result(
g.size());
1397 for (
auto& r : result) r.set_impl(
f,
false);
1405 for (std::size_t i=0; i<result.size(); ++i) {
1412 for (
auto& ig :
g) ig.get_impl()->undo_redundant(
false);
1417 template<
typename T, std::
size_t NDIM, std::
size_t LDIM>
1419 const std::tuple<int,int,int>
v) {
1420 return partial_mul<T,NDIM,LDIM>(
f,
g,std::array<int,3>({std::get<0>(
v),std::get<1>(
v),std::get<2>(
v)}));
1425 template <
typename T, std::
size_t NDIM>
1426 std::vector< Function<T,NDIM> >
1430 return mul<T,T,NDIM>(world,
v,
v, fence);
1441 template <
typename T, std::
size_t NDIM>
1442 std::vector< Function<typename Tensor<T>::scalar_type,
NDIM> >
1448 std::vector<Function<scalartype,NDIM> > result(
v.size());
1449 for (
size_t i=0; i<
v.size(); ++i) result[i]=
abs_square(
v[i],
false);
1456 template <
typename T, std::
size_t NDIM>
1458 for (
unsigned int j=0; j<
v.size(); ++j) {
1459 v[j].set_thresh(
thresh,
false);
1465 template <
typename T, std::
size_t NDIM>
1466 std::vector< Function<T,NDIM> >
1471 std::vector< Function<T,NDIM> > r =
copy(world,
v);
1472 for (
unsigned int i=0; i<
v.size(); ++i) {
1480 template <
typename T,
typename R, std::
size_t NDIM>
1484 std::vector< Function<R,NDIM> > r(
v.size());
1485 for (
unsigned int i=0; i<
v.size(); ++i) {
1486 r[i] = convert<T,R,NDIM>(
v[i],
false);
1494 template <
typename T, std::
size_t NDIM>
1495 std::vector< Function<T,NDIM> >
1500 std::vector< Function<T,NDIM> > r(
v.size());
1501 for (
unsigned int i=0; i<
v.size(); ++i) {
1502 r[i] =
copy(
v[i],
false);
1510 template <
typename T, std::
size_t NDIM>
1511 std::vector< Function<T,NDIM> >
1514 std::vector< Function<T,NDIM> > r(
v.size());
1515 if (
v.size()>0) r=
copy(
v.front().world(),
v,fence);
1520 template <
typename T, std::
size_t NDIM>
1521 std::vector< Function<T,NDIM> >
1524 const unsigned int n,
1527 std::vector< Function<T,NDIM> > r(n);
1528 for (
unsigned int i=0; i<n; ++i) {
1529 r[i] =
copy(
v,
false);
1544 template <
typename T, std::
size_t NDIM>
1548 bool fence =
true) {
1550 std::vector<Function<T, NDIM>> r(
v.size());
1551 for (
unsigned int i = 0; i <
v.size(); ++i) {
1552 r[i] =
copy(
v[i], pmap,
false);
1561 std::vector<ProcessID> owner(
nfunc);
1562 for (std::size_t j = 0; j <
nfunc; ++j) owner[j] =
ProcessID(j % std::size_t(nranks));
1572 const std::size_t
nfunc = cost.size();
1573 std::vector<ProcessID> owner(
nfunc);
1574 std::vector<std::size_t> order(
nfunc);
1575 for (std::size_t j = 0; j <
nfunc; ++j) order[j] = j;
1577 std::stable_sort(order.begin(), order.end(),
1578 [&](std::size_t
a, std::size_t
b) { return cost[a] > cost[b]; });
1579 std::vector<double>
load(std::size_t(nranks), 0.0);
1580 for (std::size_t
k = 0;
k <
nfunc; ++
k) {
1582 for (
int r = 1; r < nranks; ++r)
1583 if (
load[std::size_t(r)] <
load[std::size_t(best)]) best = r;
1584 const std::size_t j = order[
k];
1586 load[std::size_t(best)] += std::max(1.0, cost[j]);
1594 template <
typename T, std::
size_t NDIM>
1596 std::vector<double> cost(
v.size(), 0.0);
1597 for (std::size_t j = 0; j <
v.size(); ++j) cost[j] =
double(
v[j].size_local());
1598 if (!
v.empty()) world.
gop.
sum(cost.data(), cost.size());
1614 template <
typename T, std::
size_t NDIM>
1617 const std::vector<ProcessID>& owner,
1618 std::size_t cap_bytes = 0,
1619 bool rotate =
true) {
1621 if (
v.empty())
return;
1626 for (std::size_t j = 0; j < owner.size(); ++j)
h +=
long(owner[j]) * long(j + 1);
1627 long hmax =
h, hmin =
h;
1635 if (cap_bytes == 0) cap_bytes = 1024 * 1024;
1637 for (
const auto&
f :
v)
kmax = std::max(
kmax,
long(
f.k()));
1638 std::size_t box_bytes =
sizeof(T);
1639 for (std::size_t
d = 0;
d <
NDIM; ++
d) box_bytes *= std::size_t(2 *
kmax);
1640 const std::size_t cap_boxes = std::max<std::size_t>(1, cap_bytes / box_bytes);
1645 for (std::size_t j = 0; j <
v.size(); ++j) {
1646 auto pmap = std::shared_ptr<WorldDCPmapInterface<Key<NDIM>>>(
1648 v[j].get_impl()->get_coeffs().redistribute_coalesced_phase1(pmap);
1651 for (std::size_t j = 0; j <
v.size(); ++j)
1652 v[j].
get_impl()->get_coeffs().redistribute_coalesced_phase2(cap_boxes, rotate);
1657 template <
typename T,
typename R, std::
size_t NDIM>
1669 for (
unsigned int i=0; i<
a.size(); ++i) {
1670 r[i] =
add(
a[i],
b[i],
false);
1677 template <
typename T,
typename R, std::
size_t NDIM>
1688 for (
unsigned int i=0; i<
b.size(); ++i) {
1689 r[i] =
add(
a,
b[i],
false);
1694 template <
typename T,
typename R, std::
size_t NDIM>
1700 return add(world,
a,
b, fence);
1704 template <
typename T,
typename R, std::
size_t NDIM>
1716 for (
unsigned int i=0; i<
a.size(); ++i) {
1717 r[i] =
sub(
a[i],
b[i],
false);
1724 template <
typename T, std::
size_t NDIM>
1731 for (
unsigned int i=0; i<
f.size(); ++i) r.
gaxpy(1.0,
f[i],1.0,
false);
1736 template <
typename T, std::
size_t NDIM>
1744 const int64_t n =
A.coldim();
1745 const int64_t
m =
A.rowdim();
1749 const int ichunk = 1000;
1750 const int jchunk = 1000;
1751 for (int64_t ilo = 0; ilo < n; ilo += ichunk) {
1752 int64_t ihi = std::min(ilo + ichunk, n);
1753 std::vector<Function<T, NDIM>> ivec(
f.begin() + ilo,
f.begin() + ihi);
1754 for (int64_t jlo = 0; jlo <
m; jlo += jchunk) {
1755 int64_t jhi = std::min(jlo + jchunk,
m);
1756 std::vector<Function<T, NDIM>> jvec(
g.begin() + jlo,
g.begin() + jhi);
1759 A.copy_from_replicated_patch(ilo, ihi - 1, jlo, jhi - 1,
P);
1770 template <
typename T,
typename R, std::
size_t NDIM>
1781 std::vector<const FunctionImpl<T, NDIM>*> left(
f.size());
1782 std::vector<const FunctionImpl<R, NDIM>*> right(
g.size());
1783 for (
unsigned int i = 0; i <
f.size(); i++) left[i] =
f[i].
get_impl().get();
1784 for (
unsigned int i = 0; i <
g.size(); i++) right[i] =
g[i].
get_impl().get();
1799 template <
typename T,
typename R, std::
size_t NDIM>
1805 long n=
f.size(),
m=
g.size();
1811 if ((
void*)(&
f) != (
void*)(&
g))
compress(world,
g);
1813 for (
long i=0; i<n; ++i) {
1815 if (sym) jtop = i+1;
1816 for (
long j=0; j<jtop; ++j) {
1818 r(j,i) =
f[i].dot_local(
g[j]);
1820 r(i,j) =
conj(r(j,i));
1822 r(i,j) =
f[i].dot_local(
g[j]);
1833 template <
typename T,
typename R, std::
size_t NDIM>
1840 bool do_make_redundant=
true) {
1842 return sum(world,
mul_sparse(world,
a,
b,tol,
true,do_make_redundant),fence);
1846 template <
typename T,
typename R, std::
size_t NDIM>
1852 bool do_make_redundant=
true) {
1854 return sum(world,
mul(world,
a,
b,
true,do_make_redundant),fence);
1858 template <
typename T,
typename Q,
typename R, std::
size_t NDIM>
1868 if (
a.size()==0)
return std::vector<Function<resultT,NDIM> >();
1870 auto tensor_type = [](
const std::vector<Function<T,NDIM>>&
v) {
1871 return v.front().get_impl()->get_tensor_type();
1875 World& world=
a[0].world();
1876 std::vector<Function<resultT,NDIM> > result(
a.size());
1883 print(
"could not respect fence in gaxpy");
1900 template <
typename T,
typename Q,
typename R, std::
size_t NDIM>
1909 if (
a.size()==0)
return std::vector<Function<resultT,NDIM> >();
1911 World& world=
a[0].world();
1917 print(
"could not respect fence in gaxpy_oop");
1921 std::vector<Function<resultT,NDIM> > result(
a.size());
1922 for (
unsigned int i=0; i<
a.size(); ++i) {
1925 if (fence) world.gop.fence();
1931 template <
typename T,
typename Q,
typename R, std::
size_t NDIM>
1933 if (
a.size() == 0)
return;
1934 World& world=
a.front().world();
1939 template <
typename T,
typename Q,
typename R, std::
size_t NDIM>
1948 if (
a.empty())
return;
1950 auto tensor_type = [](
const std::vector<Function<T,NDIM>>&
v) {
1951 return v.front().get_impl()->get_tensor_type();
1955 bool do_in_reconstructed_state=tensor_type(
a)!=
TT_FULL;
1964 print(
"could not respect fence in gaxpy");
1978 print(
"could not respect fence in gaxpy for a");
1986 print(
"could not respect fence in gaxpy for b");
1993 for (
unsigned int i=0; i<
a.size(); ++i) {
1997 for (
unsigned int i=0; i<
a.size(); ++i)
a[i].
get_impl()->finalize_sum();
2005 template <
typename opT,
typename R, std::
size_t NDIM>
2008 const std::vector< std::shared_ptr<opT> >&
op,
2014 std::vector< Function<R,NDIM> >&
ncf = *
const_cast< std::vector< Function<R,NDIM>
>* >(&
f);
2020 for (
unsigned int i=0; i<
f.size(); ++i) {
2036 template <
typename T,
typename R, std::
size_t NDIM, std::
size_t KDIM>
2045 template <
typename T,
typename R, std::
size_t NDIM, std::
size_t KDIM>
2052 std::vector< Function<R,NDIM> >&
ncf = *
const_cast< std::vector< Function<R,NDIM>
>* >(&
f);
2059 if (
print_timings) printf(
"timer: %20.20s %8.2fs\n",
"make_nonstandard", wall1-wall0);
2062 for (
unsigned int i=0; i<
f.size(); ++i) {
2069 if (
op.destructive()) {
2070 for (
auto& ff :
ncf) ff.clear(
false);
2078 for (
auto& r : result) r.get_impl()->finalize_apply();
2082 for (
auto& r : result) r.get_impl()->print_timer();
2091 template <
typename T, std::
size_t NDIM>
2094 std::vector<double> nn =
norm2s(world,
v);
2095 for (
unsigned int i=0; i<
v.size(); ++i)
v[i].
scale(1.0/nn[i],
false);
2099 template <
typename T, std::
size_t NDIM>
2102 if(world.
rank()==0) std::cout <<
"print_size: " << msg <<
" is empty" << std::endl;
2103 }
else if(
v.size()==1){
2104 v.front().print_size(msg);
2114 template <
typename T, std::
size_t NDIM>
2118 if (x.is_initialized()) size+=x.size_local();
2120 const double d=
sizeof(T);
2121 const double fac=1024*1024*1024;
2126 template <
typename T, std::
size_t NDIM>
2133 template <
typename T, std::
size_t NDIM>
2136 if (
v.empty())
return 0.0;
2138 const double d=
sizeof(T);
2139 const double fac=1024*1024*1024;
2142 for(
unsigned int i=0;i<
v.size();i++){
2143 if (
v[i].is_initialized()) size+=
v[i].size();
2151 template <
typename T, std::
size_t NDIM>
2153 const double d=
sizeof(T);
2154 const double fac=1024*1024*1024;
2155 double size=
f.size();
2164 template <
typename T,
typename opT, std::
size_t NDIM>
2167 const bool fence=
true) {
2170 World& world=vin[0].world();
2173 std::vector<Function<T,NDIM> > vout=zero_functions<T,NDIM>(world,
op.get_result_size());
2174 for (
auto& out : vout) out.set_impl(vin[0],
false);
2185 template <
typename T, std::
size_t NDIM>
2193 template <
typename T, std::
size_t NDIM>
2201 template <
typename T, std::
size_t NDIM>
2209 template <
typename T, std::
size_t NDIM>
2217 template <
typename T, std::
size_t NDIM>
2225 template <
typename T, std::
size_t NDIM>
2233 template <
typename T,
typename R, std::
size_t NDIM>
2237 std::vector<Function<T,NDIM> > tmp=
copy(rhs[0].world(),rhs);
2244 template <
typename T,
typename R, std::
size_t NDIM>
2256 template <
typename T,
typename R, std::
size_t NDIM>
2259 if (
v.size()>0)
return mul(
v[0].world(),
a,
v,
true);
2265 template <
typename T,
typename R, std::
size_t NDIM>
2268 if (
v.size()>0)
return mul(
v[0].world(),
a,
v,
true);
2273 template <
typename T, std::
size_t NDIM>
2276 if (lhs.size() > 0)
gaxpy(lhs.front().world(), 1.0, lhs, 1.0, rhs);
2280 template <
typename T, std::
size_t NDIM>
2284 if (lhs.size() > 0)
gaxpy(lhs.front().world(), 1.0, lhs, -1.0, rhs);
2289 template <
typename T, std::
size_t NDIM>
2290 std::vector<Function<typename Tensor<T>::scalar_type,
NDIM> >
2292 std::vector<Function<typename Tensor<T>::scalar_type,
NDIM> > result(
v.size());
2293 for (std::size_t i=0; i<
v.size(); ++i) result[i]=
real(
v[i],
false);
2294 if (fence and result.size()>0) result[0].world().gop.fence();
2299 template <
typename T, std::
size_t NDIM>
2300 std::vector<Function<typename Tensor<T>::scalar_type,
NDIM> >
2302 std::vector<Function<typename Tensor<T>::scalar_type,
NDIM> > result(
v.size());
2303 for (std::size_t i=0; i<
v.size(); ++i) result[i]=
imag(
v[i],
false);
2304 if (fence and result.size()>0) result[0].world().gop.fence();
2315 template <
typename T, std::
size_t NDIM>
2317 bool refine=
false,
bool fence=
true) {
2323 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2324 gradient_operator<T,NDIM>(world);
2326 std::vector<Function<T,NDIM> > result(
NDIM);
2327 for (
size_t i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
f,
false);
2333 template <
typename T, std::
size_t NDIM>
2335 bool refine=
false,
bool fence=
true) {
2341 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2342 gradient_operator<T,NDIM>(world);
2345 for (
unsigned int i=0; i<
NDIM; ++i) (*
grad[i]).set_ble1();
2347 std::vector<Function<T,NDIM> > result(
NDIM);
2348 for (
unsigned int i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
f,
false);
2354 template <
typename T, std::
size_t NDIM>
2356 bool refine=
false,
bool fence=
true) {
2362 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2363 gradient_operator<T,NDIM>(world);
2366 for (
unsigned int i=0; i<
NDIM; ++i) (*
grad[i]).set_ble2();
2368 std::vector<Function<T,NDIM> > result(
NDIM);
2369 for (
unsigned int i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
f,
false);
2375 template <
typename T, std::
size_t NDIM>
2377 bool refine=
false,
bool fence=
true) {
2383 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2384 gradient_operator<T,NDIM>(world);
2387 for (
unsigned int i=0; i<
NDIM; ++i) (*
grad[i]).set_bspline1();
2389 std::vector<Function<T,NDIM> > result(
NDIM);
2390 for (
unsigned int i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
f,
false);
2396 template <
typename T, std::
size_t NDIM>
2398 bool refine=
false,
bool fence=
true) {
2404 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2405 gradient_operator<T,NDIM>(world);
2408 for (
unsigned int i=0; i<
NDIM; ++i) (*
grad[i]).set_bspline2();
2410 std::vector<Function<T,NDIM> > result(
NDIM);
2411 for (
unsigned int i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
f,
false);
2417 template <
typename T, std::
size_t NDIM>
2419 bool refine=
false,
bool fence=
true) {
2425 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2426 gradient_operator<T,NDIM>(world);
2429 for (
unsigned int i=0; i<
NDIM; ++i) (*
grad[i]).set_bspline3();
2431 std::vector<Function<T,NDIM> > result(
NDIM);
2432 for (
unsigned int i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
f,
false);
2455 template <
typename T, std::
size_t NDIM>
2457 const DerivMethod method,
bool do_refine=
false,
bool fence=
true) {
2460 World& world=
v[0].world();
2462 if (do_refine)
refine(world,
v);
2464 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2465 gradient_operator<T,NDIM>(world);
2469 for (
unsigned int i=0; i<
NDIM; ++i) (*
grad[i]).set_bspline1();
2471 for (
unsigned int i=0; i<
NDIM; ++i) (*
grad[i]).set_ble1();
2473 std::vector<Function<T,NDIM> > result(
NDIM);
2474 for (
size_t i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
v[i],
false);
2476 return sum(world,result,fence);
2480 template <
typename T, std::
size_t NDIM>
2482 bool do_refine=
false,
bool fence=
true) {
2487 template <
typename T, std::
size_t NDIM>
2489 bool do_refine=
false,
bool fence=
true) {
2494 template <
typename T, std::
size_t NDIM>
2496 bool do_refine=
false,
bool fence=
true) {
2501 template <
typename T, std::
size_t NDIM>
2503 bool do_refine=
false,
bool fence=
true) {
2515 template <
typename T, std::
size_t NDIM>
2517 bool do_refine=
false,
bool fence=
true) {
2520 World& world=
v[0].world();
2522 if (do_refine)
refine(world,
v);
2524 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2525 gradient_operator<T,NDIM>(world);
2527 std::vector<Function<T,NDIM> >
d(
NDIM),dd(
NDIM);
2539 d[0].gaxpy(1.0,dd[0],-1.0,
false);
2540 d[1].gaxpy(1.0,dd[1],-1.0,
false);
2541 d[2].gaxpy(1.0,dd[2],-1.0,
false);
2556 template <
typename T,
typename R, std::
size_t NDIM>
2559 bool do_refine=
false,
bool fence=
true) {
2563 World& world=
f[0].world();
2569 d[0]=
mul(
f[1],
g[2],
false);
2570 d[1]=
mul(
f[2],
g[0],
false);
2571 d[2]=
mul(
f[0],
g[1],
false);
2573 dd[0]=
mul(
f[2],
g[1],
false);
2574 dd[1]=
mul(
f[0],
g[2],
false);
2575 dd[2]=
mul(
f[1],
g[0],
false);
2582 d[0].gaxpy(1.0,dd[0],-1.0,
false);
2583 d[1].gaxpy(1.0,dd[1],-1.0,
false);
2584 d[2].gaxpy(1.0,dd[2],-1.0,
false);
2591 template<
typename T, std::
size_t NDIM>
2608 template<
typename T,
size_t NDIM>
2610 const std::string
name) {
2611 if (world.
rank()==0)
print(
"loading vector of functions",
name);
2613 std::size_t fsize=0;
2616 for (std::size_t i=0; i<fsize; ++i) ar &
f[i];
2620 template<
typename T,
size_t NDIM>
2623 World& world=
f.front().world();
2624 if (world.
rank()==0)
print(
"saving vector of functions",
name);
2626 std::size_t fsize=
f.size();
2628 for (std::size_t i=0; i<fsize; ++i) ar &
f[i];
double q(double t)
Definition DKops.h:18
Definition test_ar.cc:118
long size() const
Returns the number of elements in the tensor.
Definition basetensor.h:138
Implements derivatives operators with variety of boundary conditions on simulation domain.
Definition derivative.h:337
Definition distributed_matrix.h:68
Manages data associated with a row/column/block distributed array.
Definition distributed_matrix.h:388
static void redistribute(World &world, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &newpmap)
Sets the default process map and redistributes all functions using the old map.
Definition funcdefaults.h:458
static TensorType get_tensor_type()
Returns the default tensor type.
Definition funcdefaults.h:329
FunctionFactory implements the named-parameter idiom for Function.
Definition function_factory.h:86
FunctionFactory & compressed(bool value=true)
Definition function_factory.h:168
FunctionImpl holds all Function state to facilitate shallow copy semantics.
Definition funcimpl.h:970
static Tensor< TENSOR_RESULT_TYPE(T, R) > inner_local(const std::vector< const FunctionImpl< T, NDIM > * > &left, const std::vector< const FunctionImpl< R, NDIM > * > &right, bool sym)
Definition funcimpl.h:6278
void undo_redundant(const bool fence)
convert this from redundant to standard reconstructed form
Definition mraimpl.h:1579
void multiply(const implT *f, const FunctionImpl< T, LDIM > *g, const int particle)
multiply f (a pair function of NDIM) with an orbital g (LDIM=NDIM/2)
Definition funcimpl.h:3819
void change_tree_state(const TreeState finalstate, bool fence=true)
change the tree state of this function, might or might not respect fence!
Definition mraimpl.h:1441
static Tensor< TENSOR_RESULT_TYPE(T, R)> dot_local(const std::vector< const FunctionImpl< T, NDIM > * > &left, const std::vector< const FunctionImpl< R, NDIM > * > &right, bool sym)
Definition funcimpl.h:6330
FunctionNode holds the coefficients, etc., at each node of the 2^NDIM-tree.
Definition funcimpl.h:136
coeffT & coeff()
Returns a non-const reference to the tensor containing the coeffs.
Definition funcimpl.h:237
A multiresolution adaptive numerical function.
Definition mra.h:144
World & world() const
Returns the world.
Definition mra.h:758
Function< T, NDIM > & gaxpy(const T &alpha, const Function< Q, NDIM > &other, const R &beta, bool fence=true)
Inplace, general bi-linear operation in wavelet basis. No communication except for optional fence.
Definition mra.h:1156
void set_impl(const std::shared_ptr< FunctionImpl< T, NDIM > > &impl)
Replace current FunctionImpl with provided new one.
Definition mra.h:731
void multi_to_multi_op_values(const opT &op, const std::vector< Function< T, NDIM > > &vin, std::vector< Function< T, NDIM > > &vout, const bool fence=true)
apply op on the input vector yielding an output vector of functions
Definition mra.h:1749
bool is_initialized() const
Returns true if the function is initialized.
Definition mra.h:172
long size() const
Definition lowranktensor.h:488
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:70
std::shared_ptr< WorldDCPmapInterface< keyT > > load_balance(double fac=1.0, bool printstuff=false)
Actually does the partitioning of the tree.
Definition lbdeux.h:390
void add_tree(const Function< T, NDIM > &f, const costT &costfn, bool fence=false)
Accumulates cost from a function.
Definition lbdeux.h:294
Definition operator.h:156
A slice defines a sub-range or patch of a dimension.
Definition slice.h:103
A tensor is a multidimensional array.
Definition tensor.h:318
TensorTypeData< T >::scalar_type scalar_type
C++ typename of the real type associated with a complex type.
Definition tensor.h:410
T * ptr()
Returns a pointer to the internal data.
Definition tensor.h:1841
A simple, fixed dimension vector.
Definition vector.h:64
Interface to be provided by any process map.
Definition worlddc.h:125
void max(T *buf, size_t nelem)
Inplace global max while still processing AM & tasks.
Definition worldgop.h:902
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:177
void min(T *buf, size_t nelem)
Inplace global min while still processing AM & tasks.
Definition worldgop.h:896
void sum(T *buf, size_t nelem)
Inplace global sum while still processing AM & tasks.
Definition worldgop.h:890
void fence()
Returns after all local tasks have completed.
Definition world_task_queue.h:1384
A parallel world class.
Definition world.h:134
WorldTaskQueue & taskq
Task queue.
Definition world.h:215
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition world.h:344
ProcessID size() const
Returns the number of processes in this World (same as MPI_Comm_size()).
Definition world.h:354
WorldGopInterface & gop
Global operations.
Definition world.h:216
An archive for storing local or parallel data wrapping a BinaryFstreamOutputArchive.
Definition parallel_archive.h:321
int integer
Definition crayio.c:25
static const double R
Definition csqrt.cc:46
Declaration and initialization of tree traversal functions and generic derivative.
Tensor< T > conj_transpose(const Tensor< T > &t)
Returns a new deep copy of the complex conjugate transpose of the input tensor.
Definition tensor.h:2044
Tensor< T > transpose(const Tensor< T > &t)
Returns a new deep copy of the transpose of the input tensor.
Definition tensor.h:2035
const double beta
Definition gygi_soltion.cc:62
static const double v
Definition hatom_sf_dirac.cc:20
Tensor< double > op(const Tensor< double > &x)
Definition kain.cc:508
#define rot(x, k)
Definition lookup3.c:84
#define MADNESS_CHECK(condition)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:182
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
#define MADNESS_CHECK_THROW(condition, msg)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:207
Main include file for MADNESS and defines Function interface.
static const bool VERIFY_TREE
Definition mra.h:57
Definition potentialmanager.cc:41
void reconstruct_for_norm(World &world, const std::vector< Function< T, NDIM > > &v)
put a vector of functions into a state whose coefficients sum to ||f||^2
Definition vmra.h:909
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
void save_function(const std::vector< Function< T, NDIM > > &f, const std::string name)
save a vector of functions
Definition vmra.h:2621
bool ensure_tree_state_respecting_fence(const std::vector< Function< T, NDIM > > &v, const TreeState state, bool fence)
ensure v has the requested tree state, change the tree state of v if necessary and no fence is given
Definition vmra.h:317
void rr_cholesky(Tensor< T > &A, typename Tensor< T >::scalar_type tol, Tensor< integer > &piv, int &rank)
Compute the rank-revealing Cholesky factorization.
Definition lapack.cc:1203
void make_redundant(World &world, const std::vector< Function< T, NDIM > > &v, bool fence=true)
change tree_state of a vector of functions to redundant
Definition vmra.h:187
std::vector< Function< T, NDIM > > orthonormalize_rrcd(const std::vector< Function< T, NDIM > > &v, Tensor< T > &ovlp, const double tol, Tensor< integer > &piv, int &rank)
Definition vmra.h:663
Function< double, NDIM > abssq(const Function< double_complex, NDIM > &z, bool fence=true)
Returns a new function that is the square of the absolute value of the input.
Definition mra.h:2965
Function< TENSOR_RESULT_TYPE(L, R), NDIM > gaxpy_oop(TENSOR_RESULT_TYPE(L, R) alpha, const Function< L, NDIM > &left, TENSOR_RESULT_TYPE(L, R) beta, const Function< R, NDIM > &right, bool fence=true)
Returns new function alpha*left + beta*right optional fence and no automatic compression.
Definition mra.h:2147
Function< typename TensorTypeData< Q >::scalar_type, NDIM > abs_square(const Function< Q, NDIM > &func)
Definition complexfun.h:121
std::vector< double > function_costs(World &world, const std::vector< Function< T, NDIM > > &v)
Definition vmra.h:1595
Function< T, NDIM > square(const Function< T, NDIM > &f, bool fence=true)
Create a new function that is the square of f - global comm only if not reconstructed.
Definition mra.h:2933
Function< TENSOR_RESULT_TYPE(L, R), NDIM > sub(const Function< L, NDIM > &left, const Function< R, NDIM > &right, bool fence=true)
Same as operator- but with optional fence and no automatic compression.
Definition mra.h:2202
std::vector< ProcessID > assign_round_robin(std::size_t nfunc, int nranks)
owner[j] = j % nranks. For redistribute_to_batches.
Definition vmra.h:1559
std::vector< Function< T, NDIM > > reduce_rank(std::vector< Function< T, NDIM > > v, double thresh=0.0, bool fence=true)
reduces the tensor rank of the coefficient tensor (if applicable)
Definition vmra.h:367
Tensor< double > norm2s_T(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norms of a vector of functions.
Definition vmra.h:944
std::vector< double > norm2s(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norms of a vector of functions.
Definition vmra.h:927
Function< TENSOR_RESULT_TYPE(T, R), NDIM > dot_sparse(World &world, const std::vector< Function< T, NDIM > > &a, const std::vector< Function< R, NDIM > > &b, double tol, bool fence=true, bool do_make_redundant=true)
Multiplies and sums two vectors of functions r = \sum_i a[i] * b[i].
Definition vmra.h:1835
Function< T, NDIM > div_abgv(const std::vector< Function< T, NDIM > > &v, bool do_refine=false, bool fence=true)
div with the ABGV derivative
Definition vmra.h:2481
std::vector< Function< T, NDIM > > grad_bspline_one(const Function< T, NDIM > &f, bool refine=false, bool fence=true)
Definition vmra.h:2376
void set_impl(std::vector< Function< T, NDIM > > &v, const std::vector< std::shared_ptr< FunctionImpl< T, NDIM > > > vimpl)
Definition vmra.h:739
Function< Q, NDIM > convert(const Function< T, NDIM > &f, bool fence=true)
Type conversion implies a deep copy. No communication except for optional fence.
Definition mra.h:2280
Function< TENSOR_RESULT_TYPE(Q, T), NDIM > mul(const Q alpha, const Function< T, NDIM > &f, bool fence=true)
Returns new function equal to alpha*f(x) with optional fence.
Definition mra.h:1932
Function< TENSOR_RESULT_TYPE(T, R), NDIM > dot(World &world, const std::vector< Function< T, NDIM > > &a, const std::vector< Function< R, NDIM > > &b, bool fence=true, bool do_make_redundant=true)
Multiplies and sums two vectors of functions r = \sum_i a[i] * b[i]; see dot_sparse for screening.
Definition vmra.h:1848
std::vector< Function< T, NDIM > > orthonormalize_symmetric(const std::vector< Function< T, NDIM > > &v, const Tensor< T > &ovlp, double lindep=1e-12)
symmetric orthonormalization (see e.g. Szabo/Ostlund)
Definition vmra.h:501
std::vector< std::shared_ptr< FunctionImpl< T, NDIM > > > get_impl(const std::vector< Function< T, NDIM > > &v)
Definition vmra.h:732
Function< T, NDIM > div(const std::vector< Function< T, NDIM > > &v, bool do_refine=false, bool fence=true)
shorthand div operator, with the default (ABGV) derivative
Definition vmra.h:2502
std::vector< Function< T, NDIM > > orthonormalize_cd(const std::vector< Function< T, NDIM > > &v, Tensor< T > &ovlp)
Definition vmra.h:626
std::vector< Function< T, NDIM > > copy_n(World &world, const Function< T, NDIM > &v, const unsigned int n, bool fence=true)
Returns a vector of n deep copies of a function.
Definition vmra.h:1522
void norm_tree(World &world, const std::vector< Function< T, NDIM > > &v, bool fence=true)
Makes the norm tree for all functions in a vector.
Definition vmra.h:1345
tensorT Q2(const tensorT &s)
Given overlap matrix, return rotation with 2nd order error to orthonormalize the vectors.
Definition SCF.cc:139
std::vector< Function< TENSOR_RESULT_TYPE(T, R), NDIM > > transform(World &world, const std::vector< Function< T, NDIM > > &v, const Tensor< R > &c, bool fence=true)
Transforms a vector of functions according to new[i] = sum[j] old[j]*c[j,i].
Definition vmra.h:758
std::vector< Function< TENSOR_RESULT_TYPE(T, R), NDIM > > cross(const std::vector< Function< T, NDIM > > &f, const std::vector< Function< R, NDIM > > &g, bool do_refine=false, bool fence=true)
shorthand cross operator
Definition vmra.h:2557
TreeState
Definition funcdefaults.h:60
@ nonstandard_after_apply
s and d coeffs, state after operator application
Definition funcdefaults.h:65
@ redundant_after_merge
s coeffs everywhere, must be summed up to yield the result
Definition funcdefaults.h:67
@ reconstructed
s coeffs at the leaves only
Definition funcdefaults.h:61
@ nonstandard
s and d coeffs in internal nodes
Definition funcdefaults.h:63
@ unknown
Definition funcdefaults.h:69
@ compressed
d coeffs in internal nodes, s and d coeffs at the root, empty leaves may be present
Definition funcdefaults.h:62
@ redundant
s coeffs everywhere
Definition funcdefaults.h:66
@ nonstandard_with_leaves
like nonstandard, with s coeffs at the leaves
Definition funcdefaults.h:64
Function< T, NDIM > conj(const Function< T, NDIM > &f, bool fence=true)
Return the complex conjugate of the input function with the same distribution and optional fence.
Definition mra.h:2294
void cholesky(Tensor< T > &A)
Compute the Cholesky factorization.
Definition lapack.cc:1174
std::vector< std::vector< Function< TENSOR_RESULT_TYPE(T, R), NDIM > > > matrix_mul_sparse(World &world, const std::vector< Function< R, NDIM > > &f, const std::vector< Function< R, NDIM > > &g, double tol, bool fence=true, bool symm=false)
Outer product of a vector of functions with a vector of functions using sparsity.
Definition vmra.h:1316
Function< T, NDIM > div_bspline(const std::vector< Function< T, NDIM > > &v, bool do_refine=false, bool fence=true)
div with the b-spline smoothing first derivative
Definition vmra.h:2488
void standard(World &world, std::vector< Function< T, NDIM > > &v, bool fence=true)
Generates standard form of a vector of functions.
Definition vmra.h:244
void truncate(World &world, std::vector< Function< T, NDIM > > &v, double tol=0.0, bool fence=true)
Truncates a vector of functions.
Definition vmra.h:336
void compress(World &world, const std::vector< Function< T, NDIM > > &v, bool fence=true)
Compress a vector of functions.
Definition vmra.h:150
const std::vector< Function< T, NDIM > > & reconstruct(const std::vector< Function< T, NDIM > > &v)
reconstruct a vector of functions
Definition vmra.h:163
std::vector< Function< T, NDIM > > impl2function(const std::vector< std::shared_ptr< FunctionImpl< T, NDIM > > > vimpl)
Definition vmra.h:745
std::vector< Function< T, NDIM > > grad_bpsline_two(const Function< T, NDIM > &f, bool refine=false, bool fence=true)
Definition vmra.h:2397
void set_thresh(World &world, std::vector< Function< T, NDIM > > &v, double thresh, bool fence=true)
Sets the threshold in a vector of functions.
Definition vmra.h:1457
double norm2(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norm of a vector of functions.
Definition vmra.h:961
Function< T, NDIM > div_ble(const std::vector< Function< T, NDIM > > &v, bool do_refine=false, bool fence=true)
div with the BLE smoothing first derivative
Definition vmra.h:2495
std::vector< ProcessID > assign_cost_aware(const std::vector< double > &cost, int nranks)
Definition vmra.h:1570
std::vector< Function< T, NDIM > > flatten(const std::vector< std::vector< Function< T, NDIM > > > &vv)
Definition vmra.h:725
std::vector< CCPairFunction< T, NDIM > > operator*(const double fac, const std::vector< CCPairFunction< T, NDIM > > &arg)
Definition ccpairfunction.h:1089
static void verify_tree(World &world, const std::vector< Function< T, NDIM > > &v)
Definition SCF.cc:76
std::vector< Function< T, NDIM > > multi_to_multi_op_values(const opT &op, const std::vector< Function< T, NDIM > > &vin, const bool fence=true)
apply op on the input vector yielding an output vector of functions
Definition vmra.h:2165
static const Slice _(0,-1, 1)
Tensor< T > inverse(const Tensor< T > &a_in)
invert general square matrix A
Definition lapack.cc:832
void load_balance(const real_function_6d &f, const bool leaf)
do some load-balancing
Definition madness/chem/mp2.cc:70
TreeState get_tree_state(const Function< T, NDIM > &f)
get tree state of a function
Definition mra.h:2981
std::vector< CCPairFunction< T, NDIM > > operator-(const std::vector< CCPairFunction< T, NDIM > > c1, const std::vector< CCPairFunction< T, NDIM > > &c2)
Definition ccpairfunction.h:1060
std::vector< Function< T, NDIM > > partial_mul(const Function< T, NDIM > f, const std::vector< Function< T, LDIM > > g, const int particle)
multiply a high-dimensional function with a low-dimensional function
Definition vmra.h:1392
Function< T, NDIM > gaxpy_oop_reconstructed(const double alpha, const Function< T, NDIM > &left, const double beta, const Function< T, NDIM > &right, const bool fence=true)
Returns new function alpha*left + beta*right optional fence, having both addends reconstructed.
Definition mra.h:2165
std::vector< Function< TENSOR_RESULT_TYPE(T, R), NDIM > > transform_reconstructed(World &world, const std::vector< Function< T, NDIM > > &v, const Tensor< R > &c, bool fence=true)
Transforms a vector of functions according to new[i] = sum[j] old[j]*c[j,i].
Definition vmra.h:787
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:227
std::vector< Function< T, NDIM > > append(const std::vector< Function< T, NDIM > > &lhs, const std::vector< Function< T, NDIM > > &rhs)
combine two vectors
Definition vmra.h:718
void redistribute_to_batches(World &world, std::vector< Function< T, NDIM > > &v, const std::vector< ProcessID > &owner, std::size_t cap_bytes=0, bool rotate=true)
Definition vmra.h:1615
@ TT_2D
Definition gentensor.h:120
@ TT_FULL
Definition gentensor.h:120
void refine(World &world, const std::vector< Function< T, NDIM > > &vf, bool fence=true)
refine the functions according to the autorefine criteria
Definition vmra.h:197
Function< T, NDIM > div_deriv(const std::vector< Function< T, NDIM > > &v, const DerivMethod method, bool do_refine=false, bool fence=true)
shorthand div operator, with a choice of first derivative
Definition vmra.h:2456
void print_size(World &world, const std::vector< Function< T, NDIM > > &v, const std::string &msg="vectorfunction")
Definition vmra.h:2100
NDIM & f
Definition mra.h:2668
Function< TENSOR_RESULT_TYPE(L, R), NDIM > add(const Function< L, NDIM > &left, const Function< R, NDIM > &right, bool fence=true)
Same as operator+ but with optional fence and no automatic compression.
Definition mra.h:2157
const Function< T, NDIM > & change_tree_state(const Function< T, NDIM > &f, const TreeState finalstate, bool fence=true)
change tree state of a function
Definition mra.h:2994
std::vector< CCPairFunction< T, NDIM > > & operator-=(std::vector< CCPairFunction< T, NDIM > > &rhs, const std::vector< CCPairFunction< T, NDIM > > &lhs)
Definition ccpairfunction.h:1082
std::vector< Function< T, NDIM > > orthonormalize(const std::vector< Function< T, NDIM > > &vf_in)
orthonormalize the vectors
Definition vmra.h:466
NDIM const Function< R, NDIM > & g
Definition mra.h:2668
double wall_time()
Returns the wall time in seconds relative to an arbitrary origin.
Definition timers.cc:48
std::vector< Function< T, NDIM > > grad_ble_one(const Function< T, NDIM > &f, bool refine=false, bool fence=true)
Definition vmra.h:2334
Function< TENSOR_RESULT_TYPE(typename opT::opT, R), NDIM > apply_only(const opT &op, const Function< R, NDIM > &f, bool fence=true)
Apply operator ONLY in non-standard form - required other steps missing !!
Definition mra.h:2368
std::vector< Function< T, NDIM > > grad_bspline_three(const Function< T, NDIM > &f, bool refine=false, bool fence=true)
Definition vmra.h:2418
DerivMethod
which first derivative the div_* variants use
Definition vmra.h:2444
static const int kmax
Definition twoscale.cc:52
std::vector< Function< T, NDIM > > zero_functions_compressed(World &world, int n, bool fence=true)
Generates a vector of zero functions (compressed)
Definition vmra.h:450
double imag(double x)
Definition complexfun.h:56
void load_function(World &world, std::vector< Function< T, NDIM > > &f, const std::string name)
load a vector of functions
Definition vmra.h:2609
std::vector< Function< TENSOR_RESULT_TYPE(L, R), D > > vmulXX(const Function< L, D > &left, const std::vector< Function< R, D > > &vright, double tol, bool fence=true)
Use the vmra/mul(...) interface instead.
Definition mra.h:2037
void refine_to_common_level(World &world, std::vector< Function< T, NDIM > > &vf, bool fence=true)
refine all functions to a common (finest) level
Definition vmra.h:207
std::vector< Function< T, NDIM > > grad_ble_two(const Function< T, NDIM > &f, bool refine=false, bool fence=true)
Definition vmra.h:2355
static bool print_timings
Definition SCF.cc:108
CCPairFunction< T, NDIM > apply(const SeparatedConvolution< T, NDIM/2 > &op, const CCPairFunction< T, NDIM > &arg)
apply the operator to the argument
Definition ccpairfunction.h:896
void normalize(World &world, std::vector< Function< T, NDIM > > &v, bool fence=true)
Normalizes a vector of functions — v[i] = v[i].scale(1.0/v[i].norm2())
Definition vmra.h:2092
void stage_halo(World &world, const std::vector< std::shared_ptr< Derivative< T, NDIM > > > &grad, const std::vector< Function< T, NDIM > > &v, bool fence=true)
Pre-stages the neighbor coefficients that differentiating v with each of grad will need.
Definition vmra.h:382
std::vector< Function< T, NDIM > > zero_functions(World &world, int n, bool fence=true)
Generates a vector of zero functions (reconstructed)
Definition vmra.h:443
std::vector< CCPairFunction< T, NDIM > > operator+(const std::vector< CCPairFunction< T, NDIM > > c1, const std::vector< CCPairFunction< T, NDIM > > &c2)
Definition ccpairfunction.h:1052
Function< TENSOR_RESULT_TYPE(L, R), NDIM > mul_sparse(const Function< L, NDIM > &left, const Function< R, NDIM > &right, double tol, bool fence=true, bool do_make_redundant=true)
Sparse multiplication; the scalar interface redirects to the vector one in vmra.h.
Definition mra.h:1977
std::vector< Function< T, NDIM > > grad(const Function< T, NDIM > &f, bool refine=false, bool fence=true)
shorthand gradient operator
Definition vmra.h:2316
Function< T, CCPairFunction< T, NDIM >::LDIM > inner(const CCPairFunction< T, NDIM > &c, const Function< T, CCPairFunction< T, NDIM >::LDIM > &f, const std::tuple< int, int, int > v1, const std::tuple< int, int, int > v2)
Definition ccpairfunction.h:993
Function< T, NDIM > multiply(const Function< T, NDIM > f, const Function< T, LDIM > g, const int particle, const bool fence=true)
multiply a high-dimensional function with a low-dimensional function
Definition mra.h:2621
void scale(World &world, std::vector< Function< T, NDIM > > &v, const std::vector< Q > &factors, bool fence=true)
Scales inplace a vector of functions by distinct values.
Definition vmra.h:874
std::vector< Function< T, NDIM > > zero_functions_auto_tree_state(World &world, int n, bool fence=true)
Generates a vector of zero functions, either compressed or reconstructed, depending on tensor type.
Definition vmra.h:457
DistributedMatrix< T > matrix_dot(const DistributedMatrixDistribution &d, const std::vector< Function< T, NDIM > > &f, const std::vector< Function< T, NDIM > > &g, bool sym=false)
Definition vmra.h:1737
void load(Function< T, NDIM > &f, const std::string name)
Definition mra.h:3032
std::vector< Function< T, NDIM > > zero_functions_tree_state(World &world, int n, const TreeState state, bool fence=true)
Generates a vector of zero functions with a given tree state.
Definition vmra.h:422
double real(double x)
Definition complexfun.h:52
std::vector< CCPairFunction< T, NDIM > > & operator+=(std::vector< CCPairFunction< T, NDIM > > &lhs, const CCPairFunction< T, NDIM > &rhs)
Definition ccpairfunction.h:1068
@ same
same atoms at the same places
std::vector< Function< T, NDIM > > orthonormalize_canonical(const std::vector< Function< T, NDIM > > &v, const Tensor< T > &ovlp, double lindep=1e-12)
Definition vmra.h:563
Tensor< TENSOR_RESULT_TYPE(T, R) > matrix_dot_old(World &world, const std::vector< Function< T, NDIM > > &f, const std::vector< Function< R, NDIM > > &g, bool sym=false)
Computes the matrix dot product of two function vectors - q(i,j) = dot(f[i],g[j])
Definition vmra.h:1800
std::string name(const FuncType &type, const int ex=-1)
Definition ccpairfunction.h:28
void clear_halo(const std::vector< Function< T, NDIM > > &v)
Discards the neighbor halos staged on v.
Definition vmra.h:397
void matrix_inner(DistributedMatrix< T > &A, const std::vector< Function< T, NDIM > > &f, const std::vector< Function< T, NDIM > > &g, bool sym=false)
Definition distpm.cc:46
double get_size(World &world, const std::vector< Function< T, NDIM > > &v)
Definition vmra.h:2134
double get_size_local(World &world, const std::vector< Function< T, NDIM > > &v)
return the size of a vector of functions for each rank
Definition vmra.h:2115
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence.
Definition mra.h:2233
void syev(const Tensor< T > &A, Tensor< T > &V, Tensor< typename Tensor< T >::scalar_type > &e)
Real-symmetric or complex-Hermitian eigenproblem.
Definition lapack.cc:969
Tensor< TENSOR_RESULT_TYPE(T, R) > matrix_inner_old(World &world, const std::vector< Function< T, NDIM > > &f, const std::vector< Function< R, NDIM > > &g, bool sym=false)
Computes the matrix inner product of two function vectors - q(i,j) = inner(f[i],g[j])
Definition vmra.h:1083
void make_nonstandard(World &world, std::vector< Function< T, NDIM > > &v, bool fence=true)
Generates non-standard form of a vector of functions.
Definition vmra.h:234
void gaxpy(const double a, ScalarResult< T > &left, const double b, const T &right, const bool fence=true)
the result type of a macrotask must implement gaxpy
Definition macrotaskq.h:244
int distance(const madness::Hash_private::HashIterator< hashT > &it, const madness::Hash_private::HashIterator< hashT > &jt)
Definition worldhashmap.h:616
static long abs(long a)
Definition tensor.h:219
static const double b
Definition nonlinschro.cc:119
static const double d
Definition nonlinschro.cc:121
static const double a
Definition nonlinschro.cc:118
static const size_t nfunc
Definition pcr.cc:63
double Q(double a)
Definition relops.cc:20
static const double c
Definition relops.cc:10
static const double m
Definition relops.cc:9
static const double L
Definition rk.cc:46
static const double thresh
Definition rk.cc:45
static const long k
Definition rk.cc:44
Definition test_ar.cc:204
double operator()(const Key< 6 > &key, const FunctionNode< double, 6 > &node) const
Definition mp2.h:70
Definition lowrankfunction.h:336
Definition dirac-hatom.cc:112
std::string ok(const bool b)
Definition test6.cc:43
AtomicInt sum
Definition test_atomicint.cc:46
int P
Definition test_binsorter.cc:9
void e()
Definition test_sig.cc:75
static const double alpha
Definition testcosine.cc:10
constexpr std::size_t NDIM
Definition testgconv.cc:54
double h(const coord_1d &r)
Definition testgconv.cc:175
#define TENSOR_RESULT_TYPE(L, R)
This macro simplifies access to TensorResultType.
Definition type_data.h:205
#define PROFILE_FUNC
Definition worldprofile.h:209
#define PROFILE_BLOCK(name)
Definition worldprofile.h:208
int ProcessID
Used to clearly identify process number/rank.
Definition worldtypes.h:43