void Helmholtz( DistSparseMatrix<F>& H, Int nx, Int ny, F shift ) { DEBUG_CSE typedef Base<F> Real; const Int n = nx*ny; Zeros( H, n, n ); const Real hxInv = nx+1; const Real hyInv = ny+1; const Real hxInvSquared = hxInv*hxInv; const Real hyInvSquared = hyInv*hyInv; const F mainTerm = 2*(hxInvSquared+hyInvSquared) - shift; const Int localHeight = H.LocalHeight(); H.Reserve( 5*localHeight ); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) { const Int i = H.GlobalRow(iLoc); const Int x = i % nx; const Int y = i/nx; H.QueueUpdate( i, i, mainTerm ); if( x != 0 ) H.QueueUpdate( i, i-1, -hxInvSquared ); if( x != nx-1 ) H.QueueUpdate( i, i+1, -hxInvSquared ); if( y != 0 ) H.QueueUpdate( i, i-nx, -hyInvSquared ); if( y != ny-1 ) H.QueueUpdate( i, i+nx, -hyInvSquared ); } H.ProcessQueues(); }
void ShiftDiagonal ( DistSparseMatrix<T>& A, S alphaPre, Int offset, bool existingDiag ) { EL_DEBUG_CSE const Int mLocal = A.LocalHeight(); const Int n = A.Width(); const T alpha = T(alphaPre); if( existingDiag ) { T* valBuf = A.ValueBuffer(); for( Int iLoc=0; iLoc<mLocal; ++iLoc ) { const Int i = A.GlobalRow(iLoc); const Int e = A.Offset( iLoc, i+offset ); valBuf[e] += alpha; } } else { A.Reserve( mLocal ); for( Int iLoc=0; iLoc<mLocal; ++iLoc ) { const Int i = A.GlobalRow(iLoc); if( i+offset >= 0 && i+offset < n ) A.QueueLocalUpdate( iLoc, i+offset, alpha ); } A.ProcessLocalQueues(); } }
void Fill( DistSparseMatrix<T>& A, T alpha ) { EL_DEBUG_CSE const Int m = A.Height(); const Int n = A.Width(); A.Resize( m, n ); Zero( A ); if( alpha != T(0) ) { const Int localHeight = A.LocalHeight(); A.Reserve( localHeight*n ); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) for( Int j=0; j<n; ++j ) A.QueueLocalUpdate( iLoc, j, alpha ); A.ProcessLocalQueues(); } }
void RowMaxNorms( const DistSparseMatrix<F>& A, DistMultiVec<Base<F>>& norms ) { DEBUG_CSE typedef Base<F> Real; const Int localHeight = A.LocalHeight(); const F* valBuf = A.LockedValueBuffer(); const Int* offsetBuf = A.LockedOffsetBuffer(); norms.SetComm( A.Comm() ); norms.Resize( A.Height(), 1 ); auto& normsLoc = norms.Matrix(); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) { Real rowMax = 0; const Int offset = offsetBuf[iLoc]; const Int numConn = offsetBuf[iLoc+1] - offset; for( Int e=offset; e<offset+numConn; ++e ) rowMax = Max(rowMax,Abs(valBuf[e])); normsLoc(iLoc) = rowMax; } }
void RowTwoNorms( const DistSparseMatrix<F>& A, DistMultiVec<Base<F>>& norms ) { DEBUG_CSE typedef Base<F> Real; const Int localHeight = A.LocalHeight(); const F* valBuf = A.LockedValueBuffer(); const Int* offsetBuf = A.LockedOffsetBuffer(); norms.SetComm( A.Comm() ); norms.Resize( A.Height(), 1 ); auto& normLoc = norms.Matrix(); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) { Real scale = 0; Real scaledSquare = 1; const Int offset = offsetBuf[iLoc]; const Int numConn = offsetBuf[iLoc+1] - offset; for( Int e=offset; e<offset+numConn; ++e ) UpdateScaledSquare( valBuf[e], scale, scaledSquare ); normLoc(iLoc) = scale*Sqrt(scaledSquare); } }
void Helmholtz( DistSparseMatrix<F>& H, Int n, F shift ) { DEBUG_CSE typedef Base<F> Real; Zeros( H, n, n ); const Real hInv = n+1; const Real hInvSquared = hInv*hInv; const F mainTerm = 2*hInvSquared - shift; const Int localHeight = H.LocalHeight(); H.Reserve( 3*localHeight ); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) { const Int i = H.GlobalRow(iLoc); H.QueueUpdate( i, i, mainTerm ); if( i != 0 ) H.QueueUpdate( i, i-1, -hInvSquared ); if( i != n-1 ) H.QueueUpdate( i, i+1, -hInvSquared ); } H.ProcessQueues(); }
void JordanCholesky( DistSparseMatrix<T>& A, Int n ) { DEBUG_ONLY(CSE cse("JordanCholesky")) Zeros( A, n, n ); const Int localHeight = A.LocalHeight(); A.Reserve( 3*localHeight ); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) { const Int i = A.GlobalRow(iLoc); if( i == 0 ) A.QueueUpdate( i, i, T(1) ); else A.QueueUpdate( i, i, T(5) ); if( i > 0 ) A.QueueUpdate( i, i-1, T(2) ); if( i < n-1 ) A.QueueUpdate( i, i+1, T(2) ); } A.ProcessQueues(); }