本文整理匯總了C++中DistMatrix::LDim方法的典型用法代碼示例。如果您正苦於以下問題:C++ DistMatrix::LDim方法的具體用法?C++ DistMatrix::LDim怎麽用?C++ DistMatrix::LDim使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DistMatrix
的用法示例。
在下文中一共展示了DistMatrix::LDim方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: 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() );
}
}
示例2: 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() );
}
示例3: file
inline void
BinaryFlat
( DistMatrix<T,CIRC,CIRC>& A, Int height, Int width,
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);
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( 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) );
}
}
示例4: entry
const DistMatrix<T,MD,STAR>&
DistMatrix<T,MD,STAR>::operator=( const DistMatrix<T,STAR,STAR>& A )
{
#ifndef RELEASE
CallStackEntry entry("[MD,* ] = [* ,* ]");
this->AssertNotLocked();
this->AssertSameGrid( A.Grid() );
#endif
this->ResizeTo( A.Height(), A.Width() );
if( !this->Participating() )
return *this;
const Int lcm = this->grid_->LCM();
const Int colShift = this->ColShift();
const Int width = this->Width();
const Int localHeight = this->LocalHeight();
const T* ABuf = A.LockedBuffer();
const Int ALDim = A.LDim();
T* thisBuffer = this->Buffer();
const Int thisLDim = this->LDim();
PARALLEL_FOR
for( Int j=0; j<width; ++j )
{
T* destCol = &thisBuffer[j*thisLDim];
const T* sourceCol = &ABuf[colShift+j*ALDim];
for( Int iLoc=0; iLoc<localHeight; ++iLoc )
destCol[iLoc] = sourceCol[iLoc*lcm];
}
return *this;
}
示例5: entry
const DistMatrix<T,STAR,STAR>&
DistMatrix<T,STAR,STAR>::operator=( const DistMatrix<T,VR,STAR>& A )
{
#ifndef RELEASE
CallStackEntry entry("[* ,* ] = [VR,* ]");
this->AssertNotLocked();
this->AssertSameGrid( A.Grid() );
#endif
const elem::Grid& g = this->Grid();
this->ResizeTo( A.Height(), A.Width() );
if( !this->Participating() )
return *this;
const Int p = g.Size();
const Int height = this->Height();
const Int width = this->Width();
const Int localHeightOfA = A.LocalHeight();
const Int maxLocalHeight = MaxLength(height,p);
const Int portionSize = mpi::Pad( maxLocalHeight*width );
T* buffer = this->auxMemory_.Require( (p+1)*portionSize );
T* sendBuf = &buffer[0];
T* recvBuf = &buffer[portionSize];
// Pack
const Int ALDim = A.LDim();
const T* ABuf = A.LockedBuffer();
PARALLEL_FOR
for( Int j=0; j<width; ++j )
MemCopy
( &sendBuf[j*localHeightOfA], &ABuf[j*ALDim], localHeightOfA );
// Communicate
mpi::AllGather
( sendBuf, portionSize,
recvBuf, portionSize, g.VRComm() );
// Unpack
T* thisBuf = this->Buffer();
const Int thisLDim = this->LDim();
const Int colAlignmentOfA = A.ColAlignment();
OUTER_PARALLEL_FOR
for( Int k=0; k<p; ++k )
{
const T* data = &recvBuf[k*portionSize];
const Int colShift = Shift_( k, colAlignmentOfA, p );
const Int localHeight = Length_( height, colShift, p );
INNER_PARALLEL_FOR
for( Int j=0; j<width; ++j )
{
T* destCol = &thisBuf[colShift+j*thisLDim];
const T* sourceCol = &data[j*localHeight];
for( Int iLoc=0; iLoc<localHeight; ++iLoc )
destCol[iLoc*p] = sourceCol[iLoc];
}
}
this->auxMemory_.Release();
return *this;
}
示例6: 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
}
示例7: 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() );
}
示例8: 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) );
}
}
}
}
示例9: 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() );
}
示例10: 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() );
}
示例11: dProx
void GetMappedDiagonal
( const DistMatrix<T,U,V>& A,
AbstractDistMatrix<S>& dPre,
function<S(const T&)> func,
Int offset )
{
EL_DEBUG_CSE
EL_DEBUG_ONLY(AssertSameGrids( A, dPre ))
ElementalProxyCtrl ctrl;
ctrl.colConstrain = true;
ctrl.colAlign = A.DiagonalAlign(offset);
ctrl.rootConstrain = true;
ctrl.root = A.DiagonalRoot(offset);
DistMatrixWriteProxy<S,S,DiagCol<U,V>(),DiagRow<U,V>()> dProx( dPre, ctrl );
auto& d = dProx.Get();
d.Resize( A.DiagonalLength(offset), 1 );
if( d.Participating() )
{
const Int diagShift = d.ColShift();
const Int iStart = diagShift + Max(-offset,0);
const Int jStart = diagShift + Max( offset,0);
const Int colStride = A.ColStride();
const Int rowStride = A.RowStride();
const Int iLocStart = (iStart-A.ColShift()) / colStride;
const Int jLocStart = (jStart-A.RowShift()) / rowStride;
const Int iLocStride = d.ColStride() / colStride;
const Int jLocStride = d.ColStride() / rowStride;
const Int localDiagLength = d.LocalHeight();
S* dBuf = d.Buffer();
const T* ABuf = A.LockedBuffer();
const Int ldim = A.LDim();
EL_PARALLEL_FOR
for( Int k=0; k<localDiagLength; ++k )
{
const Int iLoc = iLocStart + k*iLocStride;
const Int jLoc = jLocStart + k*jLocStride;
dBuf[k] = func(ABuf[iLoc+jLoc*ldim]);
}
}
}
示例12: 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* 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 =
( side==LEFT ? j-offset-1
: j-offset+height-width-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 =
( side==LEFT ? std::max(j-offset+1,0)
: std::max(j-offset+height-width+1,0) );
const int numNonzeroRows =
Length_(firstZeroRow,colShift,colStride);
if( numNonzeroRows < localHeight )
{
T* col = &buffer[numNonzeroRows+jLocal*ldim];
MemZero( col, localHeight-numNonzeroRows );
}
}
}
#ifndef RELEASE
PopCallStack();
#endif
}
示例13: Blocksize
void FormDiagonalBlocks
( const DistMatrix<F,VC,STAR>& L, DistMatrix<F,STAR,STAR>& D, bool conjugate )
{
const Grid& g = L.Grid();
const Int height = L.Width();
const Int blocksize = Blocksize();
const int commRank = g.VCRank();
const int commSize = g.Size();
const Int localHeight = Length(height,commRank,commSize);
const Int maxLocalHeight = MaxLength(height,commSize);
const Int portionSize = maxLocalHeight*blocksize;
std::vector<F> sendBuffer( portionSize );
const Int colShift = L.ColShift();
const Int LLDim = L.LDim();
const F* LBuffer = L.LockedBuffer();
if( conjugate )
{
for( Int iLoc=0; iLoc<localHeight; ++iLoc )
{
const Int i = colShift + iLoc*commSize;
const Int block = i / blocksize;
const Int jStart = block*blocksize;
const Int b = std::min(height-jStart,blocksize);
for( Int jOff=0; jOff<b; ++jOff )
sendBuffer[iLoc*blocksize+jOff] =
Conj(LBuffer[iLoc+(jStart+jOff)*LLDim]);
}
}
else
{
for( Int iLoc=0; iLoc<localHeight; ++iLoc )
{
const Int i = colShift + iLoc*commSize;
const Int block = i / blocksize;
const Int jStart = block*blocksize;
const Int b = std::min(height-jStart,blocksize);
for( Int jOff=0; jOff<b; ++jOff )
sendBuffer[iLoc*blocksize+jOff] =
LBuffer[iLoc+(jStart+jOff)*LLDim];
}
}
std::vector<F> recvBuffer( portionSize*commSize );
mpi::AllGather
( &sendBuffer[0], portionSize, &recvBuffer[0], portionSize, g.VCComm() );
SwapClear( sendBuffer );
D.Resize( blocksize, height );
F* DBuffer = D.Buffer();
const Int DLDim = D.LDim();
for( Int proc=0; proc<commSize; ++proc )
{
const F* procRecv = &recvBuffer[proc*portionSize];
const Int procLocalHeight = Length(height,proc,commSize);
for( Int iLoc=0; iLoc<procLocalHeight; ++iLoc )
{
const Int i = proc + iLoc*commSize;
for( Int jOff=0; jOff<blocksize; ++jOff )
DBuffer[jOff+i*DLDim] = procRecv[jOff+iLoc*blocksize];
}
}
}
示例14: AssertSameGrids
void ColAllToAllPromote
( const DistMatrix<T, U, V >& A,
DistMatrix<T,Partial<U>(),PartialUnionRow<U,V>()>& B )
{
DEBUG_CSE
AssertSameGrids( A, B );
const Int height = A.Height();
const Int width = A.Width();
B.AlignColsAndResize
( Mod(A.ColAlign(),B.ColStride()), height, width, false, false );
if( !B.Participating() )
return;
const Int colStride = A.ColStride();
const Int colStridePart = A.PartialColStride();
const Int colStrideUnion = A.PartialUnionColStride();
const Int colRankPart = A.PartialColRank();
const Int colDiff = B.ColAlign() - Mod(A.ColAlign(),colStridePart);
const Int maxLocalHeight = MaxLength(height,colStride);
const Int maxLocalWidth = MaxLength(width,colStrideUnion);
const Int portionSize = mpi::Pad( maxLocalHeight*maxLocalWidth );
if( colDiff == 0 )
{
if( A.PartialUnionColStride() == 1 )
{
Copy( A.LockedMatrix(), B.Matrix() );
}
else
{
vector<T> buffer;
FastResize( buffer, 2*colStrideUnion*portionSize );
T* firstBuf = &buffer[0];
T* secondBuf = &buffer[colStrideUnion*portionSize];
// Pack
util::RowStridedPack
( A.LocalHeight(), width,
B.RowAlign(), colStrideUnion,
A.LockedBuffer(), A.LDim(),
firstBuf, portionSize );
// Simultaneously Gather in columns and Scatter in rows
mpi::AllToAll
( firstBuf, portionSize,
secondBuf, portionSize, A.PartialUnionColComm() );
// Unpack
util::PartialColStridedUnpack
( height, B.LocalWidth(),
A.ColAlign(), colStride,
colStrideUnion, colStridePart, colRankPart,
B.ColShift(),
secondBuf, portionSize,
B.Buffer(), B.LDim() );
}
}
else
{
#ifdef EL_UNALIGNED_WARNINGS
if( A.Grid().Rank() == 0 )
cerr << "Unaligned PartialColAllToAllPromote" << endl;
#endif
const Int sendColRankPart = Mod( colRankPart+colDiff, colStridePart );
const Int recvColRankPart = Mod( colRankPart-colDiff, colStridePart );
vector<T> buffer;
FastResize( buffer, 2*colStrideUnion*portionSize );
T* firstBuf = &buffer[0];
T* secondBuf = &buffer[colStrideUnion*portionSize];
// Pack
util::RowStridedPack
( A.LocalHeight(), width,
B.RowAlign(), colStrideUnion,
A.LockedBuffer(), A.LDim(),
secondBuf, portionSize );
// Realign the input
mpi::SendRecv
( secondBuf, colStrideUnion*portionSize, sendColRankPart,
firstBuf, colStrideUnion*portionSize, recvColRankPart,
A.PartialColComm() );
// Simultaneously Scatter in columns and Gather in rows
mpi::AllToAll
( firstBuf, portionSize,
secondBuf, portionSize, A.PartialUnionColComm() );
// Unpack
util::PartialColStridedUnpack
( height, B.LocalWidth(),
A.ColAlign(), colStride,
colStrideUnion, colStridePart, recvColRankPart,
B.ColShift(),
secondBuf, portionSize,
B.Buffer(), B.LDim() );
}
//.........這裏部分代碼省略.........
示例15: 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() );
}
}
}