예제 #1
0
int
main( int argc, char* argv[] )
{
    Initialize( argc, argv );
    mpi::Comm comm = mpi::COMM_WORLD;
    const Int commRank = mpi::Rank( comm );
    const Int commSize = mpi::Size( comm );

    try 
    {
        const Int m = 3*commSize;
        const Int n = 2*commSize;

        Grid g( comm );

        for( Int k=0; k<50; ++k )
        {
            if( commRank == 0 )
                std::cout << "Iteration " << k << std::endl;

            DistMatrix<double> A(g);
            Zeros( A, m, n );

            AxpyInterface<double> interface;
            interface.Attach( LOCAL_TO_GLOBAL, A );
            Matrix<double> X( commSize, 1 );
            for( Int j=0; j<X.Width(); ++j )
                for( Int i=0; i<commSize; ++i )
                    X.Set(i,j,commRank+1);
            for( Int i=0; i<5; ++i )
            {
                interface.Axpy( 2, X, 2*commRank, commRank );
                interface.Axpy( 2, X, 2*commRank, commRank+1 );
            }
            interface.Detach();

            Print( A, "A" );

            interface.Attach( GLOBAL_TO_LOCAL, A );
            Matrix<double> Y;
            if( commRank == 0 )
            {
                Zeros( Y, m, n );
                interface.Axpy( 1.0, Y, 0, 0 );
            }
            interface.Detach();

            if( commRank == 0 )
                Print( Y, "Copy of global matrix on root process:" );

            // TODO: Check to ensure that the result is correct
        }
    }
    catch( std::exception& e ) { ReportException(e); }

    Finalize();
    return 0;
}
예제 #2
0
int
main( int argc, char* argv[] )
{
    Initialize( argc, argv );
    mpi::Comm comm = mpi::COMM_WORLD;
    const int commRank = mpi::CommRank( comm );
    const int commSize = mpi::CommSize( comm );

    try 
    {
        const int m = 3*commSize;
        const int n = 2*commSize;

        Grid g( comm );

        for( int k=0; k<50; ++k )
        {
            if( commRank == 0 )
                std::cout << "Iteration " << k << std::endl;

            DistMatrix<double> A(g);
            Zeros( m, n, A );

            AxpyInterface<double> interface;
            interface.Attach( LOCAL_TO_GLOBAL, A );
            Matrix<double> X( commSize, 1 );
            for( int j=0; j<X.Width(); ++j )
                for( int i=0; i<commSize; ++i )
                    X.Set(i,j,commRank+1);
            for( int i=0; i<5; ++i )
            {
                interface.Axpy( 2, X, 2*commRank, commRank );
                interface.Axpy( 2, X, 2*commRank, commRank+1 );
            }
            interface.Detach();

            A.Print("A");

            interface.Attach( GLOBAL_TO_LOCAL, A );
            Matrix<double> Y;
            if( commRank == 0 )
            {
                Zeros( m, n, Y );
                interface.Axpy( 1.0, Y, 0, 0 );
            }
            interface.Detach();

            if( commRank == 0 )
                Y.Print( "Copy of global matrix on root process:" );

            // TODO: Check to ensure that the result is correct
        }
    }
    catch( std::exception& e )
    {
#ifndef RELEASE
        DumpCallStack();
#endif
        std::cerr << "Process " << commRank << " caught error message:\n"
                  << e.what() << std::endl;
    }

    Finalize();
    return 0;
}