本文整理汇总了C++中DistMultiVec::ProcessQueues方法的典型用法代码示例。如果您正苦于以下问题:C++ DistMultiVec::ProcessQueues方法的具体用法?C++ DistMultiVec::ProcessQueues怎么用?C++ DistMultiVec::ProcessQueues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DistMultiVec
的用法示例。
在下文中一共展示了DistMultiVec::ProcessQueues方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
//.........这里部分代码省略.........
const DistMultiVec<Real>& b,
Real lambda,
DistMultiVec<Real>& x,
const qp::affine::Ctrl<Real>& ctrl )
{
DEBUG_CSE
const Int m = A.Height();
const Int n = A.Width();
mpi::Comm comm = A.Comm();
DistSparseMatrix<Real> Q(comm), AHat(comm), G(comm);
DistMultiVec<Real> c(comm), h(comm);
// Q := | 0 0 0 |
// | 0 0 0 |
// | 0 0 I |
// ==============
Zeros( Q, 2*n+m, 2*n+m );
{
Int numLocalUpdates = 0;
for( Int iLoc=0; iLoc<Q.LocalHeight(); ++iLoc )
if( Q.GlobalRow(iLoc) >= 2*n )
++numLocalUpdates;
Q.Reserve( numLocalUpdates );
for( Int iLoc=0; iLoc<Q.LocalHeight(); ++iLoc )
if( Q.GlobalRow(iLoc) >= 2*n )
Q.QueueLocalUpdate( iLoc, Q.GlobalRow(iLoc), Real(1) );
Q.ProcessLocalQueues();
}
// c := lambda*[1;1;0]
// ===================
Zeros( c, 2*n+m, 1 );
auto& cLoc = c.Matrix();
for( Int iLoc=0; iLoc<c.LocalHeight(); ++iLoc )
if( c.GlobalRow(iLoc) < 2*n )
cLoc(iLoc) = lambda;
// \hat A := [A, -A, I]
// ====================
// NOTE: Since A and \hat A are the same height and each distributed within
// columns, it is possible to form \hat A from A without communication
const Int numLocalEntriesA = A.NumLocalEntries();
Zeros( AHat, m, 2*n+m );
AHat.Reserve( 2*numLocalEntriesA+AHat.LocalHeight() );
for( Int e=0; e<numLocalEntriesA; ++e )
{
AHat.QueueUpdate( A.Row(e), A.Col(e), A.Value(e) );
AHat.QueueUpdate( A.Row(e), A.Col(e)+n, -A.Value(e) );
}
for( Int iLoc=0; iLoc<AHat.LocalHeight(); ++iLoc )
{
const Int i = AHat.GlobalRow(iLoc);
AHat.QueueLocalUpdate( iLoc, i+2*n, Real(1) );
}
AHat.ProcessLocalQueues();
// G := | -I 0 0 |
// | 0 -I 0 |
// ================
Zeros( G, 2*n, 2*n+m );
G.Reserve( G.LocalHeight() );
for( Int iLoc=0; iLoc<G.LocalHeight(); ++iLoc )
{
const Int i = G.GlobalRow(iLoc);
G.QueueLocalUpdate( iLoc, i, Real(-1) );
}
G.ProcessLocalQueues();
// h := 0
// ======
Zeros( h, 2*n, 1 );
// Solve the affine QP
// ===================
DistMultiVec<Real> xHat(comm), y(comm), z(comm), s(comm);
QP( Q, AHat, G, b, c, h, xHat, y, z, s, ctrl );
// x := u - v
// ==========
Zeros( x, n, 1 );
Int numRemoteUpdates = 0;
for( Int iLoc=0; iLoc<xHat.LocalHeight(); ++iLoc )
if( xHat.GlobalRow(iLoc) < 2*n )
++numRemoteUpdates;
else
break;
x.Reserve( numRemoteUpdates );
auto& xHatLoc = xHat.LockedMatrix();
for( Int iLoc=0; iLoc<xHat.LocalHeight(); ++iLoc )
{
const Int i = xHat.GlobalRow(iLoc);
if( i < n )
x.QueueUpdate( i, 0, xHatLoc(iLoc) );
else if( i < 2*n )
x.QueueUpdate( i-n, 0, -xHatLoc(iLoc) );
else
break;
}
x.ProcessQueues();
}