Example #1
0
File: p3.cpp Project: 4ntoine/clang
void test_g0() {
  int array0[5];
  B<int, 5> b0 = g0(array0);
  const int array1[] = { 1, 2, 3};
  B<const int, 3> b1 = g0(array1);
  B<int, 3> b2 = g0b(array1);
}
Example #2
0
void bob::ip::base::TanTriggs::computeDoG(double sigma0, double sigma1, size_t size)
{
  // Generates two Gaussians with the given standard deviations
  // Warning: size should be odd
  blitz::Array<double,2> g0(size,size);
  blitz::Array<double,2> g1(size,size);
  const double inv_sigma0_2 = 0.5  / (sigma0*sigma0);
  const double inv_sigma1_2 = 0.5  / (sigma1*sigma1);
  int center = ((int)size) / 2;
  for(int y=0; y<(int)size; ++y)
    for(int x=0; x<(int)size; ++x)
    {
      int yy = y - center;
      int xx = x - center;
      int xx2 = xx*xx;
      int yy2 = yy*yy;

      g0(y,x) = exp( - inv_sigma0_2 * (xx2 + yy2) );
      g1(y,x) = exp( - inv_sigma1_2 * (xx2 + yy2) );
    }

  // Normalize the kernels such that the sum over the area is equal to 1
  // and compute the Difference of Gaussian filter
  const double inv_sum0 = 1. / blitz::sum(g0);
  const double inv_sum1 = 1. / blitz::sum(g1);
  m_kernel.resize( size, size);
  m_kernel = inv_sum0 * g0 - inv_sum1 * g1;
}
int main(int argc, char** argv)
{
	if (argc < 3)
	{
		std::cout << "Usage: combustion-vineyard FRAME1 FRAME2" << std::endl;
		exit(0);
	}
	
	int size0, nc0;
	int size1, nc1;

	std::cout << "Reading: " << argv[1] << std::endl;
	std::ifstream ifs0(argv[1], std::ios::binary);
	std::cout << "Reading: " << argv[2] << std::endl;
	std::ifstream ifs1(argv[2], std::ios::binary);

	if (!ifs0 || !ifs1)
	{
		std::cout << "Could not open the frames" << std::endl;
		exit(0);
	}

	read(ifs0, size0); read(ifs0, nc0);
	read(ifs1, size1); read(ifs1, nc1);

	assert(size0 == size1); assert(nc0 == nc1);
	assert(size0 == xsize*ysize);
	
	Grid2D g0(xsize, ysize), g1(xsize, ysize);
	
	for (int y = 0; y < ysize; ++y)
		for (int x = 0; x < xsize; ++x)
			for (int d = 0; d < nc0; ++d)
			{
				float val0, val1;
				read(ifs0, val0);
				read(ifs1, val1);
				if (d == var)
				{
					g0(x,y) = val0;
					g1(x,y) = val1;
				}
			}
	std::cout << "Grids read" << std::endl;
	
	// Generate filtration and compute pairing
	Grid2DVineyard v(&g0);
	std::cout << "Filtration generated, size: " << v.filtration()->size() << std::endl;
	v.compute_pairing();
	std::cout << "Pairing computed" << std::endl;
	
	// Compute vineyard
	v.compute_vineyard(&g1, true);
	std::cout << "Vineyard computed" << std::endl;

	v.vineyard()->save_edges("combustion");
}
void generate(int dim, char* filename)
{
	#if (!defined MPI_VERSION || MPI_VERSION<2) && (defined BGQ)
	std::cerr<<"Error: MPI-2 is required for CCNI."<<std::endl;
	exit(1);
	#endif
	static unsigned long tstart;

	int rank=0;
	#ifdef MPI_VERSION
	rank = MPI::COMM_WORLD.Get_rank();
	int np = MPI::COMM_WORLD.Get_size();
	#endif
	#ifdef DEBUG
	if (rank==0) {
		if (!isLittleEndian()) std::cout<<"Byte order is big-endian."<<std::endl;
	}
	#endif
	if (dim == 2)	{
		const int edge = 8192;
		int number_of_fields = 5120000;
		grid<2,sparse<phi_type> > initGrid(0, 0, edge, 0, edge);
		if (rank==0) std::cout<<"Grid origin: ("<<g0(initGrid,0)<<','<<g0(initGrid,1)<<"),"
			                      <<" dimensions: "<<g1(initGrid,0)-g0(initGrid,0)<<" × "<<g1(initGrid,1)-g0(initGrid,1)
			                      <<" with "<<number_of_fields<<" seeds"<<std::flush;
		#ifdef MPI_VERSION
		number_of_fields /= np;
		if (rank==0) std::cout<<", "<<number_of_fields<<" per rank"<<std::flush;
		if (rank==0 && number_of_fields % np != 0)
			std::cerr<<"\nWarning: Tessellation may hang with uneven distribution of seeds per thread."<<std::endl;
		#endif
		if (rank==0) std::cout<<"."<<std::endl;

		#if (!defined MPI_VERSION) && (defined BGQ)
		std::cerr<<"Error: Blue Gene requires MPI."<<std::endl;
		std::exit(-1);
		#endif
		tstart = time(NULL);
		tessellate<2,phi_type>(initGrid, number_of_fields);
		if (rank==0) std::cout<<"Tessellation complete ("<<time(NULL)-tstart<<" sec)."<<std::endl;
		#ifdef MPI_VERSION
		MPI::COMM_WORLD.Barrier();
		#endif
		tstart=time(NULL);
		output(initGrid, filename);
		if (rank==0) std::cout<<"Voronoi tessellation written to "<<filename<<" ("<<time(NULL)-tstart<<" sec)."<<std::endl;
	}
}
bool sanity()
{  
   GameState g0(5, 7, 7);    // Not a valid game state 
   GameState g1(1, 2, 254);  // Finish in 1 round
   GameState g2(2, 3, 254);  //   ...  in 2 rounds
   GameState g3(3, 4, 254);  //   ...  in 3 rounds
   GameState g4(4, 5, 254);  //
   GameState g5(4, 9, 254);  // These come from a (slower) python implementation
   GameState g6(8, 11, 254);
   GameState g7(12, 19, 254);
   GameState g8(8, 35, 254);
   
   GameState g9(1, 4, 6);   // From webpage, known to finish in 15 minutes = at round 2
   
   if (explore_game(g0)!=0) return false; // Verify that we get the expected number
   if (explore_game(g1)!=1) return false; // of rounds for given input states
   if (explore_game(g2)!=2) return false; //
   if (explore_game(g3)!=3) return false; // report an error if not
   if (explore_game(g4)!=4) return false;
   if (explore_game(g5)!=5) return false;
   if (explore_game(g6)!=6) return false;
   if (explore_game(g7)!=7) return false;
   if (explore_game(g8)!=8) return false;
   if (explore_game(g9)!=2) return false;
   
   return true;
}
Example #6
0
 void object::test<3>()
 {
   GeomPtr g0(wktreader.read("LINESTRING(0 0, 10 0)"));
   GeomPtr g1(wktreader.read("LINESTRING(20 0, 20 0)"));
   forwDir.clear(); backDir.clear();
   SharedPathsOp::sharedPathsOp(*g0, *g1, forwDir, backDir);
   ensure(forwDir.empty());
   ensure(backDir.empty());
 }
