void CDataManager::LevelShutdownPostEntity()
{
	if (!gpGlobals->maxClients)
		return;

	// If the thread is executing, then wait for it to finish
	if ( m_pSendData )
		m_pSendData->WaitForFinishAndRelease();

	m_pSendData = ThreadExecute( &SendData, (CFunctor**)NULL, 0 );
}
Esempio n. 2
0
int main(int argc, char** argv)
{
	FILE* f;
	int i, j;
    size_t size;
	int seedNumber;
	int REPORT = 0;
	int bytesToAllocateForArgsText = 0;

	puts("\r\n");
	puts(argv[0]);
	puts("\r\n");
	if(argc == 1)
	{
		PrintUsage(0);
	}

	// gather N, T, W, maxFullsteps, winPercent, seedNumber, INTERACTIVE from commandline args; 
	N = T = W = winPercent = INTERACTIVE = 0;
	maxFullsteps = -1;
	seedNumber = time(NULL);
	for(i = 1; i < argc; i++)
	{
		bytesToAllocateForArgsText += strlen(argv[i]) + 1;
		switch(argv[i][0])
		{
			case 'p':
				if(strlen(argv[i]) >= 2)
				{
					W = atoi(&(argv[i][1]));
				}
				else
				{
					printf("Invalid process count.\r\n");
					PrintUsage(1);
				}
				break;
			case 'b':
				if(strlen(argv[i]) >= 2)
				{
					N = atoi(&(argv[i][1]));
				}
				else
				{
					printf("Invalid size parameter for board.\r\n");
					PrintUsage(1);
				}
				break;
			case 't':
				if(strlen(argv[i]) >= 2)
				{
					T = atoi(&(argv[i][1]));
				}
				else
				{
					printf("Invalid size parameter for overlay.\r\n");
					PrintUsage(1);
				}
				break;
			case 'c':
				if(strlen(argv[i]) >= 2)
				{
					winPercent = atoi(&(argv[i][1]));
				}
				else
				{
					printf("Invalid win percentage.\r\n");
					PrintUsage(1);
				}
				break;
			case 'm':
				if(strlen(argv[i]) >= 2)
				{
					j = sscanf(&(argv[i][1]), "%d", &maxFullsteps);
					if(!j)
					{
						printf("Invalid max steps.\r\n");
						PrintUsage(1);
					}
				}
				else
				{
					printf("Invalid max steps.\r\n");
					PrintUsage(1);
				}
				break;
			case 's':
				if(strlen(argv[i]) >= 2)
				{
					j = sscanf(&(argv[i][1]), "%d", &seedNumber);
					if(!j)
					{
						printf("Invalid seed.\r\n");
						PrintUsage(1);
					}
				}
				else
				{
					PrintUsage(1);
				}
				break;
#ifndef DISABLE_INTERACTIVE
			case 'i':
				if(strlen(argv[i]) != 1)
				{
					printf("Invalid parameter %s.\r\n", argv[i]);
					PrintUsage(1);
				}
				INTERACTIVE = 1;
				break;
#endif
			case 'R':
				REPORT = 1;
				break;
			default:
				printf("Invalid parameter %s.\r\n", argv[i]);
				PrintUsage(1);
				break;
		}
	}

	argsText = malloc(bytesToAllocateForArgsText + 1);
	argsText[0] = 0;
	for(i = 1; i < argc; i++)
	{
		strcat(argsText, argv[i]);
		strcat(argsText, " ");
	}
	printf("Argument text: '%s' \r\n", argsText);

	srand(seedNumber);

	if(W <= 0)
	{
		printf("Invalid or nonexistant process count, must be greater than zero.\r\n");
		PrintUsage(1);
	}
	if(N < 2)
	{
		printf("Invalid or nonexistant size parameter for board, must be greater than or equal or 2.\r\n");
		PrintUsage(1);
	}
	if(T <= 0 || N % T != 0)
	{
		printf("Invalid or nonexistant size parameter for overlay.\r\n");
		PrintUsage(1);
	}
	if(winPercent <= 0)
	{
		printf("Invalid or nonexistant termination condition percent, must be (1-100).\r\n");
		PrintUsage(1);
	}
	if(maxFullsteps < 0)
	{
		printf("Invalid or nonexistant number of max full steps, must be greater than or equal to zero.\r\n");
		PrintUsage(1);
	}

	board = malloc(N * N);
	if(!board)
	{
		perror("Not enough memory.\r\n");
		SHUTDOWN(-1);
	}
	for(i = 0; i < N * N; i++)
	{
		board[i] = rand() % 3;
	}

	// Set up the miscellaneous. 
	maxHalfsteps = maxFullsteps * 2;
	percentHalfsteps = -1; 
	maxBluePercent = maxRedPercent = 0;

	omp_set_num_threads(W);

	StartTime();
	#pragma omp parallel
	{ 
		if(omp_get_thread_num() == 0)
		{
			W  = omp_get_num_threads();
			printf("W = %d\r\n", W);
			// If N is greater than or equal to the number of workers, there is work for every thread. 
			if(N >= W) 
			{ 
				// If workers divide N, then every worker does the same amount of work. 
				if(N % W == 0) 
				{ 
					rcLeftOver = rcSplit = N / W; 
				} 
				// If workers do not divide N, 
				// Then the truncation of N / W is handed to W - 1 of W workers, 
				// And the final worker will take all the remaining work. 
				else 
				{ 
					rcSplit = N / W; 
					rcLeftOver = N - (rcSplit * (W - 1)); 
				} 
			} 
			else 
			{ 
				// Each worker up to N takes 1 row. 
				// Leftover is set here, but won't actually used. 
				rcSplit = 1; 
				rcLeftOver = 1; 
			 
				// Set the number of workers equal to the size of the board, 
				// so that we don't spawn threads that will always be doing nothing. 
				W = N; 
			}
			// Calculate how many times T divides N in advance. 
			// This will be used a lot in the board evaluation phase. 
			subregionCount = N / T; 
			// Size of each subregion in cells. 
			subregionCells = T * T;
		}
		
		#pragma omp barrier
		printf("%d got here\r\n", omp_get_thread_num());
		
		ThreadExecute(omp_get_thread_num());
	}

	if(INTERACTIVE)
	{
		if(!interactiveExit)
		{
			PrintBoard(percentHalfsteps);
		}
	}
	else
	{
		f = fopen("redblue.txt", "w");
		PrintBoardToFile(percentHalfsteps, f);
		fclose(f);
	}

	free(argsText);
	free(board);

	SHUTDOWN(0);
	return 0;
}