本文整理匯總了C++中DistMatrix::LocalBuffer方法的典型用法代碼示例。如果您正苦於以下問題:C++ DistMatrix::LocalBuffer方法的具體用法?C++ DistMatrix::LocalBuffer怎麽用?C++ DistMatrix::LocalBuffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DistMatrix
的用法示例。
在下文中一共展示了DistMatrix::LocalBuffer方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: logic_error
// Broadcast a matrix from the root grid to the others
void DepthBroadcast
( const mpi::Comm& depthComm,
const DistMatrix<double,MC,MR>& A,
DistMatrix<double,MC,MR>& B )
{
const int rank = mpi::CommRank(mpi::COMM_WORLD);
const Grid& meshGrid = A.Grid();
const int meshSize = meshGrid.Size();
const int depthRank = rank / meshSize;
const int localSize = A.LocalHeight()*A.LocalWidth();
if( A.LocalHeight() != A.LocalLDim() )
throw std::logic_error("Leading dimension did not match local height");
B.Empty();
B.AlignWith( A );
B.ResizeTo( A.Height(), A.Width() );
// Have the root pack the broadcast data
if( depthRank == 0 )
MemCopy( B.LocalBuffer(), A.LockedLocalBuffer(), localSize );
// Broadcast from the root
mpi::Broadcast( B.LocalBuffer(), localSize, 0, depthComm );
}
示例2: buffer
static void Func
( DistMatrix<T,MC,STAR>& A, T center, typename Base<T>::type radius )
{
const Grid& grid = A.Grid();
if( grid.InGrid() )
{
const int n = A.Width();
const int localHeight = A.LocalHeight();
const int bufSize = localHeight*n;
std::vector<T> buffer( bufSize );
// Create random matrix on process column 0, then broadcast
if( grid.Col() == 0 )
{
for( int j=0; j<n; ++j )
for( int iLocal=0; iLocal<localHeight; ++iLocal )
buffer[iLocal+j*localHeight] =
center + radius*SampleUnitBall<T>();
}
mpi::Broadcast( &buffer[0], bufSize, 0, grid.RowComm() );
// Unpack
T* localBuffer = A.LocalBuffer();
const int ldim = A.LocalLDim();
#ifdef HAVE_OPENMP
#pragma omp parallel for
#endif
for( int j=0; j<n; ++j )
{
const T* bufferCol = &buffer[j*localHeight];
T* col = &localBuffer[j*ldim];
MemCopy( col, bufferCol, localHeight );
}
}
}
示例3: 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* localBuffer = A.LocalBuffer();
const int ldim = A.LocalLDim();
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 =
RawLocalLength( boundary, colShift, colStride );
MemZero( &localBuffer[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 =
RawLocalLength(firstZeroRow,colShift,colStride);
if( numNonzeroRows < localHeight )
{
T* col = &localBuffer[numNonzeroRows+jLocal*ldim];
MemZero( col, localHeight-numNonzeroRows );
}
}
}
#ifndef RELEASE
PopCallStack();
#endif
}
示例4: PushCallStack
inline void HermitianSVD
( UpperOrLower uplo,
DistMatrix<F>& A, DistMatrix<typename Base<F>::type,VR,STAR>& s,
DistMatrix<F>& U, DistMatrix<F>& V )
{
#ifndef RELEASE
PushCallStack("HermitianSVD");
#endif
typedef typename Base<F>::type 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 );
s_MR_STAR = s;
// Set the singular values to the absolute value of the eigenvalues
const int numLocalVals = s.LocalHeight();
for( int iLocal=0; iLocal<numLocalVals; ++iLocal )
{
const R sigma = s.GetLocal(iLocal,0);
s.SetLocal(iLocal,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 jLocal=0; jLocal<localWidth; ++jLocal )
{
const R sigma = s_MR_STAR.GetLocal( jLocal, 0 );
F* UCol = U.LocalBuffer( 0, jLocal );
const F* VCol = V.LockedLocalBuffer( 0, jLocal );
if( sigma >= 0 )
for( int iLocal=0; iLocal<localHeight; ++iLocal )
UCol[iLocal] = VCol[iLocal];
else
for( int iLocal=0; iLocal<localHeight; ++iLocal )
UCol[iLocal] = -VCol[iLocal];
}
#ifndef RELEASE
PopCallStack();
#endif
}
示例5: InitB
// Have the top layer initialize the distributed matrix, B
void InitB( DistMatrix<double,MC,MR>& B )
{
const int rank = mpi::CommRank(mpi::COMM_WORLD);
const Grid& g = B.Grid();
const int meshSize = g.Size();
const int depthRank = rank / meshSize;
if( depthRank == 0 )
{
if( B.LocalHeight() != B.LocalLDim() )
throw std::logic_error("Local ldim of B was too large");
double* localBuffer = B.LocalBuffer();
const int localSize = B.LocalHeight()*B.LocalWidth();
for( int iLocal=0; iLocal<localSize; ++iLocal )
localBuffer[iLocal] = iLocal*meshSize + rank;
B.Print("B");
}
}
示例6: 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.LocalBuffer(0,j);
const F* X1ColBuffer = X1.LockedLocalBuffer(0,j);
for( int iLocal=0; iLocal<localHeight; ++iLocal )
ZColBuffer[offset+stride*iLocal] += X1ColBuffer[iLocal];
}
#ifndef RELEASE
PopCallStack();
#endif
}
示例7: logic_error
inline void
Her
( UpperOrLower uplo,
T alpha, const DistMatrix<T>& x,
DistMatrix<T>& A )
{
#ifndef RELEASE
PushCallStack("Her");
if( A.Grid() != x.Grid() )
throw std::logic_error("{A,x} must be distributed over the same grid");
if( A.Height() != A.Width() )
throw std::logic_error("A must be square");
const int xLength = ( x.Width()==1 ? x.Height() : x.Width() );
if( A.Height() != xLength )
{
std::ostringstream msg;
msg << "A must conform with x: \n"
<< " A ~ " << A.Height() << " x " << A.Width() << "\n"
<< " x ~ " << x.Height() << " x " << x.Width() << "\n";
throw std::logic_error( msg.str() );
}
#endif
const Grid& g = A.Grid();
const int localHeight = A.LocalHeight();
const int localWidth = A.LocalWidth();
const int r = g.Height();
const int c = g.Width();
const int colShift = A.ColShift();
const int rowShift = A.RowShift();
if( x.Width() == 1 )
{
DistMatrix<T,MC,STAR> x_MC_STAR(g);
DistMatrix<T,MR,STAR> x_MR_STAR(g);
x_MC_STAR.AlignWith( A );
x_MR_STAR.AlignWith( A );
//--------------------------------------------------------------------//
x_MC_STAR = x;
x_MR_STAR = x_MC_STAR;
const T* xLocal = x_MC_STAR.LockedLocalBuffer();
if( uplo == LOWER )
{
for( int jLocal=0; jLocal<localWidth; ++jLocal )
{
const int j = rowShift + jLocal*c;
const int heightAboveDiag = LocalLength(j,colShift,r);
const T gamma = alpha*Conj(x_MR_STAR.GetLocal(jLocal,0));
T* ALocalCol = A.LocalBuffer(0,jLocal);
for( int iLocal=heightAboveDiag; iLocal<localHeight; ++iLocal )
ALocalCol[iLocal] += gamma*xLocal[iLocal];
}
}
else
{
for( int jLocal=0; jLocal<localWidth; ++jLocal )
{
const int j = rowShift + jLocal*c;
const int heightToDiag = LocalLength(j+1,colShift,r);
const T gamma = alpha*Conj(x_MR_STAR.GetLocal(jLocal,0));
T* ALocalCol = A.LocalBuffer(0,jLocal);
for( int iLocal=0; iLocal<heightToDiag; ++iLocal )
ALocalCol[iLocal] += gamma*xLocal[iLocal];
}
}
//--------------------------------------------------------------------//
x_MC_STAR.FreeAlignments();
x_MR_STAR.FreeAlignments();
}
else
{
DistMatrix<T,STAR,MC> x_STAR_MC(g);
DistMatrix<T,STAR,MR> x_STAR_MR(g);
x_STAR_MC.AlignWith( A );
x_STAR_MR.AlignWith( A );
//--------------------------------------------------------------------//
x_STAR_MR = x;
x_STAR_MC = x_STAR_MR;
const T* xLocal = x_STAR_MC.LockedLocalBuffer();
const int incx = x_STAR_MC.LocalLDim();
if( uplo == LOWER )
{
for( int jLocal=0; jLocal<localWidth; ++jLocal )
{
const int j = rowShift + jLocal*c;
const int heightAboveDiag = LocalLength(j,colShift,r);
const T gamma = alpha*Conj(x_STAR_MR.GetLocal(0,jLocal));
T* ALocalCol = A.LocalBuffer(0,jLocal);
for( int iLocal=heightAboveDiag; iLocal<localHeight; ++iLocal )
ALocalCol[iLocal] += gamma*xLocal[iLocal*incx];
}
}
else
//.........這裏部分代碼省略.........
示例8: logic_error
inline void
PanelLU
( DistMatrix<F, STAR,STAR>& A,
DistMatrix<F, MC, STAR>& B,
DistMatrix<int,STAR,STAR>& p,
int pivotOffset )
{
#ifndef RELEASE
PushCallStack("internal::PanelLU");
if( A.Grid() != p.Grid() || p.Grid() != B.Grid() )
throw std::logic_error
("Matrices must be distributed over the same grid");
if( A.Width() != B.Width() )
throw std::logic_error("A and B must be the same width");
if( A.Height() != p.Height() || p.Width() != 1 )
throw std::logic_error("p must be a vector that conforms with A");
#endif
const Grid& g = A.Grid();
const int r = g.Height();
const int colShift = B.ColShift();
const int colAlignment = B.ColAlignment();
// Matrix views
DistMatrix<F,STAR,STAR>
ATL(g), ATR(g), A00(g), a01(g), A02(g),
ABL(g), ABR(g), a10(g), alpha11(g), a12(g),
A20(g), a21(g), A22(g);
DistMatrix<F,MC,STAR>
BL(g), BR(g),
B0(g), b1(g), B2(g);
const int width = A.Width();
const int numBytes = (width+1)*sizeof(F)+sizeof(int);
std::vector<byte> sendData(numBytes);
std::vector<byte> recvData(numBytes);
// Extract pointers to send and recv data
// TODO: Think of how to make this safer with respect to alignment issues
F* sendBufFloat = (F*)&sendData[0];
F* recvBufFloat = (F*)&recvData[0];
int* sendBufInt = (int*)&sendData[(width+1)*sizeof(F)];
int* recvBufInt = (int*)&recvData[(width+1)*sizeof(F)];
// Start the algorithm
PushBlocksizeStack( 1 );
PartitionDownDiagonal
( A, ATL, ATR,
ABL, ABR, 0 );
PartitionRight( B, BL, BR, 0 );
while( ATL.Height() < A.Height() )
{
RepartitionDownDiagonal
( ATL, /**/ ATR, A00, /**/ a01, A02,
/*************/ /**********************/
/**/ a10, /**/ alpha11, a12,
ABL, /**/ ABR, A20, /**/ a21, A22 );
RepartitionRight
( BL, /**/ BR,
B0, /**/ b1, B2 );
//--------------------------------------------------------------------//
const int currentRow = a01.Height();
// Store the index/value of the pivot candidate in A
F pivot = alpha11.GetLocal(0,0);
int pivotRow = currentRow;
for( int i=0; i<a21.Height(); ++i )
{
F value = a21.GetLocal(i,0);
if( FastAbs(value) > FastAbs(pivot) )
{
pivot = value;
pivotRow = currentRow + i + 1;
}
}
// Update the pivot candidate to include local data from B
for( int i=0; i<B.LocalHeight(); ++i )
{
F value = b1.GetLocal(i,0);
if( FastAbs(value) > FastAbs(pivot) )
{
pivot = value;
pivotRow = A.Height() + colShift + i*r;
}
}
// Fill the send buffer with:
// [ pivotValue | pivot row data | pivotRow ]
if( pivotRow < A.Height() )
{
sendBufFloat[0] = A.GetLocal(pivotRow,a10.Width());
const int ALDim = A.LocalLDim();
const F* ABuffer = A.LocalBuffer(pivotRow,0);
for( int j=0; j<width; ++j )
sendBufFloat[j+1] = ABuffer[j*ALDim];
}
//.........這裏部分代碼省略.........
示例9: PushCallStack
inline void
MakeTrapezoidal
( LeftOrRight side, UpperOrLower uplo, int offset,
DistMatrix<T,U,V>& A )
{
#ifndef RELEASE
PushCallStack("MakeTrapezoidal");
#endif
const int height = A.Height();
const int width = A.Width();
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* localBuffer = A.LocalBuffer();
const int ldim = A.LocalLDim();
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 =
( side==LEFT ? j-offset-1
: j-offset+height-width-1 );
if( lastZeroRow >= 0 )
{
const int boundary = std::min( lastZeroRow+1, height );
const int numZeroRows =
RawLocalLength( boundary, colShift, colStride );
MemZero( &localBuffer[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 =
( side==LEFT ? std::max(j-offset+1,0)
: std::max(j-offset+height-width+1,0) );
const int numNonzeroRows =
RawLocalLength(firstZeroRow,colShift,colStride);
if( numNonzeroRows < localHeight )
{
T* col = &localBuffer[numNonzeroRows+jLocal*ldim];
MemZero( col, localHeight-numNonzeroRows );
}
}
}
#ifndef RELEASE
PopCallStack();
#endif
}
示例10: logic_error
//.........這裏部分代碼省略.........
}
}
}
// Construct the send and recv displacements from the counts
std::vector<int> sendDispls(c), recvDispls(c);
int totalSend=0, totalRecv=0;
for( int i=0; i<c; ++i )
{
sendDispls[i] = totalSend;
recvDispls[i] = totalRecv;
totalSend += sendCounts[i];
totalRecv += recvCounts[i];
}
#ifndef RELEASE
if( totalSend != totalRecv )
{
std::ostringstream msg;
msg << "Send and recv counts do not match: (send,recv)="
<< totalSend << "," << totalRecv;
throw std::logic_error( msg.str().c_str() );
}
#endif
// Fill vectors with the send data
std::vector<F> sendData(std::max(1,totalSend));
std::vector<int> offsets(c,0);
const int localWidth = LocalLength( b, rowShift, c );
for( int jLocal=0; jLocal<localWidth; ++jLocal )
{
const int sendCol = preimage[rowShift+jLocal*c];
const int sendTo = (rowAlignment+sendCol) % c;
const int offset = sendDispls[sendTo]+offsets[sendTo];
MemCopy( &sendData[offset], A.LocalBuffer(0,jLocal), localHeight );
offsets[sendTo] += localHeight;
}
for( int j=0; j<b; ++j )
{
const int recvCol = image[j];
if( recvCol >= b )
{
const int recvFrom = (rowAlignment+recvCol) % c;
if( recvFrom == myCol )
{
const int recvTo = (rowAlignment+j) % c;
const int jLocal = (recvCol-rowShift) / c;
const int offset = sendDispls[recvTo]+offsets[recvTo];
MemCopy
( &sendData[offset], A.LocalBuffer(0,jLocal), localHeight );
offsets[recvTo] += localHeight;
}
}
}
// Communicate all pivot rows
std::vector<F> recvData(std::max(1,totalRecv));
mpi::AllToAll
( &sendData[0], &sendCounts[0], &sendDispls[0],
&recvData[0], &recvCounts[0], &recvDispls[0], g.RowComm() );
// Unpack the recv data
for( int k=0; k<c; ++k )
{
offsets[k] = 0;
int thisRowShift = Shift( k, rowAlignment, c );
for( int j=thisRowShift; j<b; j+=c )
示例11: logic_error
//.........這裏部分代碼省略.........
}
}
// Construct the send and recv displacements from the counts
std::vector<int> sendDispls(r), recvDispls(r);
int totalSend=0, totalRecv=0;
for( int i=0; i<r; ++i )
{
sendDispls[i] = totalSend;
recvDispls[i] = totalRecv;
totalSend += sendCounts[i];
totalRecv += recvCounts[i];
}
#ifndef RELEASE
if( totalSend != totalRecv )
{
std::ostringstream msg;
msg << "Send and recv counts do not match: (send,recv)="
<< totalSend << "," << totalRecv;
throw std::logic_error( msg.str().c_str() );
}
#endif
// Fill vectors with the send data
const int ALDim = A.LocalLDim();
std::vector<F> sendData(std::max(1,totalSend));
std::vector<int> offsets(r,0);
const int localHeight = LocalLength( b, colShift, r );
for( int iLocal=0; iLocal<localHeight; ++iLocal )
{
const int sendRow = preimage[colShift+iLocal*r];
const int sendTo = (colAlignment+sendRow) % r;
const int offset = sendDispls[sendTo]+offsets[sendTo];
const F* ABuffer = A.LocalBuffer(iLocal,0);
for( int jLocal=0; jLocal<localWidth; ++jLocal )
sendData[offset+jLocal] = ABuffer[jLocal*ALDim];
offsets[sendTo] += localWidth;
}
for( int i=0; i<b; ++i )
{
const int recvRow = image[i];
if( recvRow >= b )
{
const int recvFrom = (colAlignment+recvRow) % r;
if( recvFrom == myRow )
{
const int recvTo = (colAlignment+i) % r;
const int iLocal = (recvRow-colShift) / r;
const int offset = sendDispls[recvTo]+offsets[recvTo];
const F* ABuffer = A.LocalBuffer(iLocal,0);
for( int jLocal=0; jLocal<localWidth; ++jLocal )
sendData[offset+jLocal] = ABuffer[jLocal*ALDim];
offsets[recvTo] += localWidth;
}
}
}
// Communicate all pivot rows
std::vector<F> recvData(std::max(1,totalRecv));
mpi::AllToAll
( &sendData[0], &sendCounts[0], &sendDispls[0],
&recvData[0], &recvCounts[0], &recvDispls[0], g.ColComm() );
// Unpack the recv data
for( int k=0; k<r; ++k )
{