Example #7
0
int main( void )
{
    g0();
    g1();
    g2();
    g3();
    g4();
    return 0;
}
Example #8
0
__complex__ double
xcexp (__complex__ double x)
{
  double r;

  r = g0 (__real__ x);
  __real__ x = r * g1 (__imag__ x);
  __imag__ x = r * g2 (__imag__ x);
  return x;
}
Example #9
0
int main1(void)
{ 
  int i;
  /* Check vec_extract with a non constant element numbering */
  for(i=0;i<10;i++)
    { 
      if (f(a, i) != (i&0x3))
        abort ();
    }
  
  /* Check vec_extract with a constant element numbering */
  if (f0(a) != 0)
    abort ();
  if (f1(a) != 1)
    abort ();
  if (f2(a) != 2)
    abort ();
  if (f3(a) != 3)
    abort ();
  /* Check that vec_extract works with a constant element higher than
     the number of elements.  */
  if (f4(a) != 0)
    abort ();

  /* Check vec_extract with a non constant element numbering */
  for(i=0;i<10;i++)
    {
      if (g(b, i) != (i&0x7))
        abort ();
    }
  
  /* Check vec_extract with a constant element numbering */
  if (g0(b) != 0)
    abort ();
  if (g1(b) != 1)
    abort ();
  if (g2(b) != 2)
    abort ();
  if (g3(b) != 3)
    abort ();
  if (g4(b) != 4)
    abort ();
  if (g5(b) != 5)
    abort ();
  if (g6(b) != 6)
    abort ();
  if (g7(b) != 7)
    abort ();
  /* Check that vec_extract works with a constant element higher than
     the number of elements.  */
  if (g8(b) != 0)
    abort ();
  
  return 0;
}
Example #10
0
 void object::test<9>()
 {
   GeomPtr g0(wktreader.read("LINESTRING(-15 0, 15 0)"));
   GeomPtr g1(wktreader.read("LINESTRING(10 0, -10 0)"));
   forwDir.clear(); backDir.clear();
   SharedPathsOp::sharedPathsOp(*g0, *g1, forwDir, backDir);
   ensure(forwDir.empty());
   ensure_equals(backDir.size(), 1u);
   ensure_equals(wktwriter.write(backDir[0]), "LINESTRING (-10 0, 10 0)");
   SharedPathsOp::clearEdges(backDir);
 }
Example #11
0
File: call.c Project: 4ntoine/clang
void test() {
  f0(0, 0);
  g0(0, 0);
  f1(0, 0);
  // RUN: %clang_cc1 -std=c89 -fsyntax-only  -code-completion-at=%s:6:6 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
  // CHECK-CC1: f0(<#float x#>, float y)
  // RUN: %clang_cc1 -std=c89 -fsyntax-only -code-completion-at=%s:6:9 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
  // CHECK-CC2: f0(float x, <#float y#>)
  // RUN: %clang_cc1 -std=c89 -fsyntax-only -code-completion-at=%s:8:6 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
  // CHECK-CC3: f1()
}
Example #12
0
 void object::test<2>()
 {
   GeomPtr g0(wktreader.read("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))"));
   GeomPtr g1(wktreader.read("LINESTRING(0 0, 10 0)"));
   bool threw = false;
   try {
     SharedPathsOp::sharedPathsOp(*g0, *g1, forwDir, backDir);
   } catch (const geos::util::IllegalArgumentException& /*ex*/) {
     threw = true;
   }
   ensure(threw);
 }
Example #13
0
void f0(void) {
  result = 1;
  
  bool_mul(bool_id(1));
  aggr_mul(aggr_id((AggrTy) { 2, 3, 5}));
  empty_mul(empty_id((EmptyTy) {}));
  scalar_mul(scalar_id(7));
  complex_mul(complex_id(11 + 13i));
  
  // This call should be eliminated.
  if (result != 2 * 3 * 5 * 7 * 11 * 13 * 53)
    g0();
}
Example #14
0
/**
 * Encrypt a single block of data.
 */
