Ejemplo n.º 1
0
void Distribution2D::distribute(const size_t& size_x, const size_t& size_y, const size_t& num_of_nodes_by_x, const size_t& num_of_nodes_by_y) {
	std::vector<Region> regions_by_x, regions_by_y;

	computeRegions(size_x, num_of_nodes_by_x, regions_by_x);
	computeRegions(size_y, num_of_nodes_by_y, regions_by_y);		
		
	for ( size_t node_y = 0; node_y < num_of_nodes_by_y; node_y++) {
		for ( size_t node_x = 0; node_x < num_of_nodes_by_x; node_x++) {						
			const Region& rx = regions_by_x[node_x];
			const Region& ry = regions_by_y[node_y];
			this->set(node_y*num_of_nodes_by_x + node_x, 
				Region2D(rx.getStart(), ry.getStart(), rx.getEnd(), ry.getEnd()));
		}
	}
}
void run_test(const Opm::parameter::ParameterGroup& param)
{
    int N=100;
    int start, end, istart, iend;
    std::tie(start,istart,iend,end) = computeRegions(N);
    Opm::ParallelISTLInformation comm(MPI_COMM_WORLD);
    auto mat = create1DLaplacian(*comm.indexSet(), N, start, end, istart, iend);
    std::vector<double> x(end-start), b(end-start);
    createRandomVectors(comm, end-start, x, b, *mat);
    std::vector<double> exact(x);
    std::fill(x.begin(), x.end(), 0.0);
    Opm::LinearSolverFactory ls(param);
    boost::any anyComm(comm);
    ls.solve(b.size(), mat->data.size(), &(mat->rowStart[0]),
             &(mat->colIndex[0]), &(mat->data[0]), &(b[0]),
             &(x[0]), anyComm);
}
void runSumMaxMinTest(const int offset)
{
    const int N=100;
    int start, end, istart, iend;
    std::tie(start,istart,iend,end) = computeRegions(N);
    Opm::ParallelISTLInformation comm(MPI_COMM_WORLD);
    auto mat = create1DLaplacian(*comm.indexSet(), N, start, end, istart, iend);
    std::vector<int> x(end-start);
    assert(comm.indexSet()->size()==x.size());
    for(auto i=comm.indexSet()->begin(), iend=comm.indexSet()->end(); i!=iend; ++i)
        x[i->local()]=i->global()+offset;
    auto containers = std::make_tuple(x, x, x);
    auto operators  = std::make_tuple(Opm::Reduction::makeGlobalSumFunctor<int>(),
                                      Opm::Reduction::makeGlobalMaxFunctor<int>(),
                                      Opm::Reduction::makeGlobalMinFunctor<int>());
    auto values     = std::make_tuple(0,0,100000);
    auto oldvalues  = values;
    comm.computeReduction(containers,operators,values);
    BOOST_CHECK(std::get<0>(values)==std::get<0>(oldvalues)+((N-1+2*offset)*N)/2);
    BOOST_CHECK(std::get<1>(values)==std::max(N+offset-1, std::get<1>(oldvalues)));
    BOOST_CHECK(std::get<2>(values)==std::min(offset, std::get<2>(oldvalues)));
}
Ejemplo n.º 4
0
void simulationGrid::draw() {	

	int i, j, k, tmpAgents;
	
	/* Graphic Reinitialization */
	if (!valid())
	{
		init();		
		resized = true;
	}
	
	/* If Restart Button is pressed */
	if(restartB)
	{
		tmpAgents = gui_linear_lattice_dimension*gui_linear_lattice_dimension;
     		m.init(gui_linear_lattice_dimension, tmpAgents, NFEATURES, gui_pos_traits, OUTDEGREE, gui_delta, m.maxSide, w(), h());         
		restartB = false;
		simStepLabel->value(0);
		restart = false;
		restartS = true;
	}	
	/* Catch parameters from gui and reinit if needed */
	else if((m.delta != gui_delta) || (m.pos_traits != gui_pos_traits ) || (m.linear_lattice_dimension != gui_linear_lattice_dimension) || restart)
	{
		tmpAgents = gui_linear_lattice_dimension*gui_linear_lattice_dimension;
		if(latticeOn)
		{
     			m.init(gui_linear_lattice_dimension, tmpAgents, NFEATURES, gui_pos_traits, OUTDEGREE, gui_delta, 1,w(), h());
			restartS = true;
		}
		else if(kleinbergOn)
		{
			m.init(gui_linear_lattice_dimension, tmpAgents, NFEATURES, gui_pos_traits, OUTDEGREE, gui_delta, 0, w(), h());
			restartS = true;
		}
		else
		{
			m.init(gui_linear_lattice_dimension, tmpAgents, NFEATURES, gui_pos_traits, OUTDEGREE, gui_delta, -1, w(), h());
			restartS = true;
		}         
		restart = false;
	}
	
	/* Clear display */
	glClear(GL_COLOR_BUFFER_BIT);
	if(linkVisualization)
	{	
		for (i=0;i<m.agents;i++)
		{
			link(i);
		}
	}

	/* Draws all Agents */
	for(i=0; i<m.agents;i++)
	{
		drawAgents(i,MIN(w(),h()));
	}

	/* Simulation Step */
	m.step();

	/* Compute Regions */
	computeRegions();

	g1->redraw();
	g2->redraw();
	g3->redraw();
}