当前位置: 首页>>代码示例>>C++>>正文


C++ AbstractDistMatrix::Buffer方法代码示例

本文整理汇总了C++中AbstractDistMatrix::Buffer方法的典型用法代码示例。如果您正苦于以下问题:C++ AbstractDistMatrix::Buffer方法的具体用法?C++ AbstractDistMatrix::Buffer怎么用?C++ AbstractDistMatrix::Buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AbstractDistMatrix的用法示例。


在下文中一共展示了AbstractDistMatrix::Buffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: file

inline void
Binary( AbstractDistMatrix<T>& A, const string filename )
{
    EL_DEBUG_CSE
    std::ifstream file( filename.c_str(), std::ios::binary );
    if( !file.is_open() )
        RuntimeError("Could not open ",filename);

    Int height, width;
    file.read( (char*)&height, sizeof(Int) );
    file.read( (char*)&width,  sizeof(Int) );
    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.CrossRank() != A.Root() )
        return;
    if( A.ColStride() == 1 && A.RowStride() == 1 )
    {
        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( A.ColStride() == 1 )
    {
        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 = metaBytes + 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 = metaBytes + localIndex*sizeof(T);
                file.seekg( pos );
                file.read( (char*)A.Buffer(iLoc,jLoc), sizeof(T) );
            }
        }
    }
}
开发者ID:elemental,项目名称:Elemental,代码行数:60,代码来源:Binary.hpp

示例2: if

void Transform2x2Rows
( const Matrix<T>& G, AbstractDistMatrix<T>& A, Int i1, Int i2 )
{
    DEBUG_CSE

    const int rowOwner1 = A.RowOwner(i1);
    const int rowOwner2 = A.RowOwner(i2);
    const bool inFirstRow = ( A.ColRank() == rowOwner1 );
    const bool inSecondRow = ( A.ColRank() == rowOwner2 );
    if( !inFirstRow && !inSecondRow )
        return;

    T* ABuf = A.Buffer();
    const Int ALDim = A.LDim();
    const Int nLoc = A.LocalWidth();

    const T gamma11 = G(0,0);
    const T gamma12 = G(0,1);
    const T gamma21 = G(1,0);
    const T gamma22 = G(1,1);

    if( inFirstRow && inSecondRow )
    {
        const Int i1Loc = A.LocalRow(i1);
        const Int i2Loc = A.LocalRow(i2);
        Transform2x2
        ( nLoc,
          gamma11, gamma12, gamma21, gamma22,
          &ABuf[i1Loc], ALDim, &ABuf[i2Loc], ALDim );
    }
    else if( inFirstRow )
    {
        const Int i1Loc = A.LocalRow(i1);
        vector<T> buf(nLoc);
        for( Int jLoc=0; jLoc<nLoc; ++jLoc ) 
            buf[jLoc] = ABuf[i1Loc+jLoc*ALDim];

        mpi::SendRecv( buf.data(), nLoc, rowOwner2, rowOwner2, A.ColComm() );

        // TODO: Generalized Axpy?
        blas::Scal( nLoc, gamma11, &ABuf[i1Loc], ALDim );
        blas::Axpy( nLoc, gamma12, buf.data(), 1, &ABuf[i1Loc], ALDim );
    }
    else
    {
        const Int i2Loc = A.LocalRow(i2);
        vector<T> buf(nLoc);
        for( Int jLoc=0; jLoc<nLoc; ++jLoc ) 
            buf[jLoc] = ABuf[i2Loc+jLoc*ALDim];

        mpi::SendRecv( buf.data(), nLoc, rowOwner1, rowOwner1, A.ColComm() );

        // TODO: Generalized Axpy?
        blas::Scal( nLoc, gamma22, &ABuf[i2Loc], ALDim );
        blas::Axpy( nLoc, gamma21, buf.data(), 1, &ABuf[i2Loc], ALDim );
    }
}
开发者ID:jeffhammond,项目名称:Elemental,代码行数:57,代码来源:Transform2x2.cpp

示例3: Broadcast

void Broadcast( AbstractDistMatrix<T>& A, mpi::Comm comm, int rank )
{
    DEBUG_CSE
    const int commSize = mpi::Size( comm );
    const int commRank = mpi::Rank( comm );
    if( commSize == 1 )
        return;
    if( !A.Participating() )
        return;

    const Int localHeight = A.LocalHeight();
    const Int localWidth = A.LocalWidth();
    const Int localSize = localHeight*localWidth;
    if( localHeight == A.LDim() )
    {
        mpi::Broadcast( A.Buffer(), localSize, rank, comm );
    }
    else
    {
        vector<T> buf;
        FastResize( buf, localSize );

        // Pack
        if( commRank == rank )
            copy::util::InterleaveMatrix
            ( localHeight, localWidth,
              A.LockedBuffer(), 1, A.LDim(),
              buf.data(),       1, localHeight );

        mpi::Broadcast( buf.data(), localSize, rank, comm );

        // Unpack
        if( commRank != rank )
            copy::util::InterleaveMatrix
            ( localHeight, localWidth,
              buf.data(), 1, localHeight,
              A.Buffer(), 1, A.LDim() );
    }
}
开发者ID:YingzhouLi,项目名称:Elemental,代码行数:39,代码来源:Broadcast.hpp


注:本文中的AbstractDistMatrix::Buffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。