35template <
class IT,
class NT>
41template <
class IT,
class NT>
45 arr.resize(MyLocLength(),
initval);
49template <
class IT,
class NT>
54template <
class IT,
class NT>
58 arr.resize(MyLocLength(),
initval);
61template <
class IT,
class NT>
69template <
class IT,
class NT>
70template <
class ITRHS,
class NTRHS>
74 arr.resize(
static_cast<IT>(
rhs.arr.size()),
NT());
78 arr[i] =
static_cast<NT>(
rhs.arr[
static_cast<ITRHS>(i)]);
86template <
class IT,
class NT>
91 int nprocs = commGrid->GetSize();
92 int rank = commGrid->GetRank();
98 glen = std::accumulate(
sizes,
sizes+nprocs,
static_cast<IT>(0));
114 int *
sendcnt =
new int[nprocs];
122 int *
recvcnt =
new int[nprocs];
125 int *
sdispls =
new int[nprocs];
126 int *
rdispls =
new int[nprocs];
129 for(
int i=0; i<nprocs-1; ++i)
147template <
class IT,
class NT>
169template <
class IT,
class NT>
170template <
typename _BinaryOperation>
181template <
class IT,
class NT>
182template <
typename OUT,
typename _BinaryOperation,
typename _UnaryOperation>
190 typename std::vector< NT >::const_iterator
iter = arr.begin();
193 while (
iter < arr.end())
207template<
class IT,
class NT>
223 for(
int i=0; i<
length; ++i)
227 for(
int i=0; i<
length; ++i)
235template <
class IT,
class NT>
236template <
class ITRHS,
class NTRHS>
239 if(
static_cast<const void*
>(
this) !=
static_cast<const void*
>(&
rhs))
242 glen =
static_cast<IT>(
rhs.glen);
245 arr.resize(
rhs.arr.size(),
NT());
248 arr[i] =
static_cast<NT>(
rhs.arr[
static_cast<ITRHS>(i)]);
254template <
class IT,
class NT>
265template <
class IT,
class NT>
269 arr.resize(
rhs.MyLocLength());
270 std::fill(arr.begin(), arr.end(),
NT());
277 arr[
rhs.ind[i]] =
rhs.num[i];
290template <
class IT,
class NT>
295 #pragma omp parallel for
299 if(arr[
rhs.ind[i]] ==
NT())
300 arr[
rhs.ind[i]] =
rhs.num[i];
302 arr[
rhs.ind[i]] +=
rhs.num[i];
309template <
class IT,
class NT>
315 arr[
rhs.ind[i]] -=
rhs.num[i];
325template <
class IT,
class NT>
326template <
typename _BinaryOperation>
329 std::transform ( arr.begin(), arr.end(),
rhs.arr.begin(), arr.begin(),
__binary_op );
336template <
class IT,
class NT>
337template <
typename _BinaryOperation,
typename OUT>
344template <
class IT,
class NT>
351 std::cout <<
"Grids are not comparable elementwise addition" << std::endl;
356 EWise(
rhs, std::plus<NT>());
362template <
class IT,
class NT>
369 std::cout <<
"Grids are not comparable elementwise addition" << std::endl;
374 EWise(
rhs, std::minus<NT>());
380template <
class IT,
class NT>
388 return static_cast<bool>(
whole);
391template <
class IT,
class NT>
392template <
typename _Predicate>
403template <
class IT,
class NT>
404template <
typename _Predicate>
432 int *
sendcnt =
new int[nprocs];
440 int *
recvcnt =
new int[nprocs];
443 int *
sdispls =
new int[nprocs];
444 int *
rdispls =
new int[nprocs];
447 for(
int i=0; i<nprocs-1; ++i)
467template <
class IT,
class NT>
468template <
typename _Predicate>
472 size_t size = arr.size();
473 for(
size_t i=0; i<
size; ++i)
478 found.num.push_back(arr[i]);
487template <
class IT,
class NT>
491 size_t size = arr.size();
492 for(
size_t i=0; i<
size; ++i)
497 found.num.push_back(val);
505template <
class IT,
class NT>
506template <
class HANDLER>
516template <
class IT,
class NT>
517template <
class HANDLER>
524template <
class IT,
class NT>
531 std::cout <<
"FullyDistVec::SetElement can't be called on an empty vector." << std::endl;
538 if (
locind > (LocArrSize() -1))
540 std::cout <<
"FullyDistVec::SetElement cannot expand array" << std::endl;
544 std::cout <<
"FullyDistVec::SetElement local index < 0" << std::endl;
553template <
class IT,
class NT>
562 std::cout <<
"FullyDistVec::GetElement can't be called on an empty vector." << std::endl;
570 if (
locind > (LocArrSize() -1))
572 std::cout <<
"FullyDistVec::GetElement local index > size" << std::endl;
578 std::cout <<
"FullyDistVec::GetElement local index < 0" << std::endl;
591template <
class IT,
class NT>
599 char _fn[] =
"temp_fullydistvec";
608 IT count = LocArrSize();
620 std::cerr <<
"Problem reading binary input file\n";
626 for(
int i=0; i<nprocs; ++i)
630 if (
result != (
unsigned)
counts[i]) { std::cout <<
"Error in fread, only " <<
result <<
" entries read" << std::endl; }
632 std::cout <<
"Elements stored on proc " << i <<
": {" ;
635 std::cout << data[
j] <<
",";
637 std::cout <<
"}" << std::endl;
644template <
class IT,
class NT>
645template <
typename _UnaryOperation,
typename IRRELEVANT_NT>
648 typename std::vector< IT >::const_iterator
miter =
mask.ind.begin();
656template <
class IT,
class NT>
657template <
typename _BinaryOperation,
typename _BinaryPredicate,
class NT2>
662 if(glen != other.glen)
664 std::ostringstream
outs;
665 outs <<
"Vector dimensions don't match (" << glen <<
" vs " << other.glen <<
") for FullyDistVec::EWiseApply\n";
671 typename std::vector< NT >::iterator
thisIter = arr.begin();
672 typename std::vector< NT2 >::const_iterator
otherIter = other.arr.begin();
684 std::ostringstream
outs;
685 outs <<
"Grids are not comparable for FullyDistVec<IT,NT>::EWiseApply" << std::endl;
694template <
class IT,
class NT>
695template <
typename _BinaryOperation,
typename _BinaryPredicate,
class NT2>
700 if(glen != other.glen)
702 std::cerr <<
"Vector dimensions don't match (" << glen <<
" vs " << other.glen <<
") for FullyDistVec::EWiseApply\n";
707 typename std::vector< IT >::const_iterator
otherInd = other.ind.begin();
708 typename std::vector< NT2 >::const_iterator
otherNum = other.num.begin();
739#pragma omp parallel for
743 if (
_do_op(arr[other.ind[i]], other.num[i],
false,
false))
744 arr[other.ind[i]] =
__binary_op(arr[other.ind[i]], other.num[i],
false,
false);
751 std::cout <<
"Grids are not comparable elementwise apply" << std::endl;
757template <
class IT,
class NT>
762 IT nnz = LocArrSize();
763 std::pair<NT,IT> *
vecpair =
new std::pair<NT,IT>[nnz];
771 for(
IT i=0; i< nnz; ++i)
778 std::vector< IT >
narr(nnz);
779 for(
IT i=0; i< nnz; ++i)
794template <
class IT,
class NT>
809#ifdef COMBBLAS_LEGACY
810 std::pair<double,NT> *
vecpair =
new std::pair<double,NT>[
size];
814 for(
int i=0; i<
size; ++i)
826 std::vector< std::vector< NT > >
data_send(nprocs);
827 for(
int i=0; i<
size; ++i)
833 int *
sendcnt =
new int[nprocs];
834 int *
sdispls =
new int[nprocs];
837 int *
rdispls =
new int[nprocs];
838 int *
recvcnt =
new int[nprocs];
842 for(
int i=0; i<nprocs-1; ++i)
848 if(
totrecv > std::numeric_limits<int>::max())
850 std::cout <<
"COMBBLAS_WARNING: total data to receive exceeds max int: " <<
totrecv << std::endl;
852 std::vector<NT>().swap(arr);
855 for(
int i=0; i<nprocs; ++i)
863 std::default_random_engine
gen(seed);
871 std::vector< std::vector< IT > >
locs_send(nprocs);
884 for(
int i=0; i<nprocs-1; ++i)
890 if(
newsize > std::numeric_limits<int>::max())
892 std::cout <<
"COMBBLAS_WARNING: total data to receive exceeds max int: " <<
newsize << std::endl;
898 std::cout <<
"COMBBLAS_WARNING: sending different sized data than received: " <<
totalsend <<
"=" <<
totrecv <<
" , " <<
newsize <<
"=" <<
size << std::endl;
900 for(
int i=0; i<nprocs; ++i)
909 for(
int i=0; i<nprocs; ++i)
927template <
class IT,
class NT>
937template <
class IT,
class NT>
942 std::cout <<
"Grids are not comparable for dense vector subsref" << std::endl;
949 std::vector< std::vector< IT > >
data_req(nprocs);
950 std::vector< std::vector< IT > >
revr_map(nprocs);
961 int *
sendcnt =
new int[nprocs];
962 int *
sdispls =
new int[nprocs];
963 for(
int i=0; i<nprocs; ++i)
966 int *
rdispls =
new int[nprocs];
967 int *
recvcnt =
new int[nprocs];
971 for(
int i=0; i<nprocs-1; ++i)
977 for(
int i=0; i<nprocs; ++i)
980 std::vector<IT>().swap(
data_req[i]);
984 for(
int i=0; i<nprocs; ++i)
987 std::vector<IT>().swap(
revr_map[i]);
999 for(
int i=0; i<nprocs; ++i)
1015 for(
int i=0; i<nprocs; ++i)
1027template <
class IT,
class NT>
1032 std::cout <<
"As a whole, " <<
vectorname <<
" has length " <<
totl << std::endl;
1039template <
class IT,
class NT>
1044 if(glen != other.glen)
1046 std::cerr <<
"Vector dimensions don't match (" << glen <<
" vs " << other.glen <<
") for FullyDistVec::Set\n";
1054#pragma omp parallel for
1058 arr[other.ind[i]] = other.num[i];
1064 std::cout <<
"Grids are not comparable for Set" << std::endl;
1074template <
class IT,
class NT>
1075template <
class NT1,
typename _BinaryOperationIdx,
typename _BinaryOperationVal>
1080 std::cout <<
"Grids are not comparable for GSet" << std::endl;
1094 std::vector< std::vector< NT > >
datsent(nprocs);
1095 std::vector< std::vector< IT > >
indsent(nprocs);
1114 for(
int j = 0;
j <
datsent[myrank].size(); ++
j)
1123 for(
int i=0; i<nprocs; ++i)
1146template <
class IT,
class NT>
1147template <
class NT1,
typename _BinaryOperationIdx>
1152 std::cout <<
"Grids are not comparable for GGet" << std::endl;
1162 std::vector< std::vector< NT > >
spIdx(nprocs);
1163 std::vector< std::vector< IT > >
indsent(nprocs);
1191 for(
int j = 0;
j <
indsent[myrank].size(); ++
j)
1199 for(
int i=0; i<nprocs; ++i)
std::shared_ptr< CommGrid > commGrid
FullyDistVec< IT, IT > FindInds(_Predicate pred) const
Return the indices where pred is true.
std::ifstream & ReadDistribute(std::ifstream &infile, int master, HANDLER handler)
NT Reduce(_BinaryOperation __binary_op, NT identity) const
friend FullyDistSpVec< IU, typename promote_trait< NU1, NU2 >::T_promote > EWiseApply(const FullyDistSpVec< IU, NU1 > &V, const FullyDistVec< IU, NU2 > &W, _BinaryOperation _binary_op, typename promote_trait< NU1, NU2 >::T_promote zero)
FullyDistVec< IT, NT > operator()(const FullyDistVec< IT, IT > &ri) const
FullyDistSpVec< IT, NT > Find(_Predicate pred) const
Return the elements for which pred is true.
bool operator==(const FullyDistVec< IT, NT > &rhs) const
void PrintInfo(std::string vectorname) const
void SaveGathered(std::ofstream &outfile, int master, HANDLER handler, bool printProcSplits=false)
FullyDistVec< IT, NT > & operator-=(const FullyDistSpVec< IT, NT > &rhs)
void SetElement(IT indx, NT numx)
void iota(IT globalsize, NT first)
void Set(const FullyDistSpVec< IT, NT > &rhs)
friend class FullyDistVec
FullyDistSpVec< IT, NT > GGet(const FullyDistSpVec< IT, NT1 > &spVec, _BinaryOperationIdx __binopIdx, NT nullValue)
IT Count(_Predicate pred) const
Return the number of elements for which pred is true.
FullyDistVec< IT, NT > & operator+=(const FullyDistSpVec< IT, NT > &rhs)
void SelectCandidates(double nver)
ABAB: Put concept check, NT should be integer for this to make sense.
void Apply(_UnaryOperation __unary_op)
void EWiseOut(const FullyDistVec< IT, NT > &rhs, _BinaryOperation __binary_op, FullyDistVec< IT, OUT > &result)
void GSet(const FullyDistSpVec< IT, NT1 > &spVec, _BinaryOperationIdx __binopIdx, _BinaryOperationVal __binopVal, MPI_Win win)
NT GetElement(IT indx) const
FullyDistVec< IT, NT > & operator=(const FullyDistVec< ITRHS, NTRHS > &rhs)
std::pair< IT, NT > MinElement() const
FullyDistVec< IT, IT > sort()
static void iota(_ForwardIter __first, _ForwardIter __last, T __val)
static void Print(const std::string &s)
static void MemoryEfficientPSort(std::pair< KEY, VAL > *array, IT length, IT *dist, const MPI_Comm &comm)