本文整理汇总了C++中mpi::Intracomm::Scatterv方法的典型用法代码示例。如果您正苦于以下问题:C++ Intracomm::Scatterv方法的具体用法?C++ Intracomm::Scatterv怎么用?C++ Intracomm::Scatterv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpi::Intracomm
的用法示例。
在下文中一共展示了Intracomm::Scatterv方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: neighbors
ifstream& FullyDistSpVec<IT,NT>::ReadDistribute (ifstream& infile, int master)
{
IT total_nnz;
MPI::Intracomm World = commGrid->GetWorld();
int neighs = World.Get_size(); // number of neighbors (including oneself)
int buffperneigh = MEMORYINBYTES / (neighs * (sizeof(IT) + sizeof(NT)));
int * displs = new int[neighs];
for (int i=0; i<neighs; ++i)
displs[i] = i*buffperneigh;
int * curptrs = NULL;
int recvcount = 0;
IT * inds = NULL;
NT * vals = NULL;
int rank = World.Get_rank();
if(rank == master) // 1 processor only
{
inds = new IT [ buffperneigh * neighs ];
vals = new NT [ buffperneigh * neighs ];
curptrs = new int[neighs];
fill_n(curptrs, neighs, 0); // fill with zero
if (infile.is_open())
{
infile.clear();
infile.seekg(0);
infile >> glen >> total_nnz;
World.Bcast(&glen, 1, MPIType<IT>(), master);
IT tempind;
NT tempval;
double loadval;
IT cnz = 0;
while ( (!infile.eof()) && cnz < total_nnz)
{
infile >> tempind;
//infile >> tempval;
infile >> loadval;
tempval = static_cast<NT>(loadval);
tempind--;
IT locind;
int rec = Owner(tempind, locind); // recipient (owner) processor
inds[ rec * buffperneigh + curptrs[rec] ] = locind;
vals[ rec * buffperneigh + curptrs[rec] ] = tempval;
++ (curptrs[rec]);
if(curptrs[rec] == buffperneigh || (cnz == (total_nnz-1)) ) // one buffer is full, or file is done !
{
// first, send the receive counts ...
World.Scatter(curptrs, 1, MPI::INT, &recvcount, 1, MPI::INT, master);
// generate space for own recv data ... (use arrays because vector<bool> is cripled, if NT=bool)
IT * tempinds = new IT[recvcount];
NT * tempvals = new NT[recvcount];
// then, send all buffers that to their recipients ...
World.Scatterv(inds, curptrs, displs, MPIType<IT>(), tempinds, recvcount, MPIType<IT>(), master);
World.Scatterv(vals, curptrs, displs, MPIType<NT>(), tempvals, recvcount, MPIType<NT>(), master);
// now push what is ours to tuples
for(IT i=0; i< recvcount; ++i)
{
ind.push_back( tempinds[i] ); // already offset'd by the sender
num.push_back( tempvals[i] );
}
// reset current pointers so that we can reuse {inds,vals} buffers
fill_n(curptrs, neighs, 0);
DeleteAll(tempinds, tempvals);
}
++ cnz;
}
assert (cnz == total_nnz);
// Signal the end of file to other processors along the diagonal
fill_n(curptrs, neighs, numeric_limits<int>::max());
World.Scatter(curptrs, 1, MPI::INT, &recvcount, 1, MPI::INT, master);
}