void skipjack_encrypt(byte tab[10][256], byte in[8], byte out[8]) {
	word32 w1, w2, w3, w4;

	w1 = (in[0] << 8) + in[1];
	w2 = (in[2] << 8) + in[3];
	w3 = (in[4] << 8) + in[5];
	w4 = (in[6] << 8) + in[7];

	/* stepping rule A: */
	g0(tab, w1); w4 ^= w1 ^ 1;
	g1(tab, w4); w3 ^= w4 ^ 2;
	g2(tab, w3); w2 ^= w3 ^ 3;
	g3(tab, w2); w1 ^= w2 ^ 4;
	g4(tab, w1); w4 ^= w1 ^ 5;
	g0(tab, w4); w3 ^= w4 ^ 6;
	g1(tab, w3); w2 ^= w3 ^ 7;
	g2(tab, w2); w1 ^= w2 ^ 8;

	/* stepping rule B: */
	w2 ^= w1 ^  9; g3(tab, w1);
	w1 ^= w4 ^ 10; g4(tab, w4);
	w4 ^= w3 ^ 11; g0(tab, w3);
	w3 ^= w2 ^ 12; g1(tab, w2);
	w2 ^= w1 ^ 13; g2(tab, w1);
	w1 ^= w4 ^ 14; g3(tab, w4);
	w4 ^= w3 ^ 15; g4(tab, w3);
	w3 ^= w2 ^ 16; g0(tab, w2);

	/* stepping rule A: */
	g1(tab, w1); w4 ^= w1 ^ 17;
	g2(tab, w4); w3 ^= w4 ^ 18;
	g3(tab, w3); w2 ^= w3 ^ 19;
	g4(tab, w2); w1 ^= w2 ^ 20;
	g0(tab, w1); w4 ^= w1 ^ 21;
	g1(tab, w4); w3 ^= w4 ^ 22;
	g2(tab, w3); w2 ^= w3 ^ 23;
	g3(tab, w2); w1 ^= w2 ^ 24;

	/* stepping rule B: */
	w2 ^= w1 ^ 25; g4(tab, w1);
	w1 ^= w4 ^ 26; g0(tab, w4);
	w4 ^= w3 ^ 27; g1(tab, w3);
	w3 ^= w2 ^ 28; g2(tab, w2);
	w2 ^= w1 ^ 29; g3(tab, w1);
	w1 ^= w4 ^ 30; g4(tab, w4);
	w4 ^= w3 ^ 31; g0(tab, w3);
	w3 ^= w2 ^ 32; g1(tab, w2);

	out[0] = (byte)(w1 >> 8); out[1] = (byte)w1;
	out[2] = (byte)(w2 >> 8); out[3] = (byte)w2;
	out[4] = (byte)(w3 >> 8); out[5] = (byte)w3;
	out[6] = (byte)(w4 >> 8); out[7] = (byte)w4;

}
Example #15
0
  void object::test<15>()
  {
    GeomPtr g0(wktreader.read("MULTILINESTRING((-10 0, -5 0),(10 0, 5 0))"));
    GeomPtr g1(wktreader.read("MULTILINESTRING((6 0, 12 0),(-2 0, -8 0))"));
    forwDir.clear(); backDir.clear();
    SharedPathsOp::sharedPathsOp(*g0, *g1, forwDir, backDir);

    ensure_equals(backDir.size(), 2u);
    ensure_equals(wktwriter.write(backDir[0]), "LINESTRING (-8 0, -5 0)");
    ensure_equals(wktwriter.write(backDir[1]), "LINESTRING (10 0, 6 0)");
    SharedPathsOp::clearEdges(backDir);

    ensure(forwDir.empty());
  }
Example #16
0
  void SurfaceBasis<EvalT, Traits>::computeDualBaseVectors(
      const MFC & midplaneCoords,
      const PHX::MDField<MeshScalarT, Cell, QuadPoint, Dim, Dim> basis,
      PHX::MDField<MeshScalarT, Cell, QuadPoint, Dim> normal,
      PHX::MDField<MeshScalarT, Cell, QuadPoint, Dim, Dim> dualBasis)
  {
    std::size_t worksetSize = midplaneCoords.dimension(0);

    Intrepid::Vector<MeshScalarT> g_0(0, 0, 0), g_1(0, 0, 0), g_2(0, 0, 0), g0(0, 0, 0),
        g1(0, 0, 0), g2(0, 0, 0);

    for (std::size_t cell(0); cell < worksetSize; ++cell) {
      for (std::size_t pt(0); pt < numQPs; ++pt) {
        g_0 = Intrepid::Vector<MeshScalarT>(3, &basis(cell, pt, 0, 0));
        g_1 = Intrepid::Vector<MeshScalarT>(3, &basis(cell, pt, 1, 0));
        g_2 = Intrepid::Vector<MeshScalarT>(3, &basis(cell, pt, 2, 0));

        normal(cell, pt, 0) = g_2(0);
        normal(cell, pt, 1) = g_2(1);
        normal(cell, pt, 2) = g_2(2);

        g0 = cross(g_1, g_2) / dot(g_0, cross(g_1, g_2));
        g1 = cross(g_0, g_2) / dot(g_1, cross(g_0, g_2));
        g2 = cross(g_0, g_1) / dot(g_2, cross(g_0, g_1));

        dualBasis(cell, pt, 0, 0) = g0(0);
        dualBasis(cell, pt, 0, 1) = g0(1);
        dualBasis(cell, pt, 0, 2) = g0(2);
        dualBasis(cell, pt, 1, 0) = g1(0);
        dualBasis(cell, pt, 1, 1) = g1(1);
        dualBasis(cell, pt, 1, 2) = g1(2);
        dualBasis(cell, pt, 2, 0) = g2(0);
        dualBasis(cell, pt, 2, 1) = g2(1);
        dualBasis(cell, pt, 2, 2) = g2(2);
      }
    }
  }
Example #17
0
geom::Geometry* CascadedPolygonUnion::binaryUnion(GeometryListHolder* geoms, 
    std::size_t start, std::size_t end)
{
    if (end - start <= 1) {
        return unionSafe(geoms->getGeometry(start), NULL);
    }
    else if (end - start == 2) {
        return unionSafe(geoms->getGeometry(start), geoms->getGeometry(start + 1));
    }
    else {
        // recurse on both halves of the list
        std::size_t mid = (end + start) / 2;
        std::auto_ptr<geom::Geometry> g0 (binaryUnion(geoms, start, mid));
        std::auto_ptr<geom::Geometry> g1 (binaryUnion(geoms, mid, end));
        return unionSafe(g0.get(), g1.get());
    }
}
Example #18
0
/**
 * Encrypt a single block of data.
 */
