本文整理汇总了C++中typenamestd::vector::rbegin方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::rbegin方法的具体用法?C++ vector::rbegin怎么用?C++ vector::rbegin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typenamestd::vector
的用法示例。
在下文中一共展示了vector::rbegin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generatePartitionSizeHistogram
void generatePartitionSizeHistogram(typename std::vector<T>& localVector, std::string filename, MPI_Comm comm = MPI_COMM_WORLD)
{
/*
* Approach :
* 1. Do a global sort by keyLayer (Partition id).
* 2. Compute the information Partition_Id:Size for boundary partitions (Avoid duplication).
* 3. Do an all_gather of boundary values plugged with ranks.
* 4. All boundary partitions should be owned by minimum rank that shares it.
* 5. Locally compute the largest partition size and do MPI_Allreduce
* with MPI_MAX.
* 6. Build the histogram locally.
* 7. Finally do MPI_Reduce over whole histogram to root node.
* 8. Write the output to file
*/
int p;
int rank;
MPI_Comm_size(comm, &p);
MPI_Comm_rank(comm, &rank);
static layer_comparator<keyLayer, T> pccomp;
//Sort the vector by each tuple's keyLayer element
mxx::sort(localVector.begin(), localVector.end(), pccomp, comm, false);
//Iterate over tuples to compute boundary information
bool iownLeftBucket, iownRightBucket, onlySingleLocalPartition;
//Type of tuple to communicate : (Partition Id, rank, size)
typedef std::tuple<uint32_t, int, uint64_t> tupletypeforbucketSize;
std::vector<tupletypeforbucketSize> toSend;
toSend.resize(2);
//Find the left most bucket
auto leftBucketRange = findRange(localVector.begin(), localVector.end(), *(localVector.begin()), pccomp);
std::get<0>(toSend[0]) = std::get<keyLayer>(*localVector.begin());
std::get<1>(toSend[0]) = rank;
std::get<2>(toSend[0]) = leftBucketRange.second - leftBucketRange.first;
//Find the right most bucket
auto rightBucketRange = findRange(localVector.rbegin(), localVector.rend(), *(localVector.rbegin()), pccomp);
std::get<0>(toSend[1]) = std::get<keyLayer>(*localVector.rbegin());
std::get<1>(toSend[1]) = rank;
std::get<2>(toSend[1]) = rightBucketRange.second - rightBucketRange.first;
//If we have only single partition, make sure we are not creating duplicates
if(std::get<0>(toSend[0]) == std::get<0>(toSend[1]))
{
//Make second send element's size zero
std::get<2>(toSend[1]) = 0;
onlySingleLocalPartition = true;
}
else
onlySingleLocalPartition = false;
//Gather all the boundary information
auto allBoundaryPartitionSizes = mxx::allgather_vectors(toSend, comm);
uint64_t leftBucketSize = 0;
uint64_t rightBucketSize = 0;
//Need to parse boundary information that matches the partitionIds we have
static layer_comparator<0, tupletypeforbucketSize> pccomp2;
auto leftBucketBoundaryRange = std::equal_range(allBoundaryPartitionSizes.begin(), allBoundaryPartitionSizes.end(), toSend[0], pccomp2);
//Check if this processor owns this bucket
if(std::get<1>(*(leftBucketBoundaryRange.first)) == rank)
{
iownLeftBucket = true;
for(auto it = leftBucketBoundaryRange.first; it != leftBucketBoundaryRange.second; it++)
{
leftBucketSize += std::get<2>(*it);
}
}
else
iownLeftBucket = false;
auto rightBucketBoundaryRange = std::equal_range(allBoundaryPartitionSizes.begin(), allBoundaryPartitionSizes.end(), toSend[1], pccomp2);
//Check if this processor owns right partition
if(std::get<1>(*rightBucketBoundaryRange.first) == rank && !onlySingleLocalPartition)
{
iownRightBucket = true;
for(auto it = rightBucketBoundaryRange.first; it != rightBucketBoundaryRange.second; it++)
{
rightBucketSize += std::get<2>(*it);
}
}
else
iownRightBucket = false;
//Map from partition size to count
typedef std::map <uint64_t, uint32_t> MapType;
MapType localHistMap;
for(auto it = localVector.begin(); it!= localVector.end();) // iterate over all segments.
{
auto innerLoopBound = findRange(it, localVector.end(), *it, pccomp);
//Left most bucket
//.........这里部分代码省略.........