/* ========== MAIN ========== */
int main(int argc, char* argv[]) {
	/* Print out starting time */
	double start = when();
	printf("Starting time: %f\n", start);
	/* Create plate */
	float* plate = createPlate();
	float* prev_plate = createPlate();
	char* lockedCells = createCharPlate();// bool array of locked cells
	/* Init main plate and make a duplicate copy */
	initPlate(plate, lockedCells);
	copy(plate, prev_plate);
	/* Start updating */
	printf("Updating plate to steady state\n");
	char flag = '1';
	int iterations = 0;
	do {
		iterations++;
		switch(flag) {
		case '1':
			update_plate(plate, prev_plate, lockedCells);
			flag = '0';
			break;
		case '0':
			update_plate(prev_plate, plate, lockedCells);
			flag = '1';
			break;
		}
	} while(steady(((flag == '0') ? plate : prev_plate), lockedCells));


	double end = when();
	printf("\nEnding time: %f\n", end);
	printf("Total execution time: %f\n", end - start);
	printf("Number of iterations: %d\n\n", iterations);
	/* Copy final array to main one and write it to the file */
	if (flag == '1') 
		copy(prev_plate, plate);
	/* write to file */
	printf("Writing to file\n");
	FILE* ofp = fopen(argv[1], "w+");
	int i, j;
	for (i = 0; i < ROWS; i++) {
		for (j = 0; j < COLS; j++) {
			fprintf(ofp, "%f," ,plate[i + j * COLS]);
		}
		fprintf(ofp, "\n");
	}
	fclose(ofp);

	/* free memory */
	printf("Cleanup\n");
	cleanupFloat(plate);
	cleanupFloat(prev_plate);
	cleanupChar(lockedCells);

	return EXIT_SUCCESS;
}
Example #2
0
int main(int argc , char** argv){
	x = atoi(argv[1]);
	y = atoi(argv[2]);
	dx = WIDTH / (x - 1);
	dy = HEIGHT / (y - 1);
	int countNodes = x * y , currentProc;

	voltage = new double*[countNodes + 1];
	for(int i = 0 ; i < countNodes + 1 ; i++)
		voltage[i] = new double[1];
	plate = createPlate(x , y , voltage);
	argThread* args = new argThread();

	struct timeval begin;
	struct timeval end;
	struct timezone zone;

	gettimeofday(&begin, &zone);

	MPI_Init (&argc, &argv);
  	MPI_Comm_size (MPI_COMM_WORLD, &countThreads);
	MPI_Comm_rank (MPI_COMM_WORLD, &currentProc);

	MPI_Barrier(MPI_COMM_WORLD);

	int** intervals = createBlockOrder(&plate -> getOrder()[1] , y ,  x , countThreads);

	if(countThreads > 1){
		Plate* plates;
		if(currentProc == 0)
			plates = new Plate(&plate -> getNodes()[intervals[0][0]] ,  intervals[1][1] - intervals[0][0]);
		else if(currentProc == countThreads - 1)
			plates = new Plate(&plate -> getNodes()[intervals[2 * currentProc - 1][0]] ,  intervals[2 * currentProc][1] - intervals[2 * currentProc - 1][0]);
		else
			plates = new Plate(&plate -> getNodes()[intervals[2 * currentProc - 1][0]] , intervals[2 * currentProc + 1][1] - intervals[2 * currentProc - 1][0]);

		args -> init(currentProc , plates , intervals[2 * currentProc][1] - intervals[2 * currentProc][0]);
	}
	else
		args -> init(0 , plate , intervals[0][1] - intervals[0][0]);


	MPI_Barrier(MPI_COMM_WORLD);


	action((void*)(args));

	gettimeofday(&end, &zone);
	fprintf(stderr , "Time executing :: %lu on number of process %d\n" , end.tv_sec * 1000000 + end.tv_usec - begin.tv_usec - begin.tv_sec * 1000000 , countThreads);
		

	createScript(x , y , MaxToGnuPlot);

	MPI_Finalize();
	delete args;
	delete plate;
	delete voltage;
	delete test;
    return 0;
}
/* ========== MAIN ========== */
int main(int argc, char* argv[]) {
	/* Print out starting time */
	double start = when();
	printf("Starting time: %f\n", start);

	/* Create thread count */
	int nthreads = atoi(argv[1]);

	/* Create plate */
	main_plate = createPlate();
	main_prev_plate = createPlate();
	main_locked_cells = createCharPlate(); // bool array of locked cells

	/* Init barriers and mutex */
	pthread_mutex_init(&finished_count, NULL);
	barr = (barrier_node*)malloc(sizeof(barrier_node));
	mylib_init_barrier(barr, nthreads);

	/* Init main plate and make a duplicate copy */
	initPlate(main_plate, main_prev_plate);

	/* Start updating */
	startUpdate(nthreads);//, barr);

	/* Report time and cleanup */
	double end = when();
	printf("\nEnding time: %f\n", end);
	printf("Total execution time: %f\n", end - start);
	printf("Number of iterations: %d\n\n", iterations);

	/* Destroy mutex and barriers */
	pthread_mutex_destroy(&finished_count);
	mylib_destroy_barrier(barr);

	/* free memory */
	printf("Cleanup\n");
	free(barr);
	cleanupFloat(main_plate);
	cleanupFloat(main_prev_plate);
	cleanupChar(main_locked_cells);

	return EXIT_SUCCESS;
}
PlateModel* PlateModelFactory::createPlateModel(DataSource *dataSource)
{
    int numberOfEntries = dataSource->getNumberOfEntries();
    Plate *plate;
    PlateModel *plateModel = new PlateModel();

    for (int i = 0; i < numberOfEntries; i++) {
        plate = createPlate(i);
        plateModel->addPlate(*plate);
    }

    return plateModel;
}
Example #5
0
bool SceneGame::init()
{
  
	if (!Layer::init())
	{
		return false;
	}

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	_c = new std::vector<Chess*>();
	_c->resize(1000);
	_steps = new std::vector<Step*>();
	_steps->reserve(1000);


	createPlate();

	Chess::_d = Director::getInstance()->getWinSize().height / 10;
	Chess::_offx = Chess::_d;
	Chess::_offy = Chess::_d / 2;

	for (int i = 0; i < 32; i++)
	{
		_c->at(i) = Chess::create();
		_c->at(i)->initChess(i);
		addChild(_c->at(i));
	}


	EventDispatcher *eventDispatcher = Director::getInstance()->getEventDispatcher();
	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = CC_CALLBACK_2(SceneGame::onTouchBegan, this);
	listener->onTouchEnded = CC_CALLBACK_2(SceneGame::onTouchEnd, this);
	eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

	_selectid = 1;
	_selectSprite = Sprite::create("selected.png");
	_selectSprite->setVisible(false);
	addChild(_selectSprite);
	_selectSprite->setScale(0.6f);
	_selectSprite->setZOrder(100);

	_bRedTurn = true;

	_steps->clear();
	addCtrlPanel();

	return true;
}
Example #6
0
Figure* Texture::makePlate() {
	// キャッシュにFigureが存在しないか検索
	Figure *figure = cache->searchFigure(MAX_FIGURE_ID, MAX_FIGURE_SUB_ID, 0, 0);
	if (figure) {
		return figure;
	}
	
	Rectf rect;
	rect.top = 0;
	rect.left = 0;
	rect.right = 1;
	rect.bottom = 1;
	float w = (rect.right - rect.left) * this->width / dispW;
	float p = (rect.bottom - rect.top) / (rect.right - rect.left);
	figure = createPlate(w, w*p);
	figure->build();
	
	// キャッシュに登録
	cache->putFigure(MAX_FIGURE_ID, MAX_FIGURE_SUB_ID, 0, 0, figure);

	return figure;
}
Example #7
0
int main(int argc, char *argv[])
{
	setbuf(stdout, 0);
	float **plate, **prev_plate, **temp_plate, **locked_cells;
    int start, end, rows_assinged;

    MPI_Init(&argc, &argv);

	char host[255];
	gethostname(host,253);

    int nproc, iproc;
    MPI_Status status;
	MPI_Request request;

    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
    MPI_Comm_rank(MPI_COMM_WORLD, &iproc);
	
	printf("I am process rank %d of %d running on %s\n", iproc, nproc,host);
    
    /* Determine how much I should be doing and allocate the arrays*/
    rows_assinged = SIZE / nproc; // rows for a specific processor to look at
	plate = createPlate(rows_assinged);
	prev_plate = createPlate(rows_assinged);
	locked_cells = createPlate(rows_assinged);

    start = 1;
    end = rows_assinged + 1;

    /* Initialize the cells */
	initPlate(plate, prev_plate, locked_cells, rows_assinged, iproc);

	if (iproc == 0) {
		start = 2;
	}
	if (iproc == (nproc - 1)) {
		end = rows_assinged;
	}

	/* First we need to get the 0th row of locked cells from my previous neighbor */
	if (iproc != 0) {
		MPI_Isend(locked_cells[1], SIZE, MPI_FLOAT, iproc - 1, 0, MPI_COMM_WORLD, &request);
		MPI_Recv(locked_cells[0], SIZE, MPI_FLOAT, iproc - 1, 0, MPI_COMM_WORLD, &status);
	}
	if (iproc != (nproc - 1)) {
		MPI_Isend(locked_cells[rows_assinged], SIZE, MPI_FLOAT, iproc + 1, 0, MPI_COMM_WORLD, &request);
		MPI_Recv(locked_cells[rows_assinged + 1], SIZE, MPI_FLOAT, iproc + 1, 0, MPI_COMM_WORLD, &status);
	}

    /* Now run the relaxation */
    double starttime = When();

    int done = 0, reallydone = 0, iterations = 0;
    while(!reallydone)
    {
		iterations++;
        /* First, I must get my neighbors boundary values */
        if (iproc != 0) 
        {
			/* If I'm not the first processor I want to send/receive to my previous neighbour */
            MPI_Isend(prev_plate[1], SIZE, MPI_FLOAT, iproc - 1, 0, MPI_COMM_WORLD, &request);
            MPI_Recv(prev_plate[0], SIZE, MPI_FLOAT, iproc - 1, 0, MPI_COMM_WORLD, &status);
        }
        if (iproc != nproc - 1) 
        {
			/* If I'm not the last processor I want to send/receice from my next neighbor */
            MPI_Isend(prev_plate[rows_assinged], SIZE, MPI_FLOAT, iproc + 1, 0, MPI_COMM_WORLD, &request);
            MPI_Recv(prev_plate[rows_assinged + 1], SIZE, MPI_FLOAT, iproc + 1, 0, MPI_COMM_WORLD, &status);
        }
        /* Do the calculations */
		update_plate(iproc, plate, prev_plate, locked_cells, rows_assinged, start, end);
        /* Check to see if we are done */
		done = steady(iproc, plate, locked_cells, rows_assinged, start, end);
        /* Do a reduce and distribute it to all processors */
        MPI_Allreduce(&done, &reallydone, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);

        /* Swap the pointers */
        temp_plate = plate;
        plate = prev_plate;
        prev_plate = temp_plate;
    }
	
    /* print out the number of iterations to relax */
    printf("%d :It took %d iterations and %lf seconds to relax the system\n", 
                                   iproc, iterations, When() - starttime);

	/* Deallocate everything */
//	cleanup(plate, rows_assinged, iproc, nproc);
//	cleanup(prev_plate, rows_assinged, iproc, nproc);
//	cleanup(locked_cells, rows_assinged, iproc, nproc);

    MPI_Finalize();
	return EXIT_SUCCESS;
}