void SKIPJACK::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
{
	word w1, w2, w3, w4;
	Block::Get(inBlock)(w4)(w3)(w2)(w1);

	/* stepping rule A: */
	g0(tab, w1); w4 ^= w1 ^ 1;
	g1(tab, w4); w3 ^= w4 ^ 2;
	g2(tab, w3); w2 ^= w3 ^ 3;
	g3(tab, w2); w1 ^= w2 ^ 4;
	g4(tab, w1); w4 ^= w1 ^ 5;
	g0(tab, w4); w3 ^= w4 ^ 6;
	g1(tab, w3); w2 ^= w3 ^ 7;
	g2(tab, w2); w1 ^= w2 ^ 8;

	/* stepping rule B: */
	w2 ^= w1 ^  9; g3(tab, w1);
	w1 ^= w4 ^ 10; g4(tab, w4);
	w4 ^= w3 ^ 11; g0(tab, w3);
	w3 ^= w2 ^ 12; g1(tab, w2);
	w2 ^= w1 ^ 13; g2(tab, w1);
	w1 ^= w4 ^ 14; g3(tab, w4);
	w4 ^= w3 ^ 15; g4(tab, w3);
	w3 ^= w2 ^ 16; g0(tab, w2);

	/* stepping rule A: */
	g1(tab, w1); w4 ^= w1 ^ 17;
	g2(tab, w4); w3 ^= w4 ^ 18;
	g3(tab, w3); w2 ^= w3 ^ 19;
	g4(tab, w2); w1 ^= w2 ^ 20;
	g0(tab, w1); w4 ^= w1 ^ 21;
	g1(tab, w4); w3 ^= w4 ^ 22;
	g2(tab, w3); w2 ^= w3 ^ 23;
	g3(tab, w2); w1 ^= w2 ^ 24;

	/* stepping rule B: */
	w2 ^= w1 ^ 25; g4(tab, w1);
	w1 ^= w4 ^ 26; g0(tab, w4);
	w4 ^= w3 ^ 27; g1(tab, w3);
	w3 ^= w2 ^ 28; g2(tab, w2);
	w2 ^= w1 ^ 29; g3(tab, w1);
	w1 ^= w4 ^ 30; g4(tab, w4);
	w4 ^= w3 ^ 31; g0(tab, w3);
	w3 ^= w2 ^ 32; g1(tab, w2);

	Block::Put(xorBlock, outBlock)(w4)(w3)(w2)(w1);
}
Example #19
0
Foam::tmp<Foam::Field<Foam::scalar>>
Foam::ParticleStressModels::Lun::tau
(
    const Field<scalar>& alpha,
    const Field<scalar>& rho,
    const Field<scalar>& uSqr
) const
{
    tmp<Field<scalar>> g0
    (
        0.6
      / max
        (
            1.0 - pow(alpha/alphaPacked_,1.0/3.0),
            max(eps_*(1.0 - alpha), small)
        )
    );

    tmp<Field<scalar>> gT(uSqr/3.0);

    return alpha*rho*(1.0 + alpha*(1.0 + e_)*g0)*gT;
}
Example #20
0
void quadratic_prog(const Vector6d &f, double &lambda, double &miu) 
{ 
	const double a=f[0], b=f[3], c=f[1], d=f[4], e=f[5];
	double sum = 0.0;  
	const int N = 2;

	Matrix<double> G(N, N);
	G[0][0]=2*a, G[0][1]=b;
	G[1][0]=b, G[1][1]=2*c;
	
    Vector<double> g0(N);
	g0[0]=d, g0[1]=e;
  
	//eq constraints
	/*
	Matrix<double> CE(n, m);
	CE[0][0]=1, CE[1][0]=1;
	Vector<double> ce0(m);
	ce0[0]=-3;
	*/
	Matrix<double> CE;
	Vector<double> ce0;
	
	//in-eq constraints
	Matrix<double> CI(N, N);
	CI[0][0]=1, CI[0][1]=0;
	CI[1][0]=0, CI[1][1]=1;
	Vector<double> ci0(N);
	ci0[0]=0, ci0[1]=-0.001;

	//===========================
	Vector<double> x(N);
	const double rr = solve_quadprog(G, g0, CE, ce0, CI, ci0, x) + f.z;
	std::cout << "MinF: " << rr <<  " x: " << x[0] <<", " <<x[1] << std::endl;
	lambda = x[0];
	miu = x[1];
}
Example #21
0
Skeleton_basic::Neighbours::Neighbours( const clipper::Xmap_base &map, const float min_distsq, const float max_distsq )
{
   /*
   note that thisd2 is a mesure of distance in real space

   So here we look around an arbitary current point and take note if
   the distance between the centre point and points one unit away from
   it (all directions) is less than a certain cuttoff distance.  We
   are left with a list of ndn neighbouring cells that are
   sufficicently close to be considered neighbours.
    
   Typically, ndn will be 18-20 at then end of this block.

   Note that body diagonals have length sqrt(3) ~= 1.73, but we passed
   squared limits.
   */

  clipper::Cell_descr rcd( map.cell().descr() );
  clipper::Cell_descr vcd( 1.0,1.0,1.0, rcd.alpha(), rcd.beta(), rcd.gamma() );
  clipper::Cell vcell( vcd );

  clipper::Coord_grid g0(-1,-1,-1); 
  clipper::Coord_grid g1( 1, 1, 1);
  clipper::Grid_sampling vgrid( 1, 1, 1 );

  clipper::Coord_grid iu, iv, iw;
  float thisd2;
  for ( iu = g0; iu.u() <= g1.u(); iu.u()++ ) {
     for ( iv = iu; iv.v() <= g1.v(); iv.v()++ ) {
        for ( iw = iv; iw.w() <= g1.w(); iw.w()++ ) {
           thisd2 = iw.coord_frac( vgrid ).lengthsq( vcell );
           if (thisd2 > min_distsq && thisd2 < max_distsq) nlist.push_back( iw );
        }
     }
  }
}
Example #22
0
int main(void)
{
/***************************** Natrual Syntax ********************************/
  Base a;
  Base b;
  Base c;
  Derived aa;

  // test ordinary function
  functor<void( ) > g0(&test0);
  g0();

  functor<double (double)> g1;
  g1 = &test1;
  assert(12.123 == g1(12.123));

  // test member function
  functor<void (int)> g2(&Base::d);
  functor<int (int)> g3(&Base::static_b);
  functor<int (int, int, int, int, int, int, int, int, int)> g4(&Base::d9);
  functor<int (int)> g5(&Base::virtual_c);
  // operator =
  functor<int (int, int)> g6;
  g6 = &Derived::Derived_a2; 

  functor<int (int)> g7(&Derived::virtual_c);
  // copy constructor
  functor<int (int)> g7_2;
  g7_2 = g7;
  functor<int (int)> g7_3(g7);
  // reference 
  functor<int (int)> &g7_4 = g7;
  // pointer 
  functor<int (int)> *g7_5 = &g7;


  g2(&a, 18);
  assert(18 == a.getBase());
  assert(g3(29) == 29);
  assert(g4(&b, 1,2,3,4,5,6,7,8,9) == (1+2+3+4+5+6+7+8+9));
  assert(g5(&c, 5) == 5);
  assert(g6(&aa, 5, 6) == 5+6);
  assert(g7(&aa, 6) == 10+6);
  assert(g7_2(&aa, 6) == 10+6);
  assert(g7_3(&aa, 6) == 10+6);
  assert(g7_4(&aa, 6) == 10+6);
  assert((*g7_5)(&aa, 6) == 10+6);

/************************************* STL *************************************/
  int myints[] = {32,71,12,45,26,80,53,33};
  std::vector<int> myvector1(myints, myints+8);
  std::vector<int> myvector2(myints, myints+8);

  functor<bool (int, int)> functorCmp = &mycmp;

  std::sort(myvector1.begin(), myvector1.end());
  std::sort(myvector2.begin(), myvector2.end(), functorCmp);

  assert(myvector1.size() == myvector2.size());
  for (unsigned int i = 0; i < myvector1.size(); ++i) {
    assert(myvector1[i] == myvector2[i]);
  }

/***************************** Performance Test ********************************/
//  performanceTest (500000000);

  return 0;
}
Example #23
0
#define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
int x;
EVAL_EXPR(1, (_Bool)&x)
EVAL_EXPR(2, (int)(1.0+(double)4))
EVAL_EXPR(3, (int)(1.0+(float)4.0))
EVAL_EXPR(4, (_Bool)(1 ? (void*)&x : 0))
EVAL_EXPR(5, (_Bool)(int[]){0})
struct y {int x,y;};
EVAL_EXPR(6, (int)(1+(struct y*)0))
EVAL_EXPR(7, (int)&((struct y*)0)->y)
EVAL_EXPR(8, (_Bool)"asdf")
EVAL_EXPR(9, !!&x)
EVAL_EXPR(10, ((void)1, 12))
void g0(void);
EVAL_EXPR(11, (g0(), 12)) // FIXME: This should give an error
EVAL_EXPR(12, 1.0&&2.0)
EVAL_EXPR(13, x || 3.0)

