本文整理匯總了C++中DistMatrix::Buffer方法的典型用法代碼示例。如果您正苦於以下問題:C++ DistMatrix::Buffer方法的具體用法?C++ DistMatrix::Buffer怎麽用?C++ DistMatrix::Buffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DistMatrix
的用法示例。
在下文中一共展示了DistMatrix::Buffer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: file
inline void
Binary( DistMatrix<T,STAR,STAR>& A, const std::string filename )
{
DEBUG_ONLY(CallStackEntry cse("read::Binary"))
std::ifstream file( filename.c_str(), std::ios::binary );
if( !file.is_open() )
RuntimeError("Could not open ",filename);
Int height, width;
file >> height;
file >> width;
const Int numBytes = FileSize( file );
const Int metaBytes = 2*sizeof(Int);
const Int dataBytes = height*width*sizeof(T);
const Int numBytesExp = metaBytes + dataBytes;
if( numBytes != numBytesExp )
RuntimeError
("Expected file to be ",numBytesExp," bytes but found ",numBytes);
A.Resize( height, width );
if( A.Height() == A.LDim() )
file.read( (char*)A.Buffer(), height*width*sizeof(T) );
else
for( Int j=0; j<width; ++j )
file.read( (char*)A.Buffer(0,j), height*sizeof(T) );
}
示例2: file
inline void
BinaryFlat
( DistMatrix<T,U,V>& A, Int height, Int width, const std::string filename )
{
DEBUG_ONLY(CallStackEntry cse("read::BinaryFlat"))
std::ifstream file( filename.c_str(), std::ios::binary );
if( !file.is_open() )
RuntimeError("Could not open ",filename);
const Int numBytes = FileSize( file );
const Int numBytesExp = height*width*sizeof(T);
if( numBytes != numBytesExp )
RuntimeError
("Expected file to be ",numBytesExp," bytes but found ",numBytes);
A.Resize( height, width );
if( U == A.UGath && V == A.VGath )
{
if( A.CrossRank() == A.Root() )
{
if( A.Height() == A.LDim() )
file.read( (char*)A.Buffer(), height*width*sizeof(T) );
else
for( Int j=0; j<width; ++j )
file.read( (char*)A.Buffer(0,j), height*sizeof(T) );
}
}
else if( U == A.UGath )
{
const Int localWidth = A.LocalWidth();
for( Int jLoc=0; jLoc<localWidth; ++jLoc )
{
const Int j = A.GlobalCol(jLoc);
const Int localIndex = j*height;
const std::streamoff pos = localIndex*sizeof(T);
file.seekg( pos );
file.read( (char*)A.Buffer(0,jLoc), height*sizeof(T) );
}
}
else
{
const Int localHeight = A.LocalHeight();
const Int localWidth = A.LocalWidth();
for( Int jLoc=0; jLoc<localWidth; ++jLoc )
{
const Int j = A.GlobalCol(jLoc);
for( Int iLoc=0; iLoc<localHeight; ++iLoc )
{
const Int i = A.GlobalRow(iLoc);
const Int localIndex = i+j*height;
const std::streamoff pos = localIndex*sizeof(T);
file.seekg( pos );
file.read( (char*)A.Buffer(iLoc,jLoc), sizeof(T) );
}
}
}
}
示例3: AssertSameGrids
void Scatter
( const DistMatrix<T,CIRC,CIRC>& A,
DistMatrix<T,STAR,STAR>& B )
{
DEBUG_CSE
AssertSameGrids( A, B );
const Int height = A.Height();
const Int width = A.Width();
B.Resize( height, width );
if( B.Participating() )
{
const Int pkgSize = mpi::Pad( height*width );
vector<T> buffer;
FastResize( buffer, pkgSize );
// Pack
if( A.Participating() )
util::InterleaveMatrix
( height, width,
A.LockedBuffer(), 1, A.LDim(),
buffer.data(), 1, height );
// Broadcast from the process that packed
mpi::Broadcast( buffer.data(), pkgSize, A.Root(), A.CrossComm() );
// Unpack
util::InterleaveMatrix
( height, width,
buffer.data(), 1, height,
B.Buffer(), 1, B.LDim() );
}
}
示例4: PushCallStack
inline void
MakeTriangular( UpperOrLower uplo, DistMatrix<T,U,V>& A )
{
#ifndef RELEASE
PushCallStack("MakeTriangular");
#endif
const int height = A.Height();
const int localHeight = A.LocalHeight();
const int localWidth = A.LocalWidth();
const int colShift = A.ColShift();
const int rowShift = A.RowShift();
const int colStride = A.ColStride();
const int rowStride = A.RowStride();
T* buffer = A.Buffer();
const int ldim = A.LDim();
if( uplo == LOWER )
{
#ifdef HAVE_OPENMP
#pragma omp parallel for
#endif
for( int jLocal=0; jLocal<localWidth; ++jLocal )
{
const int j = rowShift + jLocal*rowStride;
const int lastZeroRow = j-1;
if( lastZeroRow >= 0 )
{
const int boundary = std::min( lastZeroRow+1, height );
const int numZeroRows =
Length_( boundary, colShift, colStride );
MemZero( &buffer[jLocal*ldim], numZeroRows );
}
}
}
else
{
#ifdef HAVE_OPENMP
#pragma omp parallel for
#endif
for( int jLocal=0; jLocal<localWidth; ++jLocal )
{
const int j = rowShift + jLocal*rowStride;
const int firstZeroRow = j+1;
const int numNonzeroRows =
Length_(firstZeroRow,colShift,colStride);
if( numNonzeroRows < localHeight )
{
T* col = &buffer[numNonzeroRows+jLocal*ldim];
MemZero( col, localHeight-numNonzeroRows );
}
}
}
#ifndef RELEASE
PopCallStack();
#endif
}
示例5: AssertScaLAPACKSupport
void ScaLAPACKHelper
( DistMatrix<F,MC,MR,BLOCK>& A,
DistMatrix<F,MR,STAR,BLOCK>& householderScalars )
{
EL_DEBUG_CSE
AssertScaLAPACKSupport();
#ifdef EL_HAVE_SCALAPACK
const Int m = A.Height();
const Int n = A.Width();
const Int minDim = Min(m,n);
householderScalars.AlignWith( A );
householderScalars.Resize( minDim, 1 );
auto descA = FillDesc( A );
scalapack::QR
( m, n, A.Buffer(), descA.data(), householderScalars.Buffer() );
#endif
}
示例6: cse
void UpdateWithLocalData
( T alpha, const AbstractDistMatrix<T>& A, DistMatrix<T,STAR,STAR>& B )
{
DEBUG_ONLY(CSE cse("axpy::util::UpdateWithLocalData"))
axpy::util::InterleaveMatrixUpdate
( alpha, A.LocalHeight(), A.LocalWidth(),
A.LockedBuffer(),
1, A.LDim(),
B.Buffer(A.ColShift(),A.RowShift()),
A.ColStride(), A.RowStride()*B.LDim() );
}
示例7: AssertSameGrids
void AllGather
( const DistMatrix<T, U, V >& A,
DistMatrix<T,Collect<U>(),Collect<V>()>& B )
{
EL_DEBUG_CSE
AssertSameGrids( A, B );
const Int height = A.Height();
const Int width = A.Width();
B.SetGrid( A.Grid() );
B.Resize( height, width );
if( A.Participating() )
{
if( A.DistSize() == 1 )
{
Copy( A.LockedMatrix(), B.Matrix() );
}
else
{
const Int colStride = A.ColStride();
const Int rowStride = A.RowStride();
const Int distStride = colStride*rowStride;
const Int maxLocalHeight = MaxLength(height,colStride);
const Int maxLocalWidth = MaxLength(width,rowStride);
const Int portionSize = mpi::Pad( maxLocalHeight*maxLocalWidth );
vector<T> buf;
FastResize( buf, (distStride+1)*portionSize );
T* sendBuf = &buf[0];
T* recvBuf = &buf[portionSize];
// Pack
util::InterleaveMatrix
( A.LocalHeight(), A.LocalWidth(),
A.LockedBuffer(), 1, A.LDim(),
sendBuf, 1, A.LocalHeight() );
// Communicate
mpi::AllGather
( sendBuf, portionSize, recvBuf, portionSize, A.DistComm() );
// Unpack
util::StridedUnpack
( height, width,
A.ColAlign(), colStride,
A.RowAlign(), rowStride,
recvBuf, portionSize,
B.Buffer(), B.LDim() );
}
}
if( A.Grid().InGrid() && A.CrossComm() != mpi::COMM_SELF )
El::Broadcast( B, A.CrossComm(), A.Root() );
}
示例8: entry
inline void HermitianSVD
( UpperOrLower uplo, DistMatrix<F>& A,
DistMatrix<BASE(F),VR,STAR>& s, DistMatrix<F>& U, DistMatrix<F>& V )
{
#ifndef RELEASE
CallStackEntry entry("HermitianSVD");
#endif
#ifdef HAVE_PMRRR
typedef BASE(F) R;
// Grab an eigenvalue decomposition of A
HermitianEig( uplo, A, s, V );
// Redistribute the singular values into an [MR,* ] distribution
const Grid& grid = A.Grid();
DistMatrix<R,MR,STAR> s_MR_STAR( grid );
s_MR_STAR.AlignWith( V.DistData() );
s_MR_STAR = s;
// Set the singular values to the absolute value of the eigenvalues
const Int numLocalVals = s.LocalHeight();
for( Int iLoc=0; iLoc<numLocalVals; ++iLoc )
{
const R sigma = s.GetLocal(iLoc,0);
s.SetLocal(iLoc,0,Abs(sigma));
}
// Copy V into U (flipping the sign as necessary)
U.AlignWith( V );
U.ResizeTo( V.Height(), V.Width() );
const Int localHeight = V.LocalHeight();
const Int localWidth = V.LocalWidth();
for( Int jLoc=0; jLoc<localWidth; ++jLoc )
{
const R sigma = s_MR_STAR.GetLocal( jLoc, 0 );
F* UCol = U.Buffer( 0, jLoc );
const F* VCol = V.LockedBuffer( 0, jLoc );
if( sigma >= 0 )
for( Int iLoc=0; iLoc<localHeight; ++iLoc )
UCol[iLoc] = VCol[iLoc];
else
for( Int iLoc=0; iLoc<localHeight; ++iLoc )
UCol[iLoc] = -VCol[iLoc];
}
#else
U = A;
MakeHermitian( uplo, U );
SVD( U, s, V );
#endif // ifdef HAVE_PMRRR
}
示例9: AssertScaLAPACKSupport
void QR
( DistMatrix<F,MC,MR,BLOCK>& A,
DistMatrix<F,MR,STAR,BLOCK>& phase )
{
DEBUG_CSE
AssertScaLAPACKSupport();
#ifdef EL_HAVE_SCALAPACK
const Int m = A.Height();
const Int n = A.Width();
const Int minDim = Min(m,n);
phase.AlignWith( A );
phase.Resize( minDim, 1 );
const int bHandle = blacs::Handle( A );
const int context = blacs::GridInit( bHandle, A );
auto descA = FillDesc( A, context );
scalapack::QR( m, n, A.Buffer(), descA.data(), phase.Buffer() );
blacs::FreeGrid( context );
blacs::FreeHandle( bHandle );
#endif
}
示例10: AssertSameGrids
void Filter
( const DistMatrix<T,Collect<U>(),Collect<V>()>& A,
DistMatrix<T, U, V >& B )
{
DEBUG_CSE
AssertSameGrids( A, B );
B.Resize( A.Height(), A.Width() );
if( !B.Participating() )
return;
const Int colShift = B.ColShift();
const Int rowShift = B.RowShift();
util::InterleaveMatrix
( B.LocalHeight(), B.LocalWidth(),
A.LockedBuffer(colShift,rowShift), B.ColStride(), B.RowStride()*A.LDim(),
B.Buffer(), 1, B.LDim() );
}
示例11: PushCallStack
inline void AddInLocalData
( const DistMatrix<F,VC,STAR>& X1, DistMatrix<F,STAR,STAR>& Z )
{
#ifndef RELEASE
PushCallStack("internal::AddInLocalData");
#endif
const int width = X1.Width();
const int localHeight = X1.LocalHeight();
const int stride = X1.Grid().Size();
const int offset = X1.ColShift();
for( int j=0; j<width; ++j )
{
F* ZColBuffer = Z.Buffer(0,j);
const F* X1ColBuffer = X1.LockedBuffer(0,j);
for( int iLocal=0; iLocal<localHeight; ++iLocal )
ZColBuffer[offset+stride*iLocal] += X1ColBuffer[iLocal];
}
#ifndef RELEASE
PopCallStack();
#endif
}
示例12: AccumulateRHS
void AccumulateRHS( const DistMatrix<F,VC,STAR>& X, DistMatrix<F,STAR,STAR>& Z )
{
const Int height = X.Height();
const Int width = X.Width();
Z.Empty();
Zeros( Z, height, width );
const Int localHeight = X.LocalHeight();
const Int colShift = X.ColShift();
const int commSize = X.Grid().Size();
const F* XBuffer = X.LockedBuffer();
F* ZBuffer = Z.Buffer();
const Int XLDim = X.LDim();
const Int ZLDim = Z.LDim();
for( Int iLoc=0; iLoc<localHeight; ++iLoc )
{
const Int i = colShift + iLoc*commSize;
for( Int j=0; j<width; ++j )
ZBuffer[i+j*ZLDim] = XBuffer[iLoc+j*XLDim];
}
mpi::AllReduce( ZBuffer, ZLDim*width, mpi::SUM, X.Grid().VCComm() );
}
示例13: Length
void InPlaceRedist
( DistMatrix<F>& paddedZ, Int rowAlign, const Base<F>* readBuffer )
{
typedef Base<F> Real;
const Grid& g = paddedZ.Grid();
const Int height = paddedZ.Height();
const Int width = paddedZ.Width();
const Int r = g.Height();
const Int c = g.Width();
const Int p = r * c;
const Int row = g.Row();
const Int col = g.Col();
const Int rowShift = paddedZ.RowShift();
const Int colAlign = paddedZ.ColAlign();
const Int localWidth = Length(width,g.VRRank(),rowAlign,p);
const Int maxHeight = MaxLength(height,r);
const Int maxWidth = MaxLength(width,p);
const Int portionSize = mpi::Pad( maxHeight*maxWidth );
// Allocate our send/recv buffers
std::vector<Real> buffer(2*r*portionSize);
Real* sendBuffer = &buffer[0];
Real* recvBuffer = &buffer[r*portionSize];
// Pack
OUTER_PARALLEL_FOR
for( Int k=0; k<r; ++k )
{
Real* data = &sendBuffer[k*portionSize];
const Int thisColShift = Shift(k,colAlign,r);
const Int thisLocalHeight = Length(height,thisColShift,r);
INNER_PARALLEL_FOR_COLLAPSE2
for( Int j=0; j<localWidth; ++j )
for( Int i=0; i<thisLocalHeight; ++i )
data[i+j*thisLocalHeight] =
readBuffer[thisColShift+i*r+j*height];
}
// Communicate
mpi::AllToAll
( sendBuffer, portionSize,
recvBuffer, portionSize, g.ColComm() );
// Unpack
const Int localHeight = Length(height,row,colAlign,r);
OUTER_PARALLEL_FOR
for( Int k=0; k<r; ++k )
{
const Real* data = &recvBuffer[k*portionSize];
const Int thisRank = col+k*c;
const Int thisRowShift = Shift(thisRank,rowAlign,p);
const Int thisRowOffset = (thisRowShift-rowShift) / c;
const Int thisLocalWidth = Length(width,thisRowShift,p);
INNER_PARALLEL_FOR
for( Int j=0; j<thisLocalWidth; ++j )
{
const Real* dataCol = &(data[j*localHeight]);
Real* thisCol = (Real*)paddedZ.Buffer(0,thisRowOffset+j*r);
if( IsComplex<F>::val )
{
for( Int i=0; i<localHeight; ++i )
{
thisCol[2*i] = dataCol[i];
thisCol[2*i+1] = 0;
}
}
else
{
MemCopy( thisCol, dataCol, localHeight );
}
}
}
}
示例14: cse
void Gather
( const ElementalMatrix<T>& A,
DistMatrix<T,CIRC,CIRC>& B )
{
DEBUG_ONLY(CSE cse("copy::Gather"))
AssertSameGrids( A, B );
if( A.DistSize() == 1 && A.CrossSize() == 1 )
{
B.Resize( A.Height(), A.Width() );
if( B.CrossRank() == B.Root() )
Copy( A.LockedMatrix(), B.Matrix() );
return;
}
const Int height = A.Height();
const Int width = A.Width();
B.SetGrid( A.Grid() );
B.Resize( height, width );
// Gather the colShifts and rowShifts
// ==================================
Int myShifts[2];
myShifts[0] = A.ColShift();
myShifts[1] = A.RowShift();
vector<Int> shifts;
const Int crossSize = B.CrossSize();
if( B.CrossRank() == B.Root() )
shifts.resize( 2*crossSize );
mpi::Gather( myShifts, 2, shifts.data(), 2, B.Root(), B.CrossComm() );
// Gather the payload data
// =======================
const bool irrelevant = ( A.RedundantRank()!=0 || A.CrossRank()!=A.Root() );
int totalSend = ( irrelevant ? 0 : A.LocalHeight()*A.LocalWidth() );
vector<int> recvCounts, recvOffsets;
if( B.CrossRank() == B.Root() )
recvCounts.resize( crossSize );
mpi::Gather( &totalSend, 1, recvCounts.data(), 1, B.Root(), B.CrossComm() );
int totalRecv = Scan( recvCounts, recvOffsets );
//vector<T> sendBuf(totalSend), recvBuf(totalRecv);
vector<T> sendBuf, recvBuf;
sendBuf.reserve( totalSend );
recvBuf.reserve( totalRecv );
if( !irrelevant )
copy::util::InterleaveMatrix
( A.LocalHeight(), A.LocalWidth(),
A.LockedBuffer(), 1, A.LDim(),
sendBuf.data(), 1, A.LocalHeight() );
mpi::Gather
( sendBuf.data(), totalSend,
recvBuf.data(), recvCounts.data(), recvOffsets.data(),
B.Root(), B.CrossComm() );
// Unpack
// ======
if( B.Root() == B.CrossRank() )
{
for( Int q=0; q<crossSize; ++q )
{
if( recvCounts[q] == 0 )
continue;
const Int colShift = shifts[2*q+0];
const Int rowShift = shifts[2*q+1];
const Int colStride = A.ColStride();
const Int rowStride = A.RowStride();
const Int localHeight = Length( height, colShift, colStride );
const Int localWidth = Length( width, rowShift, rowStride );
copy::util::InterleaveMatrix
( localHeight, localWidth,
&recvBuf[recvOffsets[q]], 1, localHeight,
B.Buffer(colShift,rowShift), colStride, rowStride*B.LDim() );
}
}
}
示例15: cse
//.........這裏部分代碼省略.........
// necessary processes at each step.
Int requiredMemory = 0;
if( inAGrid )
requiredMemory += maxSendSize;
if( inBGrid )
requiredMemory += maxSendSize;
vector<T> auxBuf( requiredMemory );
Int offset = 0;
T* sendBuf = &auxBuf[offset];
if( inAGrid )
offset += maxSendSize;
T* recvBuf = &auxBuf[offset];
Int recvRow = 0; // avoid compiler warnings...
if( inAGrid )
recvRow = Mod(Mod(A.ColRank()-colAlignA,colStrideA)+colAlign,colStride);
for( Int colSend=0; colSend<numColSends; ++colSend )
{
Int recvCol = 0; // avoid compiler warnings...
if( inAGrid )
recvCol=Mod(Mod(A.RowRank()-rowAlignA,rowStrideA)+rowAlign,
rowStride);
for( Int rowSend=0; rowSend<numRowSends; ++rowSend )
{
mpi::Request sendRequest;
// Fire off this round of non-blocking sends
if( inAGrid )
{
// Pack the data
Int sendHeight = Length(A.LocalHeight(),colSend,numColSends);
Int sendWidth = Length(A.LocalWidth(),rowSend,numRowSends);
copy::util::InterleaveMatrix
( sendHeight, sendWidth,
A.LockedBuffer(colSend,rowSend),
numColSends, numRowSends*A.LDim(),
sendBuf, 1, sendHeight );
// Send data
const Int recvVCRank = recvRow + recvCol*colStride;
const Int recvViewingRank = B.Grid().VCToViewing( recvVCRank );
mpi::ISend
( sendBuf, sendHeight*sendWidth, recvViewingRank,
B.Grid().ViewingComm(), sendRequest );
}
// Perform this round of recv's
if( inBGrid )
{
const Int sendColOffset = colAlignA;
const Int recvColOffset =
(colSend*colStrideA+colAlign) % colStride;
const Int sendRowOffset = rowAlignA;
const Int recvRowOffset =
(rowSend*rowStrideA+rowAlign) % rowStride;
const Int firstSendRow =
Mod( Mod(colRank-recvColOffset,colStride)+sendColOffset,
colStrideA );
const Int firstSendCol =
Mod( Mod(rowRank-recvRowOffset,rowStride)+sendRowOffset,
rowStrideA );
const Int colShift = Mod( colRank-recvColOffset, colStride );
const Int rowShift = Mod( rowRank-recvRowOffset, rowStride );
const Int numColRecvs = Length( colStrideA, colShift, colStride );
const Int numRowRecvs = Length( rowStrideA, rowShift, rowStride );
// Recv data