Ejemplo n.º 1
0
/*
 * Does a single fwd+bwd fft of size n and checks it against python.
 * To test fftw replace fft_mkl with fft_fftw and set flag to MKL_ALIGN.
 */
void test_mkl(int n, enum mkl_align_flag flag){
	double *space = (double *)_mm_malloc((4*n+2)*sizeof(double), 64);
	double *v;
	switch(flag){
	case MKL_ALIGN:
		v = space;
		break;
	case MKL_NOALIGN:
		v = space+1;
		break;
	}
	double *w = v + 2*n;
	
	for(int i=0; i < n; i++){
		w[2*i] = v[2*i] = rand()*1.0/RAND_MAX - 0.5;
		w[2*i+1] = v[2*i+1] = rand()*1.0/RAND_MAX - 0.5;
	}

	verify_dir("DBG/");
	array_out(v, 2, n, "DBG/v.dat");
	fft_mkl fft(n);
	fft.fwd(v);
	array_out(v, 2, n, "DBG/vf.dat");
	system("test_fft.py DBG/v.dat DBG/vf.dat");

	fft.bwd(v);
	array_diff(v, w, 2*n);
	double rerror = array_max(v, 2*n)/array_max(w, 2*n);
	std::cout<<"\n\tfwd+bwd error in complex mkl 1D fft"<<std::endl;
	std::cout<<"\tn = "<<n<<std::endl;
	std::cout<<"\trel error = "<<rerror<<std::endl;

	_mm_free(space);
}
Ejemplo n.º 2
0
/*
 * anyarray_out		- output routine for pseudo-type ANYARRAY.
 *
 * We may as well allow this, since array_out will in fact work.
 * XCP needs to send from data nodes to coordinator values of that type.
 * To be able to restore values at the destination node we need to know
 * actual element type.
 */
Datum
anyarray_out(PG_FUNCTION_ARGS)
{
#ifdef XCP
	/*
	 * Output prefix: (type_namespace_name.typename) to look up actual element
	 * type at the destination node then output in usual format for array
	 */
	ArrayType  *v = PG_GETARG_ARRAYTYPE_P(0);
	Oid			element_type = ARR_ELEMTYPE(v);
	Form_pg_type typeForm;
	HeapTuple	typeTuple;
	char	   *typname,
			   *typnspname;
	/* two identifiers, parenthesis, dot and trailing \0 */
	char		prefix[2*NAMEDATALEN+4],
			   *retval,
			   *newval;
	int 		prefixlen, retvallen;
	Datum		array_out_result;
	MemoryContext save_context;

	save_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
	/* Figure out type name and type namespace */
	typeTuple = SearchSysCache(TYPEOID,
							   ObjectIdGetDatum(element_type),
							   0, 0, 0);
	if (!HeapTupleIsValid(typeTuple))
		elog(ERROR, "cache lookup failed for type %u", element_type);
	typeForm = (Form_pg_type) GETSTRUCT(typeTuple);
	typname = NameStr(typeForm->typname);
	typnspname = get_namespace_name(typeForm->typnamespace);

	sprintf(prefix, "(%s.%s)", typnspname, typname);
	ReleaseSysCache(typeTuple);
	MemoryContextSwitchTo(save_context);

	/* Get standard output and make up prefixed result */
	array_out_result = array_out(fcinfo);
	retval = DatumGetCString(array_out_result);
	prefixlen = strlen(prefix);
	retvallen = strlen(retval);
	newval = (char *) palloc(prefixlen + retvallen + 1);
	strcpy(newval, prefix);
	strcpy(newval + prefixlen, retval);

	pfree(retval);

	PG_RETURN_CSTRING(newval);
#else
	return array_out(fcinfo);
#endif
}
Ejemplo n.º 3
0
void PyPlot::prep_line(double *x, double *y, int n){
	assrt(state < 2);
	state = 1;
	linenum++;

	char fname[200];
	sprintf(fname,"FIGS/%s_x%d.dat", name, linenum);
	array_out(x, n, 1, fname);
	sprintf(fname,"FIGS/%s_y%d.dat", name, linenum);
	array_out(y, n, 1, fname);
	
	sprintf(cmdstr, 
		"x = genfromtxt('%s_x%d.dat', dtype='float')\n",
		name, linenum);
	issue_command(cmdstr);

	sprintf(cmdstr, 
		"y = genfromtxt('%s_y%d.dat', dtype='float')\n",
		name, linenum);
	issue_command(cmdstr);
}
Ejemplo n.º 4
0
void testlu(int n){
	double *A = new double[n*n];
	double *v = new double[n];
	for(int i = 0; i < n; i++){
		v[i] = rand()*1.0/RAND_MAX-0.5;
		for(int j = 0; j < n; j++)
			A[i+j*n] = rand()*1.0/RAND_MAX - 0.5;
	}
	verify_dir("DBG/");
	array_out(A, n, n, "DBG/A.dat");

	LU_Solve lu(A, n);
	lu.factorize();
	array_out(v, n, 1, "DBG/b.dat");
	lu.solve(v);
	array_out(v, n, 1, "DBG/x.dat");

	system("test_lusolve.py DBG/A.dat DBG/b.dat DBG/x.dat");

	delete[] v;
	delete[] A;
}
Ejemplo n.º 5
0
void PyPlot::yticks(double *y, int n){
	assrt(state==1);
	char fname[200];
	sprintf(fname,"FIGS/%s_yticks%d.dat", name, linenum);
	array_out(y, n, 1, fname);
	
	sprintf(cmdstr, 
		"yticks = genfromtxt('%s_yticks%d.dat', dtype='float')\n",
		name, linenum);
	issue_command(cmdstr);
	sprintf(cmdstr, "ax.set_yticks(yticks)\n");
	issue_command(cmdstr);
}
Ejemplo n.º 6
0
/*
 * anyarray_out		- output routine for pseudo-type ANYARRAY.
 *
 * We may as well allow this, since array_out will in fact work.
 */
Datum
anyarray_out(PG_FUNCTION_ARGS)
{
	return array_out(fcinfo);
}
Ejemplo n.º 7
0
/*
 * anyarray_out		- output routine for pseudo-type ANYARRAY.
 *
 * We may as well allow this, since array_out will in fact work.
 */
datum_t anyarray_out(PG_FUNC_ARGS)
{
	return array_out(fcinfo);
}