unsigned int l_19 = 1;
EVAL_EXPR(14, (1 ^ l_19) && 1); // expected-error {{fields must have a constant size}}

void f()
{
  int a;
  EVAL_EXPR(15, (_Bool)&a); // expected-error {{fields must have a constant size}}
}

// FIXME: Turn into EVAL_EXPR test once we have more folding.
_Complex float g16 = (1.0f + 1.0fi);
Example #24
0
void f0() {
  g0(1, 2, 3); // expected-error{{too many arguments to function call}}
}
Example #25
0
template <int dim> void update(grid<dim, sparse<phi_type> >& oldGrid, int steps)
{
	int rank=0;
	#ifdef MPI_VERSION
	rank=MPI::COMM_WORLD.Get_rank();
	#endif
	const phi_type dt = 0.01;
	const phi_type width = 14.5;
	const phi_type epsilon = 1.0e-8;
	const double mu_hi = 1.00;
	const double mu_lo = 0.01;
	const double mu_x = 0.6422;
	const double mu_s = 0.0175;

	std::ofstream vfile;
	if (rank==0)
		vfile.open("v.log",std::ofstream::out | std::ofstream::app);

	for (int step = 0; step < steps; step++) {
		if (rank==0) print_progress(step, steps);
		// newGrid grid must be overwritten each time
		ghostswap(oldGrid);
		grid<dim, sparse<phi_type> > newGrid(oldGrid);

		for (int d=0; d<dim; d++) {
			if (x0(oldGrid, d) == g0(oldGrid,d)) {
				b0(oldGrid,d) = Dirichlet;
				b0(newGrid,d) = Dirichlet;
			} else if (x1(oldGrid,d) == g1(oldGrid,d)) {
				b1(oldGrid,d) = Dirichlet;
				b1(newGrid,d) = Dirichlet;
			}
		}

		for (int i = 0; i < nodes(oldGrid); i++) {
			vector<int> x = position(oldGrid, i);

			// determine nonzero fields within
			// the neighborhood of this node
			// (2 adjacent voxels along each cardinal direction)
			sparse<int> s;
			for (int j = 0; j < dim; j++)
				for (int k = -1; k <= 1; k++) {
					x[j] += k;
					for (int h = 0; h < length(oldGrid(x)); h++) {
						int pindex = index(oldGrid(x), h);
						set(s, pindex) = 1;
					}
					x[j] -= k;
				}
			phi_type S = phi_type(length(s));

			// if only one field is nonzero,
			// then copy this node to newGrid
			if (S < 2.0) newGrid(i) = oldGrid(i);
			else {
				// compute laplacian of each field
				sparse<phi_type> lap = laplacian(oldGrid, i);

				// compute variational derivatives
				sparse<phi_type> dFdp;
				for (int h = 0; h < length(s); h++) {
					int hindex = index(s, h);
					for (int j = h + 1; j < length(s); j++) {
						int jindex = index(s, j);
						phi_type gamma = energy(hindex, jindex);
						phi_type eps = 4.0 / acos(-1.0) * sqrt(0.5 * gamma * width);
						phi_type w = 4.0 * gamma / width;
						// Update dFdp_h and dFdp_j, so the inner loop can be over j>h instead of j≠h
						set(dFdp, hindex) += 0.5 * eps * eps * lap[jindex] + w * oldGrid(i)[jindex];
						set(dFdp, jindex) += 0.5 * eps * eps * lap[hindex] + w * oldGrid(i)[hindex];
					}
				}

				// compute time derivatives
				sparse<phi_type> dpdt;
				phi_type mu = mobility(mu_lo, mu_hi, mu_x, mu_s, oldGrid(x).getMagPhi());

				for (int h = 0; h < length(s); h++) {
					int hindex = index(s, h);
					for (int j = h + 1; j < length(s); j++) {
						int jindex = index(s, j);
						set(dpdt, hindex) -= mu * (dFdp[hindex] - dFdp[jindex]);
						set(dpdt, jindex) -= mu * (dFdp[jindex] - dFdp[hindex]);
					}
				}

				// compute update values
				phi_type sum = 0.0;
				for (int h = 0; h < length(s); h++) {
					int pindex = index(s, h);
					phi_type value = oldGrid(i)[pindex] + dt * (2.0 / S) * dpdt[pindex]; // Extraneous factor of 2?
					if (value > 1.0) value = 1.0;
					if (value < 0.0) value = 0.0;
					if (value > epsilon) set(newGrid(i), pindex) = value;
					sum += newGrid(i)[pindex];
				}

				// project onto Gibbs simplex (enforce Σφ=1)
				phi_type rsum = 0.0;
				if (fabs(sum) > 0.0) rsum = 1.0 / sum;
				for (int h = 0; h < length(newGrid(i)); h++) {
					int pindex = index(newGrid(i), h);
					set(newGrid(i), pindex) *= rsum;
				}
			}

		} // Loop over nodes(oldGrid)

		if ((step+1) % 10 == 0) {
			// Scan along just above the mid-line for the grain boundary.
			// When found, determine its angle.
			vector<int> x(dim, 0);
			const int offset = 2;

			const phi_type vert_mag = 1.0/std::sqrt(3.0);
			const phi_type edge_mag = 1.0/std::sqrt(2.0);
			const phi_type bulk_mag = 1.0;

			const phi_type edge_contour = edge_mag + 0.125*(bulk_mag - edge_mag);
			const phi_type vert_contour = vert_mag + 0.125*(edge_mag - vert_mag);

			x[0] = x0(newGrid,0);
			x[1] = (g1(newGrid,1) - g0(newGrid,1))/2;
			while (x[0]<x1(newGrid) && x[1]>=y0(newGrid) && x[1]<y1(newGrid) && newGrid(x).getMagPhi()>vert_contour)
				x[0]++;
			if (x[0] == x1(newGrid))
				x[0] = g0(newGrid,0);
			int v0 = x[0];
			#ifdef MPI_VERSION
			MPI::COMM_WORLD.Allreduce(&x[0], &v0, 1, MPI_INT, MPI_MAX);
			#endif

			x[1] += offset;
			while (x[0]>= x0(newGrid) && x[0]<x1(newGrid) && x[1]>=y0(newGrid) && x[1]<y1(newGrid) && newGrid(x).getMagPhi()>edge_contour)
				x[0]++;
			if (x[0] == x1(newGrid))
				x[0] = g0(newGrid,0);
			int v1 = x[0];
			#ifdef MPI_VERSION
			MPI::COMM_WORLD.Allreduce(&x[0], &v1, 1, MPI_INT, MPI_MAX);
			#endif

			x[1] += offset;
			while (x[0]>= x0(newGrid) && x[0]<x1(newGrid) && x[1]>=y0(newGrid) && x[1]<y1(newGrid) && newGrid(x).getMagPhi()>edge_contour)
				x[0]++;
			if (x[0] == x1(newGrid))
				x[0] = g0(newGrid,0);
			int v2 = x[0];
			#ifdef MPI_VERSION
			MPI::COMM_WORLD.Allreduce(&x[0], &v2, 1, MPI_INT, MPI_MAX);
			#endif

			// Second-order right-sided difference to approximate slope
			double diffX = 3.0*v0 - 4.0*v1 + 1.0*v2;
			double theta = 180.0/M_PI * std::atan2(2.0*offset*dx(newGrid,1), dx(newGrid,0)*diffX);

			if (rank==0)
				vfile << dx(newGrid,0)*v0 << '\t' << dx(newGrid,0)*v1 << '\t' << dx(newGrid,0)*v2 << '\t' << diffX << '\t' << theta << '\n';
		}

		swap(oldGrid, newGrid);
	} // Loop over steps
	ghostswap(oldGrid);

	if (rank==0)
		vfile.close();
}
Example #26
0
void generate(int dim, char* filename)
{
	int rank=0;
	#ifdef MPI_VERSION
	rank = MPI::COMM_WORLD.Get_rank();
	#endif
	if (rank==0) {
		std::ofstream vfile("v.log",std::ofstream::out);
		vfile.close();
	}


	if (dim == 2)	{
		const int Lx = 768;
		const int Ly = 128;

		grid<2,sparse<phi_type> > initGrid(0, 0,Lx, 0,Ly);

		for (int d=0; d<dim; d++) {
			if (x0(initGrid, d) == g0(initGrid,d))
				b0(initGrid,d) = Dirichlet;
			else if (x1(initGrid,d) == g1(initGrid,d))
				b1(initGrid,d) = Dirichlet;
		}

		for (int n=0; n<nodes(initGrid); n++) {
			vector<int> x = position(initGrid, n);
			if (x[0]>Ly && x[1]>0.25*Ly && x[1]<0.75*Ly)
				set(initGrid(n), 0) = 1.0;
			else if (x[1]<Ly/2)
				set(initGrid(n), 1) = 1.0;
			else
				set(initGrid(n), 2) = 1.0;
		}

		output(initGrid, filename);
	}

	if (dim == 3)	{
		const int Lx = 512;
		const int Ly = 256;
		const int Lz = 64;

		grid<3,sparse<phi_type> > initGrid(0, 0,Lx, 0,Ly, 0,Lz);

		for (int d=0; d<dim; d++) {
			if (x0(initGrid, d) == g0(initGrid,d))
				b0(initGrid,d) = Dirichlet;
			else if (x1(initGrid,d) == g1(initGrid,d))
				b1(initGrid,d) = Dirichlet;
		}

		for (int n=0; n<nodes(initGrid); n++) {
			vector<int> x = position(initGrid, n);
			if (x[0]>Ly && x[1]>0.25*Ly && x[1]<0.75*Ly)
				set(initGrid(n), 0) = 1.0;
			else if (x[1]<Ly/2)
				set(initGrid(n), 1) = 1.0;
			else
				set(initGrid(n), 2) = 1.0;
		}

		output(initGrid, filename);
	}
}
Example #27
0
void
skipjack_forwards(u_int8_t *plain, u_int8_t *cipher, u_int8_t **key_tables)
{
	u_int8_t wh1 = plain[0];  u_int8_t wl1 = plain[1];
	u_int8_t wh2 = plain[2];  u_int8_t wl2 = plain[3];
	u_int8_t wh3 = plain[4];  u_int8_t wl3 = plain[5];
	u_int8_t wh4 = plain[6];  u_int8_t wl4 = plain[7];

	u_int8_t * k0 = key_tables [0];
	u_int8_t * k1 = key_tables [1];
	u_int8_t * k2 = key_tables [2];
	u_int8_t * k3 = key_tables [3];
	u_int8_t * k4 = key_tables [4];
	u_int8_t * k5 = key_tables [5];
	u_int8_t * k6 = key_tables [6];
	u_int8_t * k7 = key_tables [7];
	u_int8_t * k8 = key_tables [8];
	u_int8_t * k9 = key_tables [9];

	/* first 8 rounds */
	g0 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 1; wh4 ^= wh1;
	g4 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 2; wh3 ^= wh4;
	g8 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 3; wh2 ^= wh3;
	g2 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 4; wh1 ^= wh2;
	g6 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 5; wh4 ^= wh1;
	g0 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 6; wh3 ^= wh4;
	g4 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 7; wh2 ^= wh3;
	g8 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 8; wh1 ^= wh2;

	/* second 8 rounds */
	wh2 ^= wh1; wl2 ^= wl1 ^ 9 ; g2 (wh1,wl1, wh1,wl1);
	wh1 ^= wh4; wl1 ^= wl4 ^ 10; g6 (wh4,wl4, wh4,wl4);
	wh4 ^= wh3; wl4 ^= wl3 ^ 11; g0 (wh3,wl3, wh3,wl3);
	wh3 ^= wh2; wl3 ^= wl2 ^ 12; g4 (wh2,wl2, wh2,wl2);
	wh2 ^= wh1; wl2 ^= wl1 ^ 13; g8 (wh1,wl1, wh1,wl1);
	wh1 ^= wh4; wl1 ^= wl4 ^ 14; g2 (wh4,wl4, wh4,wl4);
	wh4 ^= wh3; wl4 ^= wl3 ^ 15; g6 (wh3,wl3, wh3,wl3);
	wh3 ^= wh2; wl3 ^= wl2 ^ 16; g0 (wh2,wl2, wh2,wl2);

	/* third 8 rounds */
	g4 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 17; wh4 ^= wh1;
	g8 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 18; wh3 ^= wh4;
	g2 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 19; wh2 ^= wh3;
	g6 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 20; wh1 ^= wh2;
	g0 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 21; wh4 ^= wh1;
	g4 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 22; wh3 ^= wh4;
	g8 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 23; wh2 ^= wh3;
	g2 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 24; wh1 ^= wh2;

	/* last 8 rounds */
	wh2 ^= wh1; wl2 ^= wl1 ^ 25; g6 (wh1,wl1, wh1,wl1);
	wh1 ^= wh4; wl1 ^= wl4 ^ 26; g0 (wh4,wl4, wh4,wl4);
	wh4 ^= wh3; wl4 ^= wl3 ^ 27; g4 (wh3,wl3, wh3,wl3);
	wh3 ^= wh2; wl3 ^= wl2 ^ 28; g8 (wh2,wl2, wh2,wl2);
	wh2 ^= wh1; wl2 ^= wl1 ^ 29; g2 (wh1,wl1, wh1,wl1);
	wh1 ^= wh4; wl1 ^= wl4 ^ 30; g6 (wh4,wl4, wh4,wl4);
	wh4 ^= wh3; wl4 ^= wl3 ^ 31; g0 (wh3,wl3, wh3,wl3);
	wh3 ^= wh2; wl3 ^= wl2 ^ 32; g4 (wh2,wl2, wh2,wl2);

	/* pack into byte vector */
	cipher [0] = wh1;  cipher [1] = wl1;
	cipher [2] = wh2;  cipher [3] = wl2;
	cipher [4] = wh3;  cipher [5] = wl3;
	cipher [6] = wh4;  cipher [7] = wl4;
}
Example #28
0
#define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
int x;
EVAL_EXPR(1, (_Bool)&x)
EVAL_EXPR(2, (int)(1.0+(double)4))
EVAL_EXPR(3, (int)(1.0+(float)4.0))
EVAL_EXPR(4, (_Bool)(1 ? (void*)&x : 0))
EVAL_EXPR(5, (_Bool)(int[]){0})
struct y {int x,y;};
EVAL_EXPR(6, (int)(1+(struct y*)0))
EVAL_EXPR(7, (int)&((struct y*)0)->y)
EVAL_EXPR(8, (_Bool)"asdf")
EVAL_EXPR(9, !!&x)
EVAL_EXPR(10, ((void)1, 12))
void g0(void);
EVAL_EXPR(11, (g0(), 12)) // expected-error {{must have a constant size}}
EVAL_EXPR(12, 1.0&&2.0)
EVAL_EXPR(13, x || 3.0) // expected-error {{must have a constant size}}

