Exemplo n.º 1
0
int main(void) {
	srand(time(NULL));

	createQueues();

	setupThreads();

	createThreads(cpuThread, cpuThreads, NUMBER_OF_CPU_THREADS);
	createThreads(ioThread, ioThreads, NUMBER_OF_IO_THREADS);
	createThreads(submissionThread, submissionThreads, NUMBER_OF_SUBMISSION_THREADS);

	waitForThreads(cpuThreads);
	waitForThreads(ioThreads);
	waitForThreads(submissionThreads);

	printf("All threads complete.\n");

	return EXIT_SUCCESS;
}
Exemplo n.º 2
0
void Board_start()
{
	int experimentEndTime;
	int updateFlag;
	int quitFlag;
	Board b;
	BoardThreadParams threadParams[MAX_N_ROBOTS];
	BoardDatabase *db;

#ifdef IS_WIN
	CvSize szGlobal = {ENVIR_DIMS, ENVIR_DIMS};
	CvSize szLocal = {LOC_MAP_DIMS, LOC_MAP_DIMS};
	IplImage *globMapIplImage;
	IplImage *localMapIplImage;
#endif

	setupExperimentDir();

	// Do this before setting up the database
	SET_N_ROBOTS(1)
#ifdef SETUP_TEST_COALITION
	SET_N_ROBOTS(2)
	SET_N_ROBOTS_THREADS_FOR_TEST_COAL(1)
#endif

#ifdef IS_WIN
	globMapIplImage = cvCreateImage (szGlobal, 8, 1);
	localMapIplImage = cvCreateImage (szLocal, 8, 1);
	b = initBoard (globMapIplImage, localMapIplImage);
#else
	b = initBoard();
#endif
	db = &b.db;

#ifdef SETUP_TEST_COALITION
	Board_setupTestCoalRobots (&b.db);
#endif

#ifdef SHOW_IMGS
	Visualisation_showSim (db);
	Visualisation_showMap (db);
//	printf ("Adjust windows and click to start\n"); cvWaitKey (0);
#endif

	if (-1 == setupSockets (db, threadParams))
	{
		goto cleanupBoard;
	}

	experimentEndTime = clock() + 10000;
	printf ("Experiment ends at %d.\n", experimentEndTime);

	if (-1 == setupThreads (db, threadParams))
	{
		goto cleanupBoard;
	}

	printf ("All threads started. Entering blackboard server loop.\n");

	quitFlag = 0;
	while (!quitFlag)
	{
		enterBoardData();
		checkTime (db, experimentEndTime, &updateFlag);
		if (updateFlag)
		{
			Board_processData (&b, 1);

			//! \todo Allocate coalitions

			quitFlag = checkIfAllFinished (db);
		}
		leaveBoardData();

		if (!updateFlag)
		{
			SLEEP_FOR_MS(10)
		}
	}

	printf ("Finished loop. Closing sockets.\n");

	closeSockets (db);

	Board_finish (&b);

cleanupBoard:
	clearBoard (&b);
#ifdef IS_WIN
	cvReleaseImage (&globMapIplImage);
	cvReleaseImage (&localMapIplImage);
	cvCleanup();
#endif
}
Exemplo n.º 3
0
 ParallelAsciifier(boost::shared_ptr<const GlyphMatcherT> c, unsigned thr_cnt)
     :matcher_(c)
 {
     setupThreads(thr_cnt);
 }