Ejemplo n.º 1
0
int main(int argc, char** argv){

	int m,n;
	cout<<setprecision(20);

	if (argc!=4){
		cerr<<"usage : test-frobenius <p> <A> <c>"<<endl
	 	    <<"         to compute the frobenius normal form of the matrix A over Z/pZ, with conditonning parameter c"
		    <<endl;
		exit(-1);
	}
	Field F( atoi(argv[1]) );
	Field::Element one;
	F.init(one, 1U);
	Field::Element * A = read_field<Field> (F,argv[2],&m,&n);
	size_t c = atoi(argv[3]);

	std::list<vector<Field::Element> > frobForm;
 FFLAS::Timer tim;
	tim.clear();
	tim.start();
	FFPACK::CharpolyArithProg (F, frobForm, n, A, n, c);
	tim.stop();
	std::list<vector<Field::Element> >::iterator it = frobForm.begin();
	while(it != frobForm.end()){
		printvect (cout, *(it++));
	}
	cerr<<c<<" "<<tim.usertime()<<" "<<4.55*n*n/1000000.0*n/tim.usertime()<<endl;
	FFLAS::fflas_delete( A);
	return 0;
}
Ejemplo n.º 2
0
int main(int argc, char** argv) {
  
	size_t iter = 3;
	int    q    = 131071;
	size_t    n    = 2000;
	std::string file = "";
  
	Argument as[] = {
		{ 'q', "-q Q", "Set the field characteristic (-1 for random).",  TYPE_INT , &q },
		{ 'n', "-n N", "Set the dimension of the matrix.",               TYPE_INT , &n },
		{ 'i', "-i R", "Set number of repetitions.",                     TYPE_INT , &iter },
		{ 'f', "-f FILE", "Set the input file (empty for random).",  TYPE_STR , &file },
		END_OF_ARGUMENTS
	};

	FFLAS::parseArguments(argc,argv,as);

  typedef Givaro::ModularBalanced<double> Field;
  typedef Field::Element Element;

  Field F(q);
  Field::Element * A;

  FFLAS::Timer chrono;
  double time=0.0;

  for (size_t i=0;i<=iter;++i){
	  if (!file.empty()){
		  A = read_field(F, file.c_str(),  &n, &n);
	  }
	  else {
		  A = FFLAS::fflas_new<Element>(n*n);
		  Field::RandIter G(F);
		  for (size_t j=0; j<(size_t)n*n; ++j)
			  G.random(*(A+j));
	  }

	  int nullity=0;
	  chrono.clear();
	  if (i) chrono.start();
	  FFPACK::Invert (F, n, A, n, nullity);
	  if (i) chrono.stop();

	  time+=chrono.usertime();
	  FFLAS::fflas_delete( A);
  }
  
	// -----------
	// Standard output for benchmark - Alexis Breust 2014/11/14
	#define CUBE(x) ((x)*(x)*(x))
	std::cout << "Time: " << time / double(iter)
			  << " Gflops: " << 2. * CUBE(double(n)/1000.) / time * double(iter);
	FFLAS::writeCommandString(std::cout, as) << std::endl;


  return 0;
}
Ejemplo n.º 3
0
bool check_ftrsm (const Field &F, size_t m, size_t n, const typename Field::Element &alpha, FFLAS::FFLAS_SIDE side, FFLAS::FFLAS_UPLO uplo, FFLAS::FFLAS_TRANSPOSE trans, FFLAS::FFLAS_DIAG diag, RandIter& Rand){

	typedef typename Field::Element Element;
	Element * A, *B, *B2, *C, tmp;
	size_t k = (side==FFLAS::FflasLeft?m:n);
	size_t lda,ldb,ldc;
	lda=k+13;
	ldb=n+14;
	ldc=n+15;
	A  = FFLAS::fflas_new(F,k,lda);
	B  = FFLAS::fflas_new(F,m,ldb);
	B2 = FFLAS::fflas_new(F,m,ldb);
	C  = FFLAS::fflas_new(F,m,ldc);

	RandomTriangularMatrix (F, k, k, uplo, diag, true, A, lda, Rand);
	RandomMatrix (F, m, n, B, ldb, Rand);
	FFLAS::fassign (F, m, n, B, ldb, B2, ldb);

	string ss=string((uplo == FFLAS::FflasLower)?"Lower_":"Upper_")+string((side == FFLAS::FflasLeft)?"Left_":"Right_")+string((trans == FFLAS::FflasTrans)?"Trans_":"NoTrans_")+string((diag == FFLAS::FflasUnit)?"Unit":"NonUnit");

	cout<<std::left<<"Checking FTRSM_";
	cout.fill('.');
	cout.width(35);
	cout<<ss;


	FFLAS::Timer t; t.clear();
	double time=0.0;
	t.clear();
	t.start();
	FFLAS::ftrsm (F, side, uplo, trans, diag, m, n, alpha, A, lda, B, ldb);
	t.stop();
	time+=t.usertime();

	Element invalpha;
	F.init(invalpha);
	F.inv(invalpha, alpha);

	//FFLAS::ftrmm (F, side, uplo, trans, diag, m, n, invalpha, A, k, B, n);

	if (side == FFLAS::FflasLeft)
		FFLAS::fgemm(F, trans, FFLAS::FflasNoTrans, m, n, m, invalpha, A, lda, B, ldb, F.zero, C, ldc);
	else
		FFLAS::fgemm(F, FFLAS::FflasNoTrans, trans, m, n, n, invalpha, B, ldb, A, lda, F.zero, C, ldc);

	bool ok = true;
	if (FFLAS::fequal (F, m, n, B2, ldb, C, ldc)){
	    //cout << "\033[1;32mPASSED\033[0m ("<<time<<")"<<endl;
		cout << "PASSED ("<<time<<")"<<endl;
		//cerr<<"PASSED ("<<time<<")"<<endl;
	} else{
	    //cout << "\033[1;31mFAILED\033[0m ("<<time<<")"<<endl;
		cout << "FAILED ("<<time<<")"<<endl;
		ok=false;
		//cerr<<"FAILED ("<<time<<")"<<endl;
	}

	F.mulin(invalpha,alpha);
	if (!F.isOne(invalpha)){
		cerr<<"invalpha is wrong !!!"<<endl;;
	}

	FFLAS::fflas_delete(A);
	FFLAS::fflas_delete(B);
	FFLAS::fflas_delete(B2);
	FFLAS::fflas_delete(C);
	return ok;
}
Ejemplo n.º 4
0
int main(int argc, char** argv){
 FFLAS::Timer tim;
	Givaro::IntPrimeDom IPD;
	uint64_t p;
	size_t M, N ;
	bool keepon = true;
	Givaro::Integer _p,tmp;
	Field::Element zero,one;
	cerr<<setprecision(10);
	size_t TMAX = 100;
	size_t PRIMESIZE = 23;

	if (argc > 1 )
		TMAX = atoi(argv[1]);
	if (argc > 2 )
		PRIMESIZE = atoi(argv[2]);

	FFLAS::FFLAS_TRANSPOSE ta;
	FFLAS::FFLAS_DIAG diag;
	size_t lda;

	Field::Element * A, *Abis, *X,* U, *L;
	size_t *P, *Q;
	while (keepon){
		srandom(_p);
		do{
			//		max = Integer::random(2);
			_p = random();//max % (2<<30);
			IPD.prevprime( tmp, (_p% (1<<PRIMESIZE)) );
			p =  tmp;

		}while( (p <= 2) );

		Field F( p);
		F.init(zero,0.0);
		F.init(one,1.0);
		Field::RandIter RValue( F );

		do{
			M = (size_t)  random() % TMAX;
			N = (size_t)  random() % TMAX;
		} while ((M == 0) || (N == 0));
		lda = N;
		if (random()%2)
			diag = FFLAS::FflasUnit;
		else
			diag = FFLAS::FflasNonUnit;


		if (random()%2){
			ta = FFLAS::FflasTrans;
			L = FFLAS::fflas_new<Field::Element>(M*N);
			U = FFLAS::fflas_new<Field::Element>(N*N);
			P = FFLAS::fflas_new<size_t>(M);
			Q = FFLAS::fflas_new<size_t>(N);
			for (size_t i=0; i<M; ++i) P[i] = 0;
			for (size_t i=0; i<N; ++i) Q[i] = 0;
		}
		else{
			ta = FFLAS::FflasNoTrans;
			L = FFLAS::fflas_new<Field::Element>(M*M);
			U = FFLAS::fflas_new<Field::Element>(M*N);
			P = FFLAS::fflas_new<size_t>(N);
			Q = FFLAS::fflas_new<size_t>(M);
			for (size_t i=0; i<N; ++i) P[i] = 0;
			for (size_t i=0; i<M; ++i) Q[i] = 0;
		}

		size_t R=0;
		Field::Element * G = FFLAS::fflas_new<Field::Element>(M*M);
		Field::Element * H = FFLAS::fflas_new<Field::Element>(M*N);
		size_t t;
		do{
			t = (size_t) random() % 10;
		} while ((!t)||(t==1));
		for (size_t i=0; i<M; ++i)
			if (!(random() % t))
				for (size_t j=0; j < M; ++j)
					RValue.random (*(G+i*M+j));
			else
				for (size_t j=0; j < M; ++j)
					F.assign(*(G+i*M+j), zero);



		for (size_t j=0; j < N; ++j)
			if (!(random() % t))
				for (size_t i=0; i<M; ++i)
					RValue.random (*(H+i*N+j));
			else
				for (size_t i=0; i<M; ++i)
					F.assign(*(H+i*N+j), zero);

// 		write_field(F,cerr<<"G = "<<endl,G,M,M,M);
// 		write_field(F,cerr<<"H = "<<endl,H,M,N,N);
		A = FFLAS::fflas_new<Field::Element>(M*N);
		FFLAS::fgemm (F, FFLAS::FflasNoTrans, FFLAS::FflasNoTrans, M, N, M, one, G, M, H, N, zero, A, N);
		FFLAS::fflas_delete( G);
		FFLAS::fflas_delete( H);

		Abis = FFLAS::fflas_new<Field::Element>(M*N);
		for (size_t i=0; i<M*N; ++i)
			*(Abis+i) = *(A+i);

		X = FFLAS::fflas_new<Field::Element>(M*N);


		cout <<"p = "<<(size_t)p<<" M = "<<M
		     <<" N = "<<N
		     <<((diag==FFLAS::FflasUnit)?" Unit ":" Non Unit ")
		     <<((ta==FFLAS::FflasNoTrans)?"LQUP ( A ) ":"LQUP ( A^T ) ")
		     <<"....";


		tim.clear();
		tim.start();
		R = FFPACK::LUdivine (F, diag, ta, M, N, A, lda, P, Q);
		tim.stop();


		//write_field(F,cerr<<"Result = "<<endl,Abis,M,N,lda);

		if (ta == FFLAS::FflasNoTrans){

			for (size_t i=0; i<R; ++i){
				for (size_t j=0; j<i; ++j)
					F.assign ( *(U + i*N + j), zero);
				for (size_t j=i+1; j<N; ++j)
					F.assign (*(U + i*N + j), *(A+ i*N+j));
			}
			for (size_t i=R;i<M; ++i)
				for (size_t j=0; j<N; ++j)
					F.assign(*(U+i*N+j), zero);
			for ( size_t i=0; i<M; ++i ){
				size_t j=0;
				for (; j< ((i<R)?i:R) ; ++j )
					F.assign( *(L + i*M+j), *(A+i*N+j));
				for (; j<M; ++j )
					F.assign( *(L+i*M+j), zero);
			}

			//write_field(F,cerr<<"L = "<<endl,L,M,M,M);
			//write_field(F,cerr<<"U = "<<endl,U,M,N,N);
			FFPACK::applyP( F, FFLAS::FflasRight, FFLAS::FflasNoTrans,
					M,0,(int) R, L, M, Q);
			for ( size_t  i=0; i<M; ++i )
				F.assign(*(L+i*(M+1)), one);

			if (diag == FFLAS::FflasNonUnit)
				for ( size_t  i=0; i<R; ++i )
					F.assign (*(U+i*(N+1)), *(A+i*(lda+1)));

			else{
				for (size_t i=0; i<R; ++i ){
					*(L+Q[i]*(M+1)) = *(A+Q[i]*lda+i);
					F.assign (*(U+i*(N+1)),one);
				}
			}

			FFPACK::applyP (F, FFLAS::FflasRight, FFLAS::FflasNoTrans,
					M,0,(int) R, U, N, P);
			FFPACK::applyP (F, FFLAS::FflasLeft, FFLAS::FflasTrans,
					N,0,(int) R, U, N, Q);
			FFLAS::fgemm (F, FFLAS::FflasNoTrans, FFLAS::FflasNoTrans, M,N,M, 1.0, L,M, U,N, 0.0, X,N);
			//FFLAS::fflas_delete( A);
		} else {

			for (size_t i=0; i<R; ++i){
				for (size_t j=0; j<i; ++j)
					F.assign ( *(L + i + j*N), zero);
				for (size_t j=i+1; j<M; ++j)
					F.assign (*(L + i + j*N), *(A+ i+j*N));
			}

			for (size_t i=R;i<N; ++i)
				for (size_t j=0; j<M; ++j)
					F.assign(*(L+i+j*N), zero);
			for ( size_t i=0; i<N; ++i ){
				size_t j=0;
				for (;  j< ((i<R)?i:R) ; ++j )
					F.assign( *(U + i+j*N), *(A+i+j*N));
				for (; j<N; ++j )
					F.assign( *(U+i+j*N), zero);
			}

			FFPACK::applyP( F, FFLAS::FflasLeft, FFLAS::FflasTrans,
					N,0,(int) R, U, N, Q);
			for (size_t i=0; i<N; ++i)
				F.assign (*(U+i*(N+1)),one);
			if (diag == FFLAS::FflasNonUnit)
				for ( size_t i=0; i<R; ++i )
					F.assign (*(L+i*(N+1)), *(A+i*(lda+1)));
			else{
				for ( size_t i=0; i<R; ++i ){
					*(U+Q[i]*(N+1)) = *(A+Q[i]+i*N);
					F.assign (*(L+i*(N+1)),one);
				}
			}
			// write_field(F,cerr<<"L = "<<endl,L,M,N,N);
// 			write_field(F,cerr<<"U = "<<endl,U,N,N,N);

			FFPACK::applyP (F, FFLAS::FflasLeft, FFLAS::FflasTrans,
					N,0,(int) R, L, N, P);
			FFPACK::applyP (F, FFLAS::FflasRight, FFLAS::FflasNoTrans,
					M,0,(int) R, L, N, Q);
			FFLAS::fgemm (F, FFLAS::FflasNoTrans, FFLAS::FflasNoTrans, M,N,N, 1.0, L,N, U,N, 0.0, X,N);
		}
		for (size_t i=0; i<M; ++i)
			for (size_t j=0; j<N; ++j)
				if (!F.areEqual (*(Abis+i*N+j), *(X+i*N+j))){
					cerr<<"error for i,j="<<i<<" "<<j<<" "<<*(Abis+i*N+j)<<" "<<*(X+i*N+j)<<endl;
					keepon = false;
				}

		//write_field(F,cerr<<"X = "<<endl,X,m,n,n);
		//write_field(F,cerr<<"B = "<<endl,B,m,n,n);

		if (keepon){
			cout<<"R = "<<R
			    <<" Passed "
			    <<(double(M*M)/1000.0*(double(N)-double(M)/3.0)/tim.usertime()/1000.0)<<"Mfops"<<endl;
			FFLAS::fflas_delete( A);
			FFLAS::fflas_delete( L);
			FFLAS::fflas_delete( U);
			FFLAS::fflas_delete( Abis);
			FFLAS::fflas_delete( X);
			FFLAS::fflas_delete( P);
			FFLAS::fflas_delete( Q);
		}
		else{
			cerr<<"Abis = "<<endl;
			write_field( F, cerr, Abis, (int) M, (int) N, (int) N );
			cerr<<"X = "<<endl;
			write_field( F, cerr, X, (int) M, (int) N, (int) N );
		}
	}
	cout<<endl;
	cerr<<"FAILED with p = "<<(size_t)p<<" M = "<<M<<" N = "<<N
	    <<" trans = "<<ta<<" diag = "<<diag<<endl;

	cerr<<"A:"<<endl;
	cerr<<M<<" "<<N<<" M"<<endl;
	for (size_t i=0; i<M; ++i)
		for (size_t j=0; j<N; ++j)
			if (*(Abis+i*lda+j))
				cerr<<i+1<<" "<<j+1<<" "<<((int) *(Abis+i*lda+j) )<<endl;
	cerr<<"0 0 0"<<endl<<endl;

	FFLAS::fflas_delete( A);
	FFLAS::fflas_delete( Abis);
	FFLAS::fflas_delete( L);
	FFLAS::fflas_delete( U);
	FFLAS::fflas_delete( X);
	FFLAS::fflas_delete( P);
	FFLAS::fflas_delete( Q);
}
Ejemplo n.º 5
0
int main(int argc, char** argv) {
  
	size_t iter = 3;
	int    q    = 131071;
	size_t    n    = 1000;
	size_t    k    = 1000;
	size_t threshold = 64;
	bool up =true;
	std::string file = "";
  
	Argument as[] = {
		{ 'q', "-q Q", "Set the field characteristic (-1 for random).",  TYPE_INT , &q },
		{ 'n', "-n N", "Set the dimension of the matrix C.",               TYPE_INT , &n },
		{ 'k', "-k K", "Set the other dimension of the matrix A.",               TYPE_INT , &k },
		{ 'u', "-u yes/no", "Updates an upper/lower triangular matrix.",  TYPE_BOOL , &up },
		{ 'i', "-i R", "Set number of repetitions.",                     TYPE_INT , &iter },
		{ 't', "-t T", "Set the threshold to the base case.",                     TYPE_INT , &threshold },
		END_OF_ARGUMENTS
	};

	FFLAS::parseArguments(argc,argv,as);
	
	typedef Givaro::ModularBalanced<double> Field;
	typedef Field::Element Element;
	
	Field F(q);
	Field::Element * A, *C;
	
	FFLAS::Timer chrono;
	double time=0.0;
	
	FFLAS_UPLO uplo = up?FflasUpper:FflasLower;
	for (size_t i=0;i<=iter;++i){
		A = fflas_new<Element>(n*k);
		size_t lda=k;
		C = fflas_new<Element>(n*n);
		size_t ldc=n;
		Field::RandIter G(F);
		RandomMatrix (F, n, k, A, k, G);
		RandomTriangularMatrix (F, n,n,uplo, FflasNonUnit, true, C, ldc, G);
		Field::Element_ptr D = FFLAS::fflas_new(F,k,1);
		Givaro::GeneralRingNonZeroRandIter<Field,Field::RandIter> nzG (G);
		for (size_t i=0; i<k; i++)
			nzG.random(D[i]);
		chrono.clear();
		if (i) chrono.start();
		fsyrk (F, uplo, FflasTrans, n, k, F.mOne, A, lda, D, 1, F.one, C, ldc, threshold);
		if (i) chrono.stop();
		
		time+=chrono.usertime();
		FFLAS::fflas_delete( A);
	}
  
		// -----------
		// Standard output for benchmark - Alexis Breust 2014/11/14
#define CUBE(x) ((x)*(x)*(x))
	std::cout << "Time: " << time / double(iter)
			  << " Gflops: " << CUBE(double(n)/1000.)/ time * double(iter);
	FFLAS::writeCommandString(std::cout, as) << std::endl;
	return 0;
}
Ejemplo n.º 6
0
int main(int argc, char** argv){


 FFLAS::Timer tim;
	Givaro::IntPrimeDom IPD;
	uint64_t p;
	size_t M, N, K ;
	bool keepon = true;
	Givaro::Integer _p,tmp;
	Field::Element zero,one;
	cerr<<setprecision(10);

	size_t TMAX = 300;
	size_t PRIMESIZE = 23;
	if (argc > 1 )
		TMAX = atoi(argv[1]);
	if (argc > 2 )
		PRIMESIZE = atoi(argv[2]);

	FFLAS::FFLAS_TRANSPOSE trans;
	FFLAS::FFLAS_SIDE side;
	FFLAS::FFLAS_UPLO uplo;
	FFLAS::FFLAS_DIAG diag;
	size_t lda, ldb;

	Field::Element * A, *Abis, *B,* Bbis;
	Field::Element alpha;

	while (keepon){
		srandom(_p);
		do{
			//		max = Integer::random(2);
			_p = random();//max % (2<<30);
			IPD.prevprime( tmp, (_p% (1<<PRIMESIZE)) );
			p =  tmp;
		}while( (p <= 2) );

		Field F (p);
		F.init (zero,0.0);
		F.init (one,1.0);
		Field::RandIter RValue (F);

		do{
			M = (size_t)  random() % TMAX;
			N = (size_t)  random() % TMAX;
		} while ((M == 0) || (N == 0));

		ldb = N;

		if (random()%2)
			trans = FFLAS::FflasNoTrans;
		else
			trans = FFLAS::FflasTrans;


		if (random()%2)
			diag = FFLAS::FflasUnit;
		else
			diag = FFLAS::FflasNonUnit;

		if (random()%2){
			side = FFLAS::FflasLeft;
			K = M;
			lda = M;
		} else {
			side = FFLAS::FflasRight;
			K = N;
			lda = N;
		}

		if (random()%2)
			uplo = FFLAS::FflasUpper;
		else
			uplo = FFLAS::FflasLower;

		while (F.isZero(RValue.random (alpha)));

		A = FFLAS::fflas_new<Field::Element>(K*K);
		B = FFLAS::fflas_new<Field::Element>(M*N);
		Abis = FFLAS::fflas_new<Field::Element>(K*K);
		Bbis = FFLAS::fflas_new<Field::Element>(M*N);
		for (size_t i = 0; i < M; ++i)
			for (size_t j = 0; j < N; ++j){
				RValue.random (*(B + i*N + j));
				*(Bbis + i*N + j) = *(B + i*N + j);
			}
		for (size_t i = 0; i < K; ++i)
			for (size_t j = 0; j < K; ++j)
				*(Abis + i*K + j) = RValue.random (*(A + i*K + j));
		for (size_t i = 0; i < K; ++i){
			while (F.isZero(RValue.random (*(A + i*(K+1)))));
			*(Abis + i*(K +1)) = *(A + i*(K+1));
		}

		cout <<"p = "<<(size_t)p
		     <<" M = "<<M
		     <<" N = "<<N
		     <<((side==FFLAS::FflasLeft)?" Left ":" Right ")
		     <<((uplo==FFLAS::FflasLower)?" Lower ":" Upper ")
		     <<((trans==FFLAS::FflasTrans)?" Trans ":" NoTrans ")
		     <<((diag==FFLAS::FflasUnit)?" Unit ":" NonUnit ")
		     <<"....";


		tim.clear();
		tim.start();
		FFLAS::ftrsm (F, side, uplo, trans, diag, M, N, alpha,
			      A, lda, B, ldb);
		tim.stop();

		// Verification
		Field::Element invalpha;
		F.inv(invalpha, alpha);
		FFLAS::ftrmm (F, side, uplo, trans, diag, M, N, invalpha,
			      A, K, B, N);
		for (size_t i = 0;i < M;++i)
			for (size_t j = 0;j < N; ++j)
				if ( !F.areEqual (*(Bbis + i*N+ j ), *(B + i*N + j))){
					cerr<<endl
					    <<"Bbis ["<<i<<", "<<j<<"] = "<<(*(Bbis + i*N + j))
					    <<" ; B ["<<i<<", "<<j<<"] = "<<(*(B + i*N + j));

					keepon = false;
				}
		for (size_t i = 0;i < K; ++i)
			for (size_t j = 0;j < K; ++j)
				if ( !F.areEqual (*(A + i*K + j), *(Abis + i*K + j))){
					cerr<<endl
					    <<"A ["<<i<<", "<<j<<"] = "<<(*(A + i*K + j))
					    <<" ; Abis ["<<i<<", "<<j<<"] = "<<(*(Abis + i*K + j));
					keepon = false;
				}
		if (keepon) {
			cout<<" Passed "
			    <<double(M*N)/1000000.0*double(K)/tim.usertime()<<" Mfops"<<endl;

			FFLAS::fflas_delete( B);
			FFLAS::fflas_delete( Bbis);
			FFLAS::fflas_delete( A);
			FFLAS::fflas_delete( Abis);
		} else {

			cerr<<endl;
			write_field (F, cerr<<"A = "<<endl, Abis, (int) K,(int) K,(int) K);
			write_field (F, cerr<<"B = "<<endl, Bbis, (int) M,(int) N,(int) N);
		}
	}

	cout<<endl;
	cerr<<"FAILED with p = "<<(size_t)p
	    <<" M = "<<M
	    <<" N = "<<N
	    <<" alpha = "<<alpha
	    <<((side==FFLAS::FflasLeft)?" Left ":" Right ")
	    <<((uplo==FFLAS::FflasLower)?" Lower ":" Upper ")
	    <<((trans==FFLAS::FflasTrans)?" Trans ":" NoTrans ")
	    <<((diag==FFLAS::FflasUnit)?" Unit ":" NonUnit ")
	    <<endl;

	cerr<<"A:"<<endl;
	cerr<<K<<" "<<K<<" M"<<endl;
	for (size_t i=0; i<K; ++i)
		for (size_t j=0; j<K; ++j)
			if ((*(Abis + i*lda + j)))
				cerr<<i+1<<" "<<j+1<<" "
				    <<((int) *(Abis+i*lda+j) )
				    <<endl;
	cerr<<"0 0 0"<<endl<<endl;

	cerr<<"B:"<<endl;
	cerr<<M<<" "<<N<<" M"<<endl;
	for (size_t i=0; i<M; ++i)
		for (size_t j=0; j<N; ++j)
			if ((*(Bbis + i*ldb + j)))
				cerr<<i+1<<" "<<j+1<<" "
				    <<((int) *(Bbis+i*ldb+j) )
				    <<endl;
	cerr<<"0 0 0"<<endl<<endl;

	FFLAS::fflas_delete( A);
	FFLAS::fflas_delete( Abis);
	FFLAS::fflas_delete( B);
	FFLAS::fflas_delete( Bbis);
}
Ejemplo n.º 7
0
int main(int argc, char** argv){

	int n,m,mb,nb;
	cerr<<setprecision(10);
	Field::Element zero, one;

	if (argc != 6)	{
		cerr<<"Usage : test-fgesv <p> <A> <b> <iter> <left/right>"
		    <<endl;
		exit(-1);
	}
	int nbit=atoi(argv[4]); // number of times the product is performed
	Field F(atoi(argv[1]));
	F.init(zero,0.0);
	F.init(one,1.0);
	Field::Element * A, *B, *X=NULL;
	A = read_field(F,argv[2],&m,&n);
	B = read_field(F,argv[3],&mb,&nb);

	FFLAS::FFLAS_SIDE side = (atoi(argv[5])) ? FFLAS::FflasRight :  FFLAS::FflasLeft;

	size_t ldx=0;
	size_t rhs = (side == FFLAS::FflasLeft) ? nb : mb;
	if (m != n) {
		if (side == FFLAS::FflasLeft){
			X = FFLAS::fflas_new<Field::Element>(n*nb);
			ldx = nb;
		}
		else {
			X = FFLAS::fflas_new<Field::Element>(mb*m);
			ldx = m;
		}
	}

	if ( ((side == FFLAS::FflasRight) && (n != nb))
	     || ((side == FFLAS::FflasLeft)&&(m != mb)) ) {
		cerr<<"Error in the dimensions of the input matrices"<<endl;
		exit(-1);
	}
	int info=0;
 FFLAS::Timer t; t.clear();
	double time=0.0;
	//write_field(F, cerr<<"A="<<endl, A, k,k,k);
	size_t R=0;
	for (int i = 0;i<nbit;++i){
		t.clear();
		t.start();
		if (m == n)
			R = FFPACK::fgesv (F, side, mb, nb, A, n, B, nb, &info);
		else
			R = FFPACK::fgesv (F, side, m, n, rhs, A, n, X, ldx, B, nb, &info);
		if (info > 0){
			std::cerr<<"System is inconsistent"<<std::endl;
			exit(-1);
		}

		t.stop();
		time+=t.usertime();
		if (i+1<nbit){
			FFLAS::fflas_delete(A);
			A = read_field(F,argv[2],&m,&n);
			FFLAS::fflas_delete( B);
			B = read_field(F,argv[3],&mb,&nb);
		}
	}

#if DEBUG
	Field::Element  *B2=NULL;
	FFLAS::fflas_delete( A);

	if (info > 0){
		std::cerr<<"System inconsistent"<<std::endl;
		exit (-1);
	}

	A = read_field(F,argv[2],&m,&n);

	B2 = FFLAS::fflas_new<Field::Element>(mb*nb);


	if (m==n)
		if (side == FFLAS::FflasLeft)
			FFLAS::fgemm (F, FFLAS::FflasNoTrans, FFLAS::FflasNoTrans, m, nb, n,
				      one, A, n, B, nb, zero, B2, nb);
		else
			FFLAS::fgemm (F, FFLAS::FflasNoTrans, FFLAS::FflasNoTrans, mb, n, m,
				      one, B, nb, A, n, zero, B2, nb);
	else
		if (side == FFLAS::FflasLeft)
			FFLAS::fgemm (F, FFLAS::FflasNoTrans, FFLAS::FflasNoTrans, m, nb, n,
				      one, A, n, X, ldx, zero, B2, nb);
		else
			FFLAS::fgemm (F, FFLAS::FflasNoTrans, FFLAS::FflasNoTrans, mb, n, m,
				      one, X, ldx, A, n, zero, B2, nb);
	FFLAS::fflas_delete( B);
	FFLAS::fflas_delete( X);

	B = read_field(F,argv[3],&mb,&nb);

	bool wrong = false;
	for (int i=0;i<mb;++i)
		for (int j=0;j<nb;++j)
			if ( !F.areEqual(*(B2+i*nb+j), *(B+i*nb+j))){
				cerr<<"B2 ["<<i<<", "<<j<<"] = "<<(*(B2+i*nb+j))
				    <<" ; B ["<<i<<", "<<j<<"] = "<<(*(B+i*nb+j))
				    <<endl;
				wrong = true;
			}

	if (wrong) {
		cerr<<"FAIL"<<endl;
		//write_field (F,cerr<<"B2="<<endl,B2,m,n,n);
		//write_field (F,cerr<<"B="<<endl,B,m,n,n);
	}else{

		cerr<<"PASS"<<endl;
	}


	FFLAS::fflas_delete( B2);
#endif

	FFLAS::fflas_delete( A);
	FFLAS::fflas_delete( B);
#if TIME
	double mflops;
	double cplx = (double)n*m*m-(double)m*m*m/3;
	if (side == FFLAS::FflasLeft)
		mflops = (cplx+(double)(2*R*R*n))/1000000.0*nbit/time;
	else
		mflops = (cplx+(double)(2*R*R*m))/1000000.0*nbit/time;
	cerr<<"m,n,mb,nb = "<<m<<" "<<n<<" "<<mb<<" "<<nb<<". fgesv "
	    <<((side == FFLAS::FflasLeft)?" Left ":" Right ")
	    <<"over Z/"<<atoi(argv[1])<<"Z :"
	    <<endl
	    <<"t= "
	    << time/nbit
	    << " s, Mffops = "<<mflops
	    << endl;

	cout<<m<<" "<<n<<" "<<mflops<<" "<<time/nbit<<endl;
#endif
}