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);
895 template <
typename T, std::
size_t NDIM>
899 std::vector<double> norms(
v.size());
901 for (
unsigned int i=0; i<
v.size(); ++i) norms[i] =
v[i].norm2sq_local();
902 world.
gop.
sum(&norms[0], norms.size());
903 for (
unsigned int i=0; i<
v.size(); ++i) norms[i] = sqrt(norms[i]);
908 template <
typename T, std::
size_t NDIM>
913 for (
unsigned int i = 0; i <
v.size(); ++i) norms[i] =
v[i].norm2sq_local();
915 for (
unsigned int i = 0; i <
v.size(); ++i) norms[i] = sqrt(norms[i]);
921 template <
typename T, std::
size_t NDIM>
924 if (
v.size()==0)
return 0.0;
926 std::vector<double> norms(
v.size());
927 for (
unsigned int i=0; i<
v.size(); ++i) norms[i] =
v[i].norm2sq_local();
928 world.
gop.
sum(&norms[0], norms.size());
929 for (
unsigned int i=1; i<
v.size(); ++i) norms[0] += norms[i];
931 return sqrt(norms[0]);
977 template <
typename T, std::
size_t NDIM>
985 const int64_t n =
A.coldim();
986 const int64_t
m =
A.rowdim();
990 const int ichunk = 1000;
991 const int jchunk = 1000;
992 for (int64_t ilo=0; ilo<n; ilo+=ichunk) {
993 int64_t ihi = std::min(ilo + ichunk, n);
994 std::vector< Function<T,NDIM> > ivec(
f.begin()+ilo,
f.begin()+ihi);
995 for (int64_t jlo=0; jlo<
m; jlo+=jchunk) {
996 int64_t jhi = std::min(jlo + jchunk,
m);
997 std::vector< Function<T,NDIM> > jvec(
g.begin()+jlo,
g.begin()+jhi);
1000 A.copy_from_replicated_patch(ilo, ihi - 1, jlo, jhi - 1,
P);
1011 template <
typename T,
typename R, std::
size_t NDIM>
1018 auto tensor_type = [](
const std::vector<Function<T,NDIM>>&
v) {
1019 return v.front().get_impl()->get_tensor_type();
1025 std::vector<const FunctionImpl<T,NDIM>*> left(
f.size());
1026 std::vector<const FunctionImpl<R,NDIM>*> right(
g.size());
1027 for (
unsigned int i=0; i<
f.size(); i++) left[i] =
f[i].
get_impl().get();
1028 for (
unsigned int i=0; i<
g.size(); i++) right[i]=
g[i].
get_impl().get();
1043 template <
typename T,
typename R, std::
size_t NDIM>
1049 long n=
f.size(),
m=
g.size();
1055 if ((
void*)(&
f) != (
void*)(&
g))
compress(world,
g);
1057 for (
long i=0; i<n; ++i) {
1059 if (sym) jtop = i+1;
1060 for (
long j=0; j<jtop; ++j) {
1061 r(i,j) =
f[i].inner_local(
g[j]);
1062 if (sym) r(j,i) =
conj(r(i,j));
1087 template <
typename T,
typename R, std::
size_t NDIM>
1092 long n=
f.size(),
m=
g.size();
1097 auto tensor_type = [](
const std::vector<Function<T,NDIM>>&
v) {
1098 return v.front().get_impl()->get_tensor_type();
1104 for (
long i=0; i<n; ++i) r(i) =
f[i].inner_local(
g[i]);
1116 template <
typename T,
typename R, std::
size_t NDIM>
1124 auto tensor_type = [](
const std::vector<Function<T,NDIM>>&
v) {
1125 return v.front().get_impl()->get_tensor_type();
1128 f.change_tree_state(operating_state,
false);
1132 for (
long i=0; i<n; ++i) {
1133 r(i) =
f.inner_local(
g[i]);
1144 template <
typename T,
typename R, std::
size_t NDIM>
1148 if(
f.empty())
return 0.0;
1149 else return inner(
f[0].world(),
f,
g).sum();
1154 template <
typename T,
typename R, std::
size_t NDIM>
1162 a.make_redundant(
false);
1186 template <
typename T,
typename R, std::
size_t NDIM>
1193 bool do_make_redundant=
true) {
1195 if (do_make_redundant) {
1200 print(
"could not respect fence in mul_sparse");
1201 a.make_redundant(
false);
1205 }
else if (!
v.empty()) {
1207 "mul_sparse: left input must be redundant when do_make_redundant=false");
1209 "mul_sparse: right inputs must be redundant when do_make_redundant=false");
1233 template <
typename T,
typename R, std::
size_t NDIM>
1240 bool do_make_redundant=
true) {
1242 if (do_make_redundant) {
1247 print(
"could not respect fence in mul_sparse");
1254 for (
unsigned int i=0; i<
a.size(); ++i) {
1275 template <
typename T,
typename R, std::
size_t NDIM>
1282 bool symm =
false) {
1289 std::vector<std::vector<Function<R,NDIM> > >result(
f.size());
1290 std::vector<Function<R,NDIM>> g_i;
1291 for (int64_t i=
f.size()-1; i>=0; --i) {
1293 result[i]=
vmulXX(
f[i],
g, tol,
false);
1295 if (g_i.empty()) g_i =
g;
1297 result[i]=
vmulXX(
f[i], g_i, tol,
false);
1305 template <
typename T, std::
size_t NDIM>
1311 for (
unsigned int i=0; i<
v.size(); ++i) {
1312 v[i].norm_tree(
false);
1318 template <
typename T,
typename R, std::
size_t NDIM>
1324 bool do_make_redundant=
true) {
1326 if (do_make_redundant) {
1331 print(
"could not respect fence in mul");
1338 for (
unsigned int i=0; i<
a.size(); ++i) {
1339 q[i] =
mul(
a[i],
b[i],
false,
false);
1352 template<
typename T, std::
size_t NDIM, std::
size_t LDIM>
1357 std::vector<Function<T,NDIM> > result(
g.size());
1358 for (
auto& r : result) r.set_impl(
f,
false);
1366 for (std::size_t i=0; i<result.size(); ++i) {
1373 for (
auto& ig :
g) ig.get_impl()->undo_redundant(
false);
1378 template<
typename T, std::
size_t NDIM, std::
size_t LDIM>
1380 const std::tuple<int,int,int>
v) {
1381 return partial_mul<T,NDIM,LDIM>(
f,
g,std::array<int,3>({std::get<0>(
v),std::get<1>(
v),std::get<2>(
v)}));
1386 template <
typename T, std::
size_t NDIM>
1387 std::vector< Function<T,NDIM> >
1391 return mul<T,T,NDIM>(world,
v,
v, fence);
1402 template <
typename T, std::
size_t NDIM>
1403 std::vector< Function<typename Tensor<T>::scalar_type,
NDIM> >
1409 std::vector<Function<scalartype,NDIM> > result(
v.size());
1410 for (
size_t i=0; i<
v.size(); ++i) result[i]=
abs_square(
v[i],
false);
1417 template <
typename T, std::
size_t NDIM>
1419 for (
unsigned int j=0; j<
v.size(); ++j) {
1420 v[j].set_thresh(
thresh,
false);
1426 template <
typename T, std::
size_t NDIM>
1427 std::vector< Function<T,NDIM> >
1432 std::vector< Function<T,NDIM> > r =
copy(world,
v);
1433 for (
unsigned int i=0; i<
v.size(); ++i) {
1441 template <
typename T,
typename R, std::
size_t NDIM>
1445 std::vector< Function<R,NDIM> > r(
v.size());
1446 for (
unsigned int i=0; i<
v.size(); ++i) {
1447 r[i] = convert<T,R,NDIM>(
v[i],
false);
1455 template <
typename T, std::
size_t NDIM>
1456 std::vector< Function<T,NDIM> >
1461 std::vector< Function<T,NDIM> > r(
v.size());
1462 for (
unsigned int i=0; i<
v.size(); ++i) {
1463 r[i] =
copy(
v[i],
false);
1471 template <
typename T, std::
size_t NDIM>
1472 std::vector< Function<T,NDIM> >
1475 std::vector< Function<T,NDIM> > r(
v.size());
1476 if (
v.size()>0) r=
copy(
v.front().world(),
v,fence);
1481 template <
typename T, std::
size_t NDIM>
1482 std::vector< Function<T,NDIM> >
1485 const unsigned int n,
1488 std::vector< Function<T,NDIM> > r(n);
1489 for (
unsigned int i=0; i<n; ++i) {
1490 r[i] =
copy(
v,
false);
1505 template <
typename T, std::
size_t NDIM>
1509 bool fence =
true) {
1511 std::vector<Function<T, NDIM>> r(
v.size());
1512 for (
unsigned int i = 0; i <
v.size(); ++i) {
1513 r[i] =
copy(
v[i], pmap,
false);
1522 std::vector<ProcessID> owner(
nfunc);
1523 for (std::size_t j = 0; j <
nfunc; ++j) owner[j] =
ProcessID(j % std::size_t(nranks));
1533 const std::size_t
nfunc = cost.size();
1534 std::vector<ProcessID> owner(
nfunc);
1535 std::vector<std::size_t> order(
nfunc);
1536 for (std::size_t j = 0; j <
nfunc; ++j) order[j] = j;
1538 std::stable_sort(order.begin(), order.end(),
1539 [&](std::size_t
a, std::size_t
b) { return cost[a] > cost[b]; });
1540 std::vector<double>
load(std::size_t(nranks), 0.0);
1541 for (std::size_t
k = 0;
k <
nfunc; ++
k) {
1543 for (
int r = 1; r < nranks; ++r)
1544 if (
load[std::size_t(r)] <
load[std::size_t(best)]) best = r;
1545 const std::size_t j = order[
k];
1547 load[std::size_t(best)] += std::max(1.0, cost[j]);
1555 template <
typename T, std::
size_t NDIM>
1557 std::vector<double> cost(
v.size(), 0.0);
1558 for (std::size_t j = 0; j <
v.size(); ++j) cost[j] =
double(
v[j].size_local());
1559 if (!
v.empty()) world.
gop.
sum(cost.data(), cost.size());
1575 template <
typename T, std::
size_t NDIM>
1578 const std::vector<ProcessID>& owner,
1579 std::size_t cap_bytes = 0,
1580 bool rotate =
true) {
1582 if (
v.empty())
return;
1587 for (std::size_t j = 0; j < owner.size(); ++j)
h +=
long(owner[j]) * long(j + 1);
1588 long hmax =
h, hmin =
h;
1596 if (cap_bytes == 0) cap_bytes = 1024 * 1024;
1598 for (
const auto&
f :
v)
kmax = std::max(
kmax,
long(
f.k()));
1599 std::size_t box_bytes =
sizeof(T);
1600 for (std::size_t
d = 0;
d <
NDIM; ++
d) box_bytes *= std::size_t(2 *
kmax);
1601 const std::size_t cap_boxes = std::max<std::size_t>(1, cap_bytes / box_bytes);
1606 for (std::size_t j = 0; j <
v.size(); ++j) {
1607 auto pmap = std::shared_ptr<WorldDCPmapInterface<Key<NDIM>>>(
1609 v[j].get_impl()->get_coeffs().redistribute_coalesced_phase1(pmap);
1612 for (std::size_t j = 0; j <
v.size(); ++j)
1613 v[j].
get_impl()->get_coeffs().redistribute_coalesced_phase2(cap_boxes, rotate);
1618 template <
typename T,
typename R, std::
size_t NDIM>
1630 for (
unsigned int i=0; i<
a.size(); ++i) {
1631 r[i] =
add(
a[i],
b[i],
false);
1638 template <
typename T,
typename R, std::
size_t NDIM>
1649 for (
unsigned int i=0; i<
b.size(); ++i) {
1650 r[i] =
add(
a,
b[i],
false);
1655 template <
typename T,
typename R, std::
size_t NDIM>
1661 return add(world,
a,
b, fence);
1665 template <
typename T,
typename R, std::
size_t NDIM>
1677 for (
unsigned int i=0; i<
a.size(); ++i) {
1678 r[i] =
sub(
a[i],
b[i],
false);
1685 template <
typename T, std::
size_t NDIM>
1692 for (
unsigned int i=0; i<
f.size(); ++i) r.
gaxpy(1.0,
f[i],1.0,
false);
1697 template <
typename T, std::
size_t NDIM>
1705 const int64_t n =
A.coldim();
1706 const int64_t
m =
A.rowdim();
1710 const int ichunk = 1000;
1711 const int jchunk = 1000;
1712 for (int64_t ilo = 0; ilo < n; ilo += ichunk) {
1713 int64_t ihi = std::min(ilo + ichunk, n);
1714 std::vector<Function<T, NDIM>> ivec(
f.begin() + ilo,
f.begin() + ihi);
1715 for (int64_t jlo = 0; jlo <
m; jlo += jchunk) {
1716 int64_t jhi = std::min(jlo + jchunk,
m);
1717 std::vector<Function<T, NDIM>> jvec(
g.begin() + jlo,
g.begin() + jhi);
1720 A.copy_from_replicated_patch(ilo, ihi - 1, jlo, jhi - 1,
P);
1731 template <
typename T,
typename R, std::
size_t NDIM>
1742 std::vector<const FunctionImpl<T, NDIM>*> left(
f.size());
1743 std::vector<const FunctionImpl<R, NDIM>*> right(
g.size());
1744 for (
unsigned int i = 0; i <
f.size(); i++) left[i] =
f[i].
get_impl().get();
1745 for (
unsigned int i = 0; i <
g.size(); i++) right[i] =
g[i].
get_impl().get();
1760 template <
typename T,
typename R, std::
size_t NDIM>
1766 long n=
f.size(),
m=
g.size();
1772 if ((
void*)(&
f) != (
void*)(&
g))
compress(world,
g);
1774 for (
long i=0; i<n; ++i) {
1776 if (sym) jtop = i+1;
1777 for (
long j=0; j<jtop; ++j) {
1779 r(j,i) =
f[i].dot_local(
g[j]);
1781 r(i,j) =
conj(r(j,i));
1783 r(i,j) =
f[i].dot_local(
g[j]);
1794 template <
typename T,
typename R, std::
size_t NDIM>
1801 bool do_make_redundant=
true) {
1803 return sum(world,
mul_sparse(world,
a,
b,tol,
true,do_make_redundant),fence);
1807 template <
typename T,
typename R, std::
size_t NDIM>
1813 bool do_make_redundant=
true) {
1815 return sum(world,
mul(world,
a,
b,
true,do_make_redundant),fence);
1819 template <
typename T,
typename Q,
typename R, std::
size_t NDIM>
1829 if (
a.size()==0)
return std::vector<Function<resultT,NDIM> >();
1831 auto tensor_type = [](
const std::vector<Function<T,NDIM>>&
v) {
1832 return v.front().get_impl()->get_tensor_type();
1836 World& world=
a[0].world();
1837 std::vector<Function<resultT,NDIM> > result(
a.size());
1844 print(
"could not respect fence in gaxpy");
1861 template <
typename T,
typename Q,
typename R, std::
size_t NDIM>
1870 if (
a.size()==0)
return std::vector<Function<resultT,NDIM> >();
1872 World& world=
a[0].world();
1878 print(
"could not respect fence in gaxpy_oop");
1882 std::vector<Function<resultT,NDIM> > result(
a.size());
1883 for (
unsigned int i=0; i<
a.size(); ++i) {
1886 if (fence) world.gop.fence();
1892 template <
typename T,
typename Q,
typename R, std::
size_t NDIM>
1894 if (
a.size() == 0)
return;
1895 World& world=
a.front().world();
1900 template <
typename T,
typename Q,
typename R, std::
size_t NDIM>
1909 if (
a.empty())
return;
1911 auto tensor_type = [](
const std::vector<Function<T,NDIM>>&
v) {
1912 return v.front().get_impl()->get_tensor_type();
1916 bool do_in_reconstructed_state=tensor_type(
a)!=
TT_FULL;
1925 print(
"could not respect fence in gaxpy");
1939 print(
"could not respect fence in gaxpy for a");
1947 print(
"could not respect fence in gaxpy for b");
1954 for (
unsigned int i=0; i<
a.size(); ++i) {
1958 for (
unsigned int i=0; i<
a.size(); ++i)
a[i].
get_impl()->finalize_sum();
1966 template <
typename opT,
typename R, std::
size_t NDIM>
1969 const std::vector< std::shared_ptr<opT> >&
op,
1975 std::vector< Function<R,NDIM> >&
ncf = *
const_cast< std::vector< Function<R,NDIM>
>* >(&
f);
1981 for (
unsigned int i=0; i<
f.size(); ++i) {
1997 template <
typename T,
typename R, std::
size_t NDIM, std::
size_t KDIM>
2006 template <
typename T,
typename R, std::
size_t NDIM, std::
size_t KDIM>
2013 std::vector< Function<R,NDIM> >&
ncf = *
const_cast< std::vector< Function<R,NDIM>
>* >(&
f);
2020 if (
print_timings) printf(
"timer: %20.20s %8.2fs\n",
"make_nonstandard", wall1-wall0);
2023 for (
unsigned int i=0; i<
f.size(); ++i) {
2030 if (
op.destructive()) {
2031 for (
auto& ff :
ncf) ff.clear(
false);
2039 for (
auto& r : result) r.get_impl()->finalize_apply();
2043 for (
auto& r : result) r.get_impl()->print_timer();
2052 template <
typename T, std::
size_t NDIM>
2055 std::vector<double> nn =
norm2s(world,
v);
2056 for (
unsigned int i=0; i<
v.size(); ++i)
v[i].
scale(1.0/nn[i],
false);
2060 template <
typename T, std::
size_t NDIM>
2063 if(world.
rank()==0) std::cout <<
"print_size: " << msg <<
" is empty" << std::endl;
2064 }
else if(
v.size()==1){
2065 v.front().print_size(msg);
2075 template <
typename T, std::
size_t NDIM>
2079 if (x.is_initialized()) size+=x.size_local();
2081 const double d=
sizeof(T);
2082 const double fac=1024*1024*1024;
2087 template <
typename T, std::
size_t NDIM>
2094 template <
typename T, std::
size_t NDIM>
2097 if (
v.empty())
return 0.0;
2099 const double d=
sizeof(T);
2100 const double fac=1024*1024*1024;
2103 for(
unsigned int i=0;i<
v.size();i++){
2104 if (
v[i].is_initialized()) size+=
v[i].size();
2112 template <
typename T, std::
size_t NDIM>
2114 const double d=
sizeof(T);
2115 const double fac=1024*1024*1024;
2116 double size=
f.size();
2125 template <
typename T,
typename opT, std::
size_t NDIM>
2128 const bool fence=
true) {
2131 World& world=vin[0].world();
2134 std::vector<Function<T,NDIM> > vout=zero_functions<T,NDIM>(world,
op.get_result_size());
2135 for (
auto& out : vout) out.set_impl(vin[0],
false);
2146 template <
typename T, std::
size_t NDIM>
2154 template <
typename T, std::
size_t NDIM>
2162 template <
typename T, std::
size_t NDIM>
2170 template <
typename T, std::
size_t NDIM>
2178 template <
typename T, std::
size_t NDIM>
2186 template <
typename T, std::
size_t NDIM>
2194 template <
typename T,
typename R, std::
size_t NDIM>
2198 std::vector<Function<T,NDIM> > tmp=
copy(rhs[0].world(),rhs);
2205 template <
typename T,
typename R, std::
size_t NDIM>
2217 template <
typename T,
typename R, std::
size_t NDIM>
2220 if (
v.size()>0)
return mul(
v[0].world(),
a,
v,
true);
2226 template <
typename T,
typename R, std::
size_t NDIM>
2229 if (
v.size()>0)
return mul(
v[0].world(),
a,
v,
true);
2234 template <
typename T, std::
size_t NDIM>
2237 if (lhs.size() > 0)
gaxpy(lhs.front().world(), 1.0, lhs, 1.0, rhs);
2241 template <
typename T, std::
size_t NDIM>
2245 if (lhs.size() > 0)
gaxpy(lhs.front().world(), 1.0, lhs, -1.0, rhs);
2250 template <
typename T, std::
size_t NDIM>
2251 std::vector<Function<typename Tensor<T>::scalar_type,
NDIM> >
2253 std::vector<Function<typename Tensor<T>::scalar_type,
NDIM> > result(
v.size());
2254 for (std::size_t i=0; i<
v.size(); ++i) result[i]=
real(
v[i],
false);
2255 if (fence and result.size()>0) result[0].world().gop.fence();
2260 template <
typename T, std::
size_t NDIM>
2261 std::vector<Function<typename Tensor<T>::scalar_type,
NDIM> >
2263 std::vector<Function<typename Tensor<T>::scalar_type,
NDIM> > result(
v.size());
2264 for (std::size_t i=0; i<
v.size(); ++i) result[i]=
imag(
v[i],
false);
2265 if (fence and result.size()>0) result[0].world().gop.fence();
2276 template <
typename T, std::
size_t NDIM>
2278 bool refine=
false,
bool fence=
true) {
2284 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2285 gradient_operator<T,NDIM>(world);
2287 std::vector<Function<T,NDIM> > result(
NDIM);
2288 for (
size_t i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
f,
false);
2294 template <
typename T, std::
size_t NDIM>
2296 bool refine=
false,
bool fence=
true) {
2302 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2303 gradient_operator<T,NDIM>(world);
2306 for (
unsigned int i=0; i<
NDIM; ++i) (*
grad[i]).set_ble1();
2308 std::vector<Function<T,NDIM> > result(
NDIM);
2309 for (
unsigned int i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
f,
false);
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);
2327 for (
unsigned int i=0; i<
NDIM; ++i) (*
grad[i]).set_ble2();
2329 std::vector<Function<T,NDIM> > result(
NDIM);
2330 for (
unsigned int i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
f,
false);
2336 template <
typename T, std::
size_t NDIM>
2338 bool refine=
false,
bool fence=
true) {
2344 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2345 gradient_operator<T,NDIM>(world);
2348 for (
unsigned int i=0; i<
NDIM; ++i) (*
grad[i]).set_bspline1();
2350 std::vector<Function<T,NDIM> > result(
NDIM);
2351 for (
unsigned int i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
f,
false);
2357 template <
typename T, std::
size_t NDIM>
2359 bool refine=
false,
bool fence=
true) {
2365 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2366 gradient_operator<T,NDIM>(world);
2369 for (
unsigned int i=0; i<
NDIM; ++i) (*
grad[i]).set_bspline2();
2371 std::vector<Function<T,NDIM> > result(
NDIM);
2372 for (
unsigned int i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
f,
false);
2378 template <
typename T, std::
size_t NDIM>
2380 bool refine=
false,
bool fence=
true) {
2386 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2387 gradient_operator<T,NDIM>(world);
2390 for (
unsigned int i=0; i<
NDIM; ++i) (*
grad[i]).set_bspline3();
2392 std::vector<Function<T,NDIM> > result(
NDIM);
2393 for (
unsigned int i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
f,
false);
2408 template <
typename T, std::
size_t NDIM>
2410 bool do_refine=
false,
bool fence=
true) {
2413 World& world=
v[0].world();
2415 if (do_refine)
refine(world,
v);
2417 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2418 gradient_operator<T,NDIM>(world);
2420 std::vector<Function<T,NDIM> > result(
NDIM);
2421 for (
size_t i=0; i<
NDIM; ++i) result[i]=
apply(*(
grad[i]),
v[i],
false);
2423 return sum(world,result,fence);
2434 template <
typename T, std::
size_t NDIM>
2436 bool do_refine=
false,
bool fence=
true) {
2439 World& world=
v[0].world();
2441 if (do_refine)
refine(world,
v);
2443 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
grad=
2444 gradient_operator<T,NDIM>(world);
2446 std::vector<Function<T,NDIM> >
d(
NDIM),dd(
NDIM);
2458 d[0].gaxpy(1.0,dd[0],-1.0,
false);
2459 d[1].gaxpy(1.0,dd[1],-1.0,
false);
2460 d[2].gaxpy(1.0,dd[2],-1.0,
false);
2475 template <
typename T,
typename R, std::
size_t NDIM>
2478 bool do_refine=
false,
bool fence=
true) {
2482 World& world=
f[0].world();
2488 d[0]=
mul(
f[1],
g[2],
false);
2489 d[1]=
mul(
f[2],
g[0],
false);
2490 d[2]=
mul(
f[0],
g[1],
false);
2492 dd[0]=
mul(
f[2],
g[1],
false);
2493 dd[1]=
mul(
f[0],
g[2],
false);
2494 dd[2]=
mul(
f[1],
g[0],
false);
2501 d[0].gaxpy(1.0,dd[0],-1.0,
false);
2502 d[1].gaxpy(1.0,dd[1],-1.0,
false);
2503 d[2].gaxpy(1.0,dd[2],-1.0,
false);
2510 template<
typename T, std::
size_t NDIM>
2527 template<
typename T,
size_t NDIM>
2529 const std::string
name) {
2530 if (world.
rank()==0)
print(
"loading vector of functions",
name);
2532 std::size_t fsize=0;
2535 for (std::size_t i=0; i<fsize; ++i) ar &
f[i];
2539 template<
typename T,
size_t NDIM>
2542 World& world=
f.front().world();
2543 if (world.
rank()==0)
print(
"saving vector of functions",
name);
2545 std::size_t fsize=
f.size();
2547 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:329
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:442
static TensorType get_tensor_type()
Returns the default tensor type.
Definition funcdefaults.h:323
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:6242
void undo_redundant(const bool fence)
convert this from redundant to standard reconstructed form
Definition mraimpl.h:1559
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:3798
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:1421
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:6294
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:1124
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:1701
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
Convolutions in separated form (including Gaussian)
Definition operator.h:139
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:176
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:72
#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
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:13
void save_function(const std::vector< Function< T, NDIM > > &f, const std::string name)
save a vector of functions
Definition vmra.h:2540
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:2917
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:2099
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:1556
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:2885
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:2154
std::vector< ProcessID > assign_round_robin(std::size_t nfunc, int nranks)
owner[j] = j % nranks. For redistribute_to_batches.
Definition vmra.h:1520
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:909
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:896
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:1796
std::vector< Function< T, NDIM > > grad_bspline_one(const Function< T, NDIM > &f, bool refine=false, bool fence=true)
Definition vmra.h:2337
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:2232
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:1884
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:1809
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
Definition vmra.h:2409
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:1483
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:1306
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:2476
TreeState
Definition funcdefaults.h:59
@ nonstandard_after_apply
s and d coeffs, state after operator application
Definition funcdefaults.h:64
@ redundant_after_merge
s coeffs everywhere, must be summed up to yield the result
Definition funcdefaults.h:66
@ reconstructed
s coeffs at the leaves only
Definition funcdefaults.h:60
@ nonstandard
s and d coeffs in internal nodes
Definition funcdefaults.h:62
@ unknown
Definition funcdefaults.h:68
@ compressed
d coeffs in internal nodes, s and d coeffs at the root, empty leaves may be present
Definition funcdefaults.h:61
@ redundant
s coeffs everywhere
Definition funcdefaults.h:65
@ nonstandard_with_leaves
like nonstandard, with s coeffs at the leaves
Definition funcdefaults.h:63
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:2246
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:1277
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:2358
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:1418
double norm2(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norm of a vector of functions.
Definition vmra.h:922
std::vector< ProcessID > assign_cost_aware(const std::vector< double > &cost, int nranks)
Definition vmra.h:1531
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:2126
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:2933
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:1353
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:2117
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:1576
@ 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
void print_size(World &world, const std::vector< Function< T, NDIM > > &v, const std::string &msg="vectorfunction")
Definition vmra.h:2061
NDIM & f
Definition mra.h:2620
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:2109
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:2946
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:2620
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:2295
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:2320
std::vector< Function< T, NDIM > > grad_bspline_three(const Function< T, NDIM > &f, bool refine=false, bool fence=true)
Definition vmra.h:2379
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:2528
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:1989
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:2316
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:2053
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:1929
std::vector< Function< T, NDIM > > grad(const Function< T, NDIM > &f, bool refine=false, bool fence=true)
shorthand gradient operator
Definition vmra.h:2277
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:2573
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:1698
void load(Function< T, NDIM > &f, const std::string name)
Definition mra.h:2984
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:1761
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:2095
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:2076
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:2185
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:1044
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