예제 #1
0
static bool testNonzeroRandom (Field &F, unsigned int iterations)
{
	int i;

	commentator().start ("Testing nonzero random elements", "testNonzeroRandom", iterations);

	bool ret = true;

	typename Field::Element x;
	typename Field::RandIter r (F);

	//NonzeroRandIter <Field, typename Field::RandIter> rp (F, r);
	Givaro::GeneralRingNonZeroRandIter <Field> rp (r);

	for (i = 0; i <(int) iterations; i++) {
		commentator().startIteration ((unsigned int)i);

		rp.random (x);

		ostream &report = commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_DESCRIPTION);
		report << "Element: ";
		F.write (report, x);
		report << endl;

		if (F.isZero (x)) {
			ret = false;
			commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR)
				<< "ERROR: Element is zero" << endl;
		}

		commentator().stop ("done");
		commentator().progress ();
	}

	commentator().stop (MSG_STATUS (ret), (const char *) 0, "testNonzeroRandom");

	return ret;
}
예제 #2
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;
}