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)]);
87template <
class IT,
class NT>
92 int nprocs = commGrid->GetSize();
93 int rank = commGrid->GetRank();
117 int * sdispls =
new int[
nprocs];
118 int * rdispls =
new int[
nprocs];
121 for(
int i=0; i<
nprocs-1; ++i)
123 sdispls[i+1] = sdispls[i] +
sendcnt[i];
124 rdispls[i+1] = rdispls[i] +
recvcnt[i];
137template <
class IT,
class NT>
157template <
class IT,
class NT>
158template <
typename _BinaryOperation>
169template <
class IT,
class NT>
170template <
typename OUT,
typename _BinaryOperation,
typename _UnaryOperation>
178 typename std::vector< NT >::const_iterator
iter = arr.begin();
181 while (
iter < arr.end())
195template<
class IT,
class NT>
211 for(
int i=0; i<
length; ++i)
215 for(
int i=0; i<
length; ++i)
223template <
class IT,
class NT>
224template <
class ITRHS,
class NTRHS>
227 if(
static_cast<const void*
>(
this) !=
static_cast<const void*
>(&
rhs))
230 glen =
static_cast<IT>(
rhs.glen);
233 arr.resize(
rhs.arr.size(),
NT());
236 arr[i] =
static_cast<NT>(
rhs.arr[
static_cast<ITRHS>(i)]);
242template <
class IT,
class NT>
253template <
class IT,
class NT>
257 arr.resize(
rhs.MyLocLength());
258 std::fill(arr.begin(), arr.end(),
NT());
265 arr[
rhs.ind[i]] =
rhs.num[i];
278template <
class IT,
class NT>
283 #pragma omp parallel for
287 if(arr[
rhs.ind[i]] ==
NT())
288 arr[
rhs.ind[i]] =
rhs.num[i];
290 arr[
rhs.ind[i]] +=
rhs.num[i];
297template <
class IT,
class NT>
303 arr[
rhs.ind[i]] -=
rhs.num[i];
313template <
class IT,
class NT>
314template <
typename _BinaryOperation>
317 std::transform ( arr.begin(), arr.end(),
rhs.arr.begin(), arr.begin(),
__binary_op );
324template <
class IT,
class NT>
325template <
typename _BinaryOperation,
typename OUT>
332template <
class IT,
class NT>
339 std::cout <<
"Grids are not comparable elementwise addition" << std::endl;
344 EWise(
rhs, std::plus<NT>());
350template <
class IT,
class NT>
357 std::cout <<
"Grids are not comparable elementwise addition" << std::endl;
362 EWise(
rhs, std::minus<NT>());
368template <
class IT,
class NT>
376 return static_cast<bool>(
whole);
379template <
class IT,
class NT>
380template <
typename _Predicate>
391template <
class IT,
class NT>
392template <
typename _Predicate>
414 found.glen = std::accumulate(dist, dist+
nprocs,
static_cast<IT>(0));
431 int * sdispls =
new int[
nprocs];
432 int * rdispls =
new int[
nprocs];
435 for(
int i=0; i<
nprocs-1; ++i)
437 sdispls[i+1] = sdispls[i] +
sendcnt[i];
438 rdispls[i+1] = rdispls[i] +
recvcnt[i];
455template <
class IT,
class NT>
456template <
typename _Predicate>
460 size_t size = arr.size();
461 for(
size_t i=0; i<
size; ++i)
466 found.num.push_back(arr[i]);
475template <
class IT,
class NT>
479 size_t size = arr.size();
480 for(
size_t i=0; i<
size; ++i)
485 found.num.push_back(val);
493template <
class IT,
class NT>
494template <
class HANDLER>
504template <
class IT,
class NT>
505template <
class HANDLER>
512template <
class IT,
class NT>
519 std::cout <<
"FullyDistVec::SetElement can't be called on an empty vector." << std::endl;
526 if (
locind > (LocArrSize() -1))
528 std::cout <<
"FullyDistVec::SetElement cannot expand array" << std::endl;
532 std::cout <<
"FullyDistVec::SetElement local index < 0" << std::endl;
541template <
class IT,
class NT>
550 std::cout <<
"FullyDistVec::GetElement can't be called on an empty vector." << std::endl;
558 if (
locind > (LocArrSize() -1))
560 std::cout <<
"FullyDistVec::GetElement local index > size" << std::endl;
566 std::cout <<
"FullyDistVec::GetElement local index < 0" << std::endl;
579template <
class IT,
class NT>
587 char _fn[] =
"temp_fullydistvec";
596 IT count = LocArrSize();
608 std::cerr <<
"Problem reading binary input file\n";
614 for(
int i=0; i<
nprocs; ++i)
618 if (
result != (
unsigned)
counts[i]) { std::cout <<
"Error in fread, only " <<
result <<
" entries read" << std::endl; }
620 std::cout <<
"Elements stored on proc " << i <<
": {" ;
623 std::cout << data[
j] <<
",";
625 std::cout <<
"}" << std::endl;
632template <
class IT,
class NT>
633template <
typename _UnaryOperation,
typename IRRELEVANT_NT>
636 typename std::vector< IT >::const_iterator
miter =
mask.ind.begin();
644template <
class IT,
class NT>
645template <
typename _BinaryOperation,
typename _BinaryPredicate,
class NT2>
650 if(glen != other.glen)
652 std::ostringstream
outs;
653 outs <<
"Vector dimensions don't match (" << glen <<
" vs " << other.glen <<
") for FullyDistVec::EWiseApply\n";
659 typename std::vector< NT >::iterator
thisIter = arr.begin();
660 typename std::vector< NT2 >::const_iterator
otherIter = other.arr.begin();
672 std::ostringstream
outs;
673 outs <<
"Grids are not comparable for FullyDistVec<IT,NT>::EWiseApply" << std::endl;
682template <
class IT,
class NT>
683template <
typename _BinaryOperation,
typename _BinaryPredicate,
class NT2>
688 if(glen != other.glen)
690 std::cerr <<
"Vector dimensions don't match (" << glen <<
" vs " << other.glen <<
") for FullyDistVec::EWiseApply\n";
695 typename std::vector< IT >::const_iterator
otherInd = other.ind.begin();
696 typename std::vector< NT2 >::const_iterator
otherNum = other.num.begin();
727#pragma omp parallel for
731 if (
_do_op(arr[other.ind[i]], other.num[i],
false,
false))
732 arr[other.ind[i]] =
__binary_op(arr[other.ind[i]], other.num[i],
false,
false);
739 std::cout <<
"Grids are not comparable elementwise apply" << std::endl;
745template <
class IT,
class NT>
750 IT nnz = LocArrSize();
751 std::pair<NT,IT> *
vecpair =
new std::pair<NT,IT>[nnz];
759 for(
IT i=0; i< nnz; ++i)
766 std::vector< IT >
narr(nnz);
767 for(
IT i=0; i< nnz; ++i)
782template <
class IT,
class NT>
797#ifdef COMBBLAS_LEGACY
798 std::pair<double,NT> *
vecpair =
new std::pair<double,NT>[
size];
802 for(
int i=0; i<
size; ++i)
815 for(
int i=0; i<
size; ++i)
822 int * sdispls =
new int[
nprocs];
825 int * rdispls =
new int[
nprocs];
830 for(
int i=0; i<
nprocs-1; ++i)
832 sdispls[i+1] = sdispls[i] +
sendcnt[i];
833 rdispls[i+1] = rdispls[i] +
recvcnt[i];
836 if(
totrecv > std::numeric_limits<int>::max())
838 std::cout <<
"COMBBLAS_WARNING: total data to receive exceeds max int: " <<
totrecv << std::endl;
840 std::vector<NT>().swap(arr);
843 for(
int i=0; i<
nprocs; ++i)
851 std::default_random_engine
gen(seed);
872 for(
int i=0; i<
nprocs-1; ++i)
874 sdispls[i+1] = sdispls[i] +
sendcnt[i];
875 rdispls[i+1] = rdispls[i] +
recvcnt[i];
878 if(
newsize > std::numeric_limits<int>::max())
880 std::cout <<
"COMBBLAS_WARNING: total data to receive exceeds max int: " <<
newsize << std::endl;
886 std::cout <<
"COMBBLAS_WARNING: sending different sized data than received: " <<
totalsend <<
"=" <<
totrecv <<
" , " <<
newsize <<
"=" <<
size << std::endl;
888 for(
int i=0; i<
nprocs; ++i)
897 for(
int i=0; i<
nprocs; ++i)
915template <
class IT,
class NT>
925template <
class IT,
class NT>
930 std::cout <<
"Grids are not comparable for dense vector subsref" << std::endl;
950 int * sdispls =
new int[
nprocs];
951 for(
int i=0; i<
nprocs; ++i)
954 int * rdispls =
new int[
nprocs];
959 for(
int i=0; i<
nprocs-1; ++i)
961 sdispls[i+1] = sdispls[i] +
sendcnt[i];
962 rdispls[i+1] = rdispls[i] +
recvcnt[i];
965 for(
int i=0; i<
nprocs; ++i)
968 std::vector<IT>().swap(
data_req[i]);
972 for(
int i=0; i<
nprocs; ++i)
975 std::vector<IT>().swap(
revr_map[i]);
987 for(
int i=0; i<
nprocs; ++i)
989 for(
int j = rdispls[i];
j < rdispls[i] +
recvcnt[i]; ++
j)
1003 for(
int i=0; i<
nprocs; ++i)
1005 for(
int j=sdispls[i];
j< sdispls[i]+
sendcnt[i]; ++
j)
1015template <
class IT,
class NT>
1020 std::cout <<
"As a whole, " <<
vectorname <<
" has length " <<
totl << std::endl;
1027template <
class IT,
class NT>
1032 if(glen != other.glen)
1034 std::cerr <<
"Vector dimensions don't match (" << glen <<
" vs " << other.glen <<
") for FullyDistVec::Set\n";
1042#pragma omp parallel for
1046 arr[other.ind[i]] = other.num[i];
1052 std::cout <<
"Grids are not comparable for Set" << std::endl;
1062template <
class IT,
class NT>
1063template <
class NT1,
typename _BinaryOperationIdx,
typename _BinaryOperationVal>
1068 std::cout <<
"Grids are not comparable for GSet" << std::endl;
1102 for(
int j = 0;
j <
datsent[myrank].size(); ++
j)
1111 for(
int i=0; i<
nprocs; ++i)
1134template <
class IT,
class NT>
1135template <
class NT1,
typename _BinaryOperationIdx>
1140 std::cout <<
"Grids are not comparable for GGet" << std::endl;
1179 for(
int j = 0;
j <
indsent[myrank].size(); ++
j)
1187 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)