unsigned int l_19 = 1;
EVAL_EXPR(14, (1 ^ l_19) && 1); // expected-error {{fields must have a constant size}}

void f()
{
  int a;
  EVAL_EXPR(15, (_Bool)&a);
}

// FIXME: Turn into EVAL_EXPR test once we have more folding.
_Complex float g16 = (1.0f + 1.0fi);
Example #29
0
int main()
{
    // Test dijkstra

    /*
       LocalTesting test;
       test.Test();
       return 0;
       */

    srand(time(NULL));
    int dimention = 4;

    cout << "Enter HexBoard side length:";
    cin >> dimention;

    if(dimention<2 || dimention>26)
    {
	cout << "\nInvalid dimention, it should be 2<=dimention<=26. Exiting the game" << endl;
	return -1;
    }

    cout << "\nCreating a hexboard of size" << dimention << " X " << dimention << endl;

    HexBoard hex(dimention);
    hex.moveNumber = 0;

    //Create 2 graphs each of size (dimention*dimention)+2
    //those last 2 additional vertices are for virtual nodes
    //Creating 2 separate graphs each for players 0(Blue) and 1(Red)
    int vertices = (dimention*dimention)+2;
    Graph g0(vertices);
    Graph g1(vertices);

    // Now, connect virtual nodes with corresponding nodes
    // For g0, WEST virtual vertex is vertex[vertices-2]
    // EAST virtual vertex is vertex[vertices-1]

    // For g1, NORTH virtual vertex is vertex[vertices-2]
    // SOUTH virual vertex is vertex[vertices-1]

    // Connecting WEST virtual vertex with 1A, 2A, 3A, 4A, ....
    for(int i=0; i<dimention; i++)
    {
	// Undirected graph, so adding it twice
	g0.add_edge((g0.vertices)-2, (i*dimention));
	g0.add_edge((i*dimention), (g0.vertices)-2);

	// Setting edge_values 1 for all.
	g0.set_edge_value((g0.vertices)-2, (i*dimention), 1.0);
	g0.set_edge_value((i*dimention), (g0.vertices)-2, 1.0);
    }

    // Connecting EAST virtual vertex with 1G, 2G, 3G, 4G, ....(if it's a 7x7 board)
    for(int i=0; i<dimention; i++)
    {
	// Undirected graph, so adding it twice
	g0.add_edge((g0.vertices)-1, (i*dimention+(dimention-1)));
	g0.add_edge((i*dimention+(dimention-1)), (g0.vertices)-1);

	// Setting edge_values 1 for all.
	g0.set_edge_value((g0.vertices)-1, (i*dimention+(dimention-1)), 1.0);
	g0.set_edge_value((i*dimention+(dimention-1)), (g0.vertices)-1, 1.0);
    }

    // Connecting NORTH virtual vertex with 1A, 1B, 1C, 1D, ..etc.
    for(int i=0; i<dimention; i++)
    {
	// Undirected graph, so adding it twice
	g1.add_edge((g1.vertices)-2, (i));
	g1.add_edge((i), (g1.vertices)-2);

	// Setting edge_values 1 for all.
	g1.set_edge_value((g1.vertices)-2, (i), 1.0);
	g1.set_edge_value((i), (g1.vertices)-2, 1.0);
    }

    // Connecting SOUTH virtual vertex with 7A, 7B, 7C, 7D, ....(if it's a 7x7 board)
    for(int i=0; i<dimention; i++)
    {
	// Undirected graph, so adding it twice
	g1.add_edge((g1.vertices)-1, (dimention*(dimention-1)+i));
	g1.add_edge((dimention*(dimention-1)+i), (g1.vertices)-1);

	// Setting edge_values 1 for all.
	g1.set_edge_value((g1.vertices)-1, (dimention*(dimention-1)+i), 1.0);
	g1.set_edge_value((dimention*(dimention-1)+i), (g1.vertices)-1, 1.0);
    }

    cout << "Blue player(Player 0) direction is EAST<->WEST. Occupied position is shown with O" << '\n' << endl;
    cout << "Red player(Player 1) direction is NORTH<->SOUTH. Occupied position is shown with X" << '\n' << endl;
    hex.print_board();

    cout << '\n' << "Always enter ROW COLUMN(without space and in capital letters)" << endl;
    cout << "So, row would always be a number and column would be a char" << endl;
    cout << "Example: 5B is correct, but B5 is wrong" << endl;
    cout << '\n' << endl;
    cout << "===================================================================" << endl;
    cout << "Remember that Blue player always starts the game." << '\n' << endl;
    cout << "Game is starting now" << '\n' << endl;
    cout << "===================================================================" << '\n' << endl;
    //cout << "Helper " << Helper::xy_to_linear(string("4D"), 4) << '\n' << endl;
    //cout << "Helper " << Helper::linear_to_xy(15, 4) << '\n' << endl;

    //Main while loop where game is played
    //while nobody won the game
    char ch;
    int isHumanFirst = 1;
    cout << "Human, do you wanna go first? (Y/N) :";
    cin >> ch;
    cout << '\n' << endl;

    if(toupper(ch) == 'Y')
    {
	isHumanFirst = 1;
    }
    else if(toupper(ch) == 'N')
    {
	isHumanFirst = 0;
    }
    else
    {
	cout << "You neither entered Y or N. By default human goes first." << endl;
    }


    while((hex.is_win(0, g0)==false) && (hex.is_win(1, g1)==false))
    {
	string player;
	string color;
	string move;
	pair<int, int> p;

	// Determine which player is playing based on moveNumber.
	// Player 0 if even moveNumber, Player 1 otherwise.
	if(hex.moveNumber%2==0)
	{
	    if(isHumanFirst)
	    {
		player = "Human";
	    }
	    else
	    {
		player = "Computer";
	    }

	    color.assign("Blue");
	}
	else
	{
	    if(isHumanFirst)
	    {
		player = "Computer";
	    }
	    else
	    {
		player = "Human";
	    }

	    color.assign("Red");
	}

	cout << "Player: " << color << "(" << player << ")" << "is playing" << endl;
	cout << "Move number:" << hex.moveNumber << endl;

	if(player == "Human")
	{
	    cout << "Enter move:";
	    cin >> move;
	}
	else
	{
Example #30
0
unsigned long generate(MMSP::grid<dim,MMSP::sparse<float> >*& grid, int seeds, int nthreads)
{
#if (defined CCNI) && (!defined MPI_VERSION)
    std::cerr<<"Error: MPI is required for CCNI."<<std::endl;
    exit(1);
#endif
    int rank=0;
#ifdef MPI_VERSION
    rank = MPI::COMM_WORLD.Get_rank();
    int np = MPI::COMM_WORLD.Get_size();
#endif
    unsigned long timer=0;
    if (dim == 2) {
        const int edge = 1024;
        int number_of_fields(seeds);
        if (number_of_fields==0) number_of_fields = static_cast<int>(float(edge*edge)/(M_PI*10.*10.)); // average grain is a disk of radius 10
#ifdef MPI_VERSION
        while (number_of_fields % np) --number_of_fields;
#endif
        grid = new MMSP::grid<dim,MMSP::sparse<float> >(0, 0, edge, 0, edge);
#ifndef SILENT
        if (rank==0) std::cout<<"Grid origin: ("<<g0(*grid,0)<<','<<g0(*grid,1)<<"),"
                                  <<" dimensions: "<<g1(*grid,0)-g0(*grid,0)<<" × "<<g1(*grid,1)-g0(*grid,1)
                                  <<" with "<<number_of_fields<<" grains."<<std::endl;
#endif
#ifdef MPI_VERSION
        number_of_fields /= np;
#endif

#if (!defined MPI_VERSION) && ((defined CCNI) || (defined BGQ))
        std::cerr<<"Error: CCNI requires MPI."<<std::endl;
        std::exit(1);
#endif
        timer = tessellate<dim,float>(*grid, number_of_fields, nthreads);
#ifndef SILENT
        if (rank==0) std::cout<<"Tessellation complete."<<std::endl;
#endif
#ifdef MPI_VERSION
        MPI::COMM_WORLD.Barrier();
#endif
    } else if (dim == 3) {
        const int edge = 64;
        int number_of_fields(seeds);
        if (number_of_fields==0) number_of_fields = static_cast<int>(float(edge*edge*edge)/(4./3*M_PI*10.*10.*10.)); // Average grain is a sphere of radius 10 voxels
#ifdef MPI_VERSION
        while (number_of_fields % np) --number_of_fields;
#endif
        grid = new MMSP::grid<dim,MMSP::sparse<float> >(0,0,edge,0,edge,0,edge);
#ifndef SILENT
        if (rank==0) std::cout<<"Grid origin: ("<<g0(*grid,0)<<','<<g0(*grid,1)<<','<<g0(*grid,2)<<"),"
                                  <<" dimensions: "<<g1(*grid,0)-g0(*grid,0)<<" × "<<g1(*grid,1)-g0(*grid,1)<<" × "<<g1(*grid,2)-g0(*grid,2)
                                  <<" with "<<number_of_fields<<" grains."<<std::endl;
#endif
#ifdef MPI_VERSION
        number_of_fields /= np;
#endif

#if (!defined MPI_VERSION) && ((defined CCNI) || (defined BGQ))
        std::cerr<<"Error: CCNI requires MPI."<<std::endl;
        std::exit(1);
#endif
        timer = tessellate<dim,float>(*grid, number_of_fields, nthreads);
#ifdef MPI_VERSION
        MPI::COMM_WORLD.Barrier();
#endif
#ifndef SILENT
        if (rank==0) std::cout<<"Tessellation complete."<<std::endl;
#endif
    }
    return timer;
}