本文整理匯總了C++中DistMatrix::Print方法的典型用法代碼示例。如果您正苦於以下問題:C++ DistMatrix::Print方法的具體用法?C++ DistMatrix::Print怎麽用?C++ DistMatrix::Print使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DistMatrix
的用法示例。
在下文中一共展示了DistMatrix::Print方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: Initialize
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 );
if( argc < 2 )
{
if( commRank == 0 )
Usage();
Finalize();
return 0;
}
const int n = atoi( argv[1] );
try
{
DistMatrix<double> I;
Identity( n, n, I );
I.Print("Identity");
}
catch( std::exception& e )
{
#ifndef RELEASE
DumpCallStack();
#endif
std::cerr << "Process " << commRank << " caught error message:\n"
<< e.what() << std::endl;
}
Finalize();
return 0;
}
示例2: Initialize
int
main( int argc, char* argv[] )
{
Initialize( argc, argv );
mpi::Comm comm = mpi::COMM_WORLD;
const int commRank = mpi::CommRank( comm );
try
{
const int m = Input("--height","height of matrix",10);
const int n = Input("--width","width of matrix",10);
const bool print = Input("--print","print matrix?",true);
ProcessInput();
PrintInputReport();
DistMatrix<double> A;
Ones( m, n, A );
if( print )
A.Print("Ones matrix:");
}
catch( std::exception& e )
{
std::ostringstream os;
os << "Process " << commRank << " caught error message:\n" << e.what()
<< std::endl;
std::cerr << os.str();
#ifndef RELEASE
DumpCallStack();
#endif
}
Finalize();
return 0;
}
示例3: InitA
// Have the top layer initialize the distributed matrix, A
void InitA( DistMatrix<double,MC,MR>& A )
{
const int rank = mpi::CommRank(mpi::COMM_WORLD);
const Grid& g = A.Grid();
const int meshSize = g.Size();
const int depthRank = rank / meshSize;
if( depthRank == 0 )
{
MakeIdentity( A );
Scal( 10.0, A );
A.Print("A");
}
}
示例4: Initialize
int
main( int argc, char* argv[] )
{
Initialize( argc, argv );
mpi::Comm comm = mpi::COMM_WORLD;
const int commRank = mpi::CommRank( comm );
try
{
const int m = Input("--height","height of matrix",10);
const int n = Input("--width","width of matrix",10);
const bool print = Input("--print","print matrices?",true);
ProcessInput();
PrintInputReport();
std::vector<double> r(m), s(n), x(m), y(n);
for( int j=0; j<m; ++j )
r[j] = 1./(j+1);
for( int j=0; j<n; ++j )
s[j] = 1./(j+1);
for( int j=0; j<m; ++j )
x[j] = j;
for( int j=0; j<n; ++j )
y[j] = j+m;
DistMatrix<double> A;
CauchyLike( r, s, x, y, A );
if( print )
A.Print("CauchyLike matrix:");
}
catch( ArgException& e )
{
// There is nothing to do
}
catch( std::exception& e )
{
std::ostringstream os;
os << "Process " << commRank << " caught error message:\n"
<< e.what() << std::endl;
#ifndef RELEASE
DumpCallStack();
#endif
}
Finalize();
return 0;
}
示例5: Initialize
int
main( int argc, char* argv[] )
{
Initialize( argc, argv );
mpi::Comm comm = mpi::COMM_WORLD;
const int commRank = mpi::CommRank( comm );
try
{
const int n = Input("--size","size of identity matrix",10);
const double phi = Input("--phi","number in (0,1)",0.2);
const bool print = Input("--print","print matrix?",true);
#ifdef HAVE_QT5
const bool display = Input("--display","display matrix?",true);
#endif
ProcessInput();
PrintInputReport();
DistMatrix<double> A;
Kahan( A, n, phi );
if( print )
A.Print("Kahan");
#ifdef HAVE_QT5
if( display )
Display( A, "Kahan" );
#endif
}
catch( ArgException& e )
{
// There is nothing to do
}
catch( std::exception& e )
{
std::ostringstream os;
os << "Process " << commRank << " caught error message:\n" << e.what()
<< std::endl;
std::cerr << os.str();
#ifndef RELEASE
DumpCallStack();
#endif
}
Finalize();
return 0;
}
示例6: Initialize
int
main( int argc, char* argv[] )
{
Initialize( argc, argv );
mpi::Comm comm = mpi::COMM_WORLD;
const int commRank = mpi::CommRank( comm );
try
{
const int n = Input("--size","size of matrix",10);
const double realCenter = Input
("--realCenter","real center of uniform eigval distribution",3.);
const double imagCenter = Input
("--imagCenter","imag center of uniform eigval distribution",-4.);
const double radius = Input
("--radius","radius of uniform eigval distribution",2.);
const bool print = Input("--print","print matrix?",true);
ProcessInput();
PrintInputReport();
const Complex<double> center( realCenter, imagCenter );
DistMatrix<Complex<double> > X;
NormalUniformSpectrum( n, X, center, radius );
if( print )
X.Print("X");
}
catch( ArgException& e )
{
// There is nothing to do
}
catch( std::exception& e )
{
std::ostringstream os;
os << "Process " << commRank << " caught error message:\n" << e.what()
<< std::endl;
std::cerr << os.str();
#ifndef RELEASE
DumpCallStack();
#endif
}
Finalize();
return 0;
}
示例7: 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");
}
}
示例8: Initialize
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 );
if( argc < 3 )
{
if( commRank == 0 )
Usage();
Finalize();
return 0;
}
const int m = atoi( argv[1] );
const int n = atoi( argv[2] );
try
{
const int length = m+n-1;
std::vector<double> a( length );
for( int j=0; j<length; ++j )
a[j] = j;
DistMatrix<double> H;
Hankel( m, n, a, H );
H.Print("Hankel matrix:");
}
catch( std::exception& e )
{
#ifndef RELEASE
DumpCallStack();
#endif
std::cerr << "Process " << commRank << " caught error message:\n"
<< e.what() << std::endl;
}
Finalize();
return 0;
}
示例9: Initialize
int
main( int argc, char* argv[] )
{
Initialize( argc, argv );
mpi::Comm comm = mpi::COMM_WORLD;
const int commRank = mpi::CommRank( comm );
try
{
const int n = Input("--size","size of matrix",10);
const bool print = Input("--print","print matrices?",true);
ProcessInput();
PrintInputReport();
std::vector<double> d( n );
for( int j=0; j<n; ++j )
d[j] = j;
DistMatrix<double> D;
Diagonal( d, D );
if( print )
D.Print("D:");
}
catch( ArgException& e )
{
// There is nothing to do
}
catch( std::exception& e )
{
std::ostringstream os;
os << "Process " << commRank << " caught error message:\n"
<< e.what() << std::endl;
std::cerr << os.str();
#ifndef RELEASE
DumpCallStack();
#endif
}
Finalize();
return 0;
}
示例10: Initialize
int
main( int argc, char* argv[] )
{
Initialize( argc, argv );
mpi::Comm comm = mpi::COMM_WORLD;
const int commRank = mpi::CommRank( comm );
try
{
const int n = Input("--size","size of Hermitian matrix",10);
const double lower = Input("--lower","lower bound on spectrum",1.);
const double upper = Input("--upper","upper bound on spectrum",10.);
const bool print = Input("--print","print matrix?",true);
ProcessInput();
PrintInputReport();
DistMatrix<double> X;
HermitianUniformSpectrum( n, X, lower, upper );
if( print )
X.Print("X");
}
catch( ArgException& e )
{
// There is nothing to do
}
catch( std::exception& e )
{
std::ostringstream os;
os << "Process " << commRank << " caught error message:\n" << e.what()
<< std::endl;
std::cerr << os.str();
#ifndef RELEASE
DumpCallStack();
#endif
}
Finalize();
return 0;
}
示例11: Initialize
int
main( int argc, char* argv[] )
{
Initialize( argc, argv );
mpi::Comm comm = mpi::COMM_WORLD;
const int commRank = mpi::CommRank( comm );
try
{
const int k = Input("--order","generate 2^k x 2^k matrix",4);
const bool print = Input("--print","print matrix?",true);
ProcessInput();
PrintInputReport();
// Generate a binary Walsh matrix of order k (a 2^k x 2^k matrix)
DistMatrix<double> W;
Walsh( k, W, true );
if( print )
W.Print("binary W(2^k)");
}
catch( ArgException& e )
{
// There is nothing to do
}
catch( std::exception& e )
{
std::ostringstream os;
os << "Process " << commRank << " caught error message:\n" << e.what()
<< std::endl;
std::cerr << os.str();
#ifndef RELEASE
DumpCallStack();
#endif
}
Finalize();
return 0;
}
示例12: Initialize
int
main( int argc, char* argv[] )
{
Initialize( argc, argv );
mpi::Comm comm = mpi::COMM_WORLD;
const int commRank = mpi::CommRank( comm );
try
{
const int n = Input("--size","size of matrix",10);
const bool print = Input("--print","print matrix?",true);
ProcessInput();
PrintInputReport();
DistMatrix<Complex<double> > A;
DiscreteFourier( n, A );
if( print )
A.Print("DFT matrix:");
}
catch( ArgException& e )
{
// There is nothing to do
}
catch( std::exception& e )
{
std::ostringstream os;
os << "Process " << commRank << " caught error message:\n"
<< e.what() << std::endl;
std::cerr << os.str();
#ifndef RELEASE
DumpCallStack();
#endif
}
Finalize();
return 0;
}
示例13: Initialize
int
main( int argc, char* argv[] )
{
Initialize( argc, argv );
mpi::Comm comm = mpi::COMM_WORLD;
const int commRank = mpi::CommRank( comm );
try
{
const int n = Input("--size","size of matrix",10);
const bool print = Input("--print","print matrices?",true);
#ifdef HAVE_QT5
const bool display = Input("--display","display matrices?",true);
#endif
ProcessInput();
PrintInputReport();
// Create a circulant matrix
DistMatrix<Complex<double> > A;
std::vector<Complex<double> > a( n );
for( int j=0; j<n; ++j )
a[j] = j;
Circulant( A, a );
if( print )
A.Print("Circulant matrix:");
#ifdef HAVE_QT5
if( display )
Display( A, "Circulant" );
#endif
// Create a discrete Fourier matrix, which can be used to diagonalize
// circulant matrices
DistMatrix<Complex<double> > F;
DiscreteFourier( F, n );
if( print )
F.Print("DFT matrix (F):");
#ifdef HAVE_QT5
if( display )
Display( F, "Discrete Fourier" );
#endif
// Form B := A F
DistMatrix<Complex<double> > B;
Zeros( B, n, n );
Gemm( NORMAL, NORMAL,
Complex<double>(1), A, F, Complex<double>(0), B );
// Form A := F^H B = F^H \hat A F
Gemm( ADJOINT, NORMAL,
Complex<double>(1), F, B, Complex<double>(0), A );
if( print )
A.Print("A := F^H A F");
#ifdef HAVE_QT5
if( display )
Display( A, "F^H A F" );
#endif
// Form the thresholded result
const int localHeight = A.LocalHeight();
const int localWidth = A.LocalWidth();
for( int jLocal=0; jLocal<localWidth; ++jLocal )
{
for( int iLocal=0; iLocal<localHeight; ++iLocal )
{
const double absValue = Abs(A.GetLocal(iLocal,jLocal));
if( absValue < 1e-13 )
A.SetLocal(iLocal,jLocal,0);
}
}
if( print )
A.Print("A with values below 1e-13 removed");
#ifdef HAVE_QT5
if( display )
Display( A, "Thresholded (1e-13) A" );
#endif
}
catch( ArgException& e )
{
// There is nothing to do
}
catch( std::exception& e )
{
std::ostringstream os;
os << "Process " << commRank << " caught error message:\n" << e.what()
<< std::endl;
std::cerr << os.str();
#ifndef RELEASE
DumpCallStack();
#endif
}
Finalize();
return 0;
}
示例14: Initialize
int
main( int argc, char* argv[] )
{
Initialize( argc, argv );
mpi::Comm comm = mpi::COMM_WORLD;
const int commRank = mpi::CommRank( comm );
try
{
const int m = Input("--height","height of matrix",20);
const int n = Input("--width","width of matrix",100);
const int maxSteps = Input("--maxSteps","max # of steps of QR",10);
const double tol = Input("--tol","tolerance for ID",-1.);
const bool print = Input("--print","print matrices?",false);
ProcessInput();
PrintInputReport();
DistMatrix<C> A;
Uniform( A, m, n );
const Real frobA = FrobeniusNorm( A );
if( print )
A.Print("A");
const Grid& g = A.Grid();
DistMatrix<int,VR,STAR> pR(g), pC(g);
DistMatrix<C> Z(g);
Skeleton( A, pR, pC, Z, maxSteps, tol );
const int numSteps = pR.Height();
if( print )
{
pR.Print("pR");
pC.Print("pC");
Z.Print("Z");
}
// Form the matrices of A's (hopefully) dominant rows and columns
DistMatrix<C> AR( A );
ApplyRowPivots( AR, pR );
AR.ResizeTo( numSteps, A.Width() );
DistMatrix<C> AC( A );
ApplyColumnPivots( AC, pC );
AC.ResizeTo( A.Height(), numSteps );
if( print )
{
AC.Print("AC");
AR.Print("AR");
}
// Check || A - AC Z AR ||_F / || A ||_F
DistMatrix<C> B(g);
Gemm( NORMAL, NORMAL, C(1), Z, AR, B );
Gemm( NORMAL, NORMAL, C(-1), AC, B, C(1), A );
const Real frobError = FrobeniusNorm( A );
if( print )
A.Print("A - AC Z AR");
if( commRank == 0 )
{
std::cout << "|| A ||_F = " << frobA << "\n\n"
<< "|| A - AC Z AR ||_F / || A ||_F = "
<< frobError/frobA << "\n" << std::endl;
}
}
catch( ArgException& e )
{
// There is nothing to do
}
catch( exception& e )
{
ostringstream os;
os << "Process " << commRank << " caught exception with message: "
<< e.what() << endl;
cerr << os.str();
#ifndef RELEASE
DumpCallStack();
#endif
}
Finalize();
return 0;
}