#include <iostream>
#include "linbox/blackbox/sparse.h"
#include "linbox/util/matrix-stream.h"
int main (int argc, char **argv)
{
commentator().
setMaxDetailLevel (-1);
commentator().
setMaxDepth (-1);
commentator().
setReportStream (std::cerr);
if (argc < 2 || argc > 4) {
cerr << "Usage: solve <matrix-file-in-supported-format> [<dense-vector-file>] [<p>]" << endl;
return 0;
}
srand48( BaseTimer::seed() );
std::ifstream input (argv[1]);
if (!input) { cerr << "Error opening matrix file " << argv[1] << endl; return -1; }
std::ifstream invect;
bool createB = false;
int ModComp = 0;
if (argc == 2) {
createB = true;
ModComp = 0;
}
if (argc == 3) {
invect.open (argv[2], std::ifstream::in);
if (!invect) {
createB = true;
ModComp = 2;
}
else {
createB = false;
ModComp = 0;
}
}
if (argc == 4) {
ModComp = 3;
invect.open (argv[2], std::ifstream::in);
if (!invect) {
createB = true;
}
else
createB = false;
}
if (ModComp) {
double q = atof(argv[ModComp]);
Field F(q);
cout <<
"A is " << A.
rowdim() <<
" by " << A.
coldim() << endl;
if (createB) {
cerr << "Creating a random {-1,1} vector " << endl;
std::vector<Field::Element> U( A.
coldim() );
for(std::vector<Field::Element>::iterator it=U.begin();
it != U.end(); ++it)
if (drand48() <0.5)
F.init(*it,-1);
else
F.init(*it,1);
}
else {
for(std::vector<Field::Element>::iterator it=B.begin();
it != B.end(); ++it)
invect >> *it;
}
std::cout << "B is [";
for(std::vector<Field::Element>::const_iterator it=B.begin();it != B.end(); ++it)
F.write(cout, *it) << " ";
std::cout << "]" << std::endl;
Timer chrono;
std::cout << "Sparse Elimination" << std::endl;
chrono.clear();
chrono.start();
chrono.stop();
std::cout << "(Sparse Gauss) Solution is [";
for(std::vector<Field::Element>::const_iterator it=X.begin();it != X.end(); ++it)
F.write(cout, *it) << " ";
std::cout << "]" << std::endl;
std::cout << "CPU time (seconds): " << chrono.usertime() << std::endl<<std::endl;;
std::cout << "BlasElimination" << std::endl;
chrono.start();
chrono.stop();
std::cout << "(BlasElimination) Solution is [";
for(std::vector<Field::Element>::const_iterator it=X.begin();it != X.end(); ++it)
F.write(cout, *it) << " ";
std::cout << "]" << std::endl;
std::cout << "CPU time (seconds): " << chrono.usertime() << std::endl<< std::endl;
std::cout << "Blackbox" << std::endl;
chrono.clear();
chrono.start();
chrono.stop();
std::cout << "(Wiedemann) Solution is [";
for(std::vector<Field::Element>::const_iterator it=X.begin();it != X.end(); ++it)
F.write(cout, *it) << " ";
std::cout << "]" << std::endl;
std::cout << "CPU time (seconds): " << chrono.usertime() << std::endl<<std::endl;;
#if 0
std::cout << "Lanczos" << std::endl;
chrono.clear();
chrono.start();
chrono.stop();
std::cout << "(Lanczos) Solution is [";
for(std::vector<Field::Element>::const_iterator it=X.begin();it != X.end(); ++it)
F.write(cout, *it) << " ";
std::cout << "]" << std::endl;
std::cout << "CPU time (seconds): " << chrono.usertime() << std::endl<< std::endl;
std::cout << "Block Lanczos" << std::endl;
MBL.preconditioner(Specifier::FULL_DIAGONAL);
chrono.clear();
chrono.start();
chrono.stop();
std::cout << "(Block Lanczos) Solution is [";
for(std::vector<Field::Element>::const_iterator it=X.begin();it != X.end(); ++it)
F.write(cout, *it) << " ";
std::cout << "]" << std::endl;
std::cout << "CPU time (seconds): " << chrono.usertime() << std::endl<< std::endl;
#endif
}
else {
PID_integer::Element d;
std::cout <<
"A is " << A.
rowdim() <<
" by " << A.
coldim() << std::endl;
std::vector<PID_integer::Element> X( A.
coldim()),B(A.
rowdim());
if (createB) {
cerr << "Creating a random {-1,1} vector " << endl;
for(std::vector<PID_integer::Element>::iterator it=B.begin();
it != B.end(); ++it)
if (drand48() <0.5)
*it = -1;
else
*it = 1;
}
else {
for(std::vector<PID_integer::Element>::iterator it=B.begin();
it != B.end(); ++it)
invect >> *it;
}
std::cout << "B is [";
for(std::vector<PID_integer::Element>::const_iterator it=B.begin();
it != B.end(); ++it)
ZZ.
write(cout, *it) <<
" ";
std::cout << "]" << std::endl;
Timer chrono;
std::cout << "Wiedemann" << std::endl;
chrono.start();
chrono.stop();
std::cout << "(Wiedemann) Solution is [";
for(std::vector<PID_integer::Element>::const_iterator it=X.begin();it != X.end(); ++it)
ZZ.write(cout, *it) << " ";
std::cout << "] / ";
ZZ.write(std::cout, d) << std::endl;
std::cout << "CPU time (seconds): " << chrono.usertime() << std::endl;
std::cout << "BlasElimination" << std::endl;
chrono.start();
chrono.stop();
std::cout << "(BlasElimination) Solution is [";
for(std::vector<PID_integer::Element>::const_iterator it=X.begin();it != X.end(); ++it)
ZZ.write(cout, *it) << " ";
std::cout << "] / ";
ZZ.write(std::cout, d)<< std::endl;
std::cout << "CPU time (seconds): " << chrono.usertime() << std::endl;
std::cout << "Sparse Elimination" << std::endl;
chrono.start();
chrono.stop();
std::cout << "(SparseElimination) Solution is [";
for(std::vector<PID_integer::Element>::const_iterator it=X.begin();it != X.end(); ++it)
ZZ.write(cout, *it) << " ";
std::cout << "] / ";
ZZ.write(std::cout, d)<< std::endl;
std::cout << "CPU time (seconds): " << chrono.usertime() << std::endl;
#if 0
std::cout << "Lanczos" << std::endl;
chrono.start();
chrono.stop();
std::cout << "(Lanczos) Solution is [";
for(std::vector<PID_integer::Element>::const_iterator it=X.begin();it != X.end(); ++it)
ZZ.write(cout, *it) << " ";
std::cout << "] / ";
ZZ.write(std::cout, d) << std::endl;
std::cout << "CPU time (seconds): " << chrono.usertime() << std::endl;
std::cout << "Block Lanczos" << std::endl;
chrono.clear();
chrono.start();
chrono.stop();
std::cout << "(Block Lanczos) Solution is [";
for(std::vector<PID_integer::Element>::const_iterator it=X.begin();it != X.end(); ++it)
ZZ.write(cout, *it) << " ";
std::cout << "] / ";
ZZ.write(std::cout, d) << std::endl;
std::cout << "CPU time (seconds): " << chrono.usertime() << std::endl;
#endif
}
return 0;
}