Ejemplo n.º 1
0
void runSerial(int expectedNumEntries, int numOperations, float insertOperationsPercent) {

    StdMapType map(expectedNumEntries);

    auto find = [&map](const Key& key) {
        map.find(key);
    };

    auto insert = [&map](const Key& key) {
        if (map.find(key) == map.end()) {
            Value value = calculate(key);
            map.insert(std::make_pair(key, value));
        }
    };

    runThreads(1, threadFunction, numOperations, insertOperationsPercent, find, insert);

}
Ejemplo n.º 2
0
void runFcmm(int expectedNumEntries, int numThreads, int numOperationsPerThread, double insertOperationsPercent, bool verbose = false) {

    FcmmType map(expectedNumEntries);

    auto find = [&map](const Key& key) {
        map.find(key);
    };

    auto insert = [&map](const Key& key) {
        map.insert(key, calculate);
    };

    runThreads(numThreads, threadFunction, numOperationsPerThread, insertOperationsPercent, find, insert);

    if (verbose) {
        printStats(map);
    }

}
Ejemplo n.º 3
0
void runTbb(int expectedNumEntries, int numThreads, int numOperationsPerThread, double insertOperationsPercent) {

    TbbConcurrentMapType map(expectedNumEntries);

    auto find = [&map](const Key& key) {
        TbbConcurrentMapType::const_accessor accessor;
        map.find(accessor, key);
    };

    auto insert = [&map](const Key& key) {
        TbbConcurrentMapType::accessor accessor;
        if (map.insert(accessor, key)) {
            accessor->second = calculate(key);
        }
    };

    runThreads(numThreads, threadFunction, numOperationsPerThread, insertOperationsPercent, find, insert);

}
int main( int argc, const char* argv[])
{
	int argi = 1;
	int nofThreads = -1;
	for (; argi < argc && argv[argi][0] == '-'; ++argi)
	{
		if (0==std::strcmp( argv[argi], "--"))
		{
			++argi;
			break;
		}
		else if (0==std::strcmp( argv[argi], "-h") || 0==std::strcmp( argv[argi], "--help"))
		{
			std::cerr << "Usage: testRequestTransactionMap [-h,-V] <nofIterations>" << std::endl;
			return 0;
		}
		else if (0==std::strcmp( argv[argi], "-t") || 0==std::strcmp( argv[argi], "--threads"))
		{
			const char* optarg_ = argv[++argi];
			nofThreads = optarg_ ? atoi( optarg_) : -1;
			if (nofThreads <= 0)
			{
				std::cerr << "argument of option --threads|-t has to be a positive integer: " << (optarg_?optarg_:"NULL") << std::endl;
				return -1;
			}
		}
		else if (0==std::strcmp( argv[argi], "-V") || 0==std::strcmp( argv[argi], "--verbose"))
		{
			g_verbose = true;
		}
		else
		{
			std::cerr << "unknown option " << argv[argi] << " (only --help|-h or --verbose|-V known)" << std::endl;
			return -1;
		}
	}
	int nofIterations = (argc == argi) ? 100 : atoi( argv[argi++]);
	if (nofThreads <= 0)
	{
		nofThreads = strus::platform::cores();
		if (nofThreads <= 0)
		{
			std::cerr << "failed to determine numer of cores, default to 2" << std::endl;
			nofThreads = 2;
		}
		else
		{
			std::cerr << "found " << nofThreads << " cores" << std::endl;
		}
	}
	else
	{
		std::cerr << "number of threads " << nofThreads << " specified as program option." << std::endl;
	}
	if (nofIterations <= 0 || argi < argc)
	{
		std::cerr << "Usage: testRequestTransactionMap [-h,-V,-t <threads>] <nofIterations>" << std::endl;
		return 1;
	}
	try
	{
		g_timecnt_start = g_random.get( 1, std::numeric_limits<int>::max());
		g_timecnt.set( g_timecnt_start);

		enum {MaxTransactionTimeout=60, MinNofTransactionPerSecond=10};
		g_tpool.reset( new strus::TransactionPool( g_timecnt.value(), MaxTransactionTimeout, nofIterations*2*nofThreads + MinNofTransactionPerSecond, NULL/*logger interface*/));
		strus::thread timerThread( &runTimerThread);

		runThreads( nofThreads, nofIterations);
		timerThread.join();
		if (g_errorCounter.value() == 0)
		{
			std::cerr << "OK" << std::endl;
			return 0;
		}
		else
		{
			std::cerr << "ERR " << g_errorCounter.value() << " errors" << std::endl;
			return -1;
		}
	}
	catch (const std::exception& err)
	{
		std::cerr << "ERROR " << err.what() << std::endl;
		return -1;
	}
}
Ejemplo n.º 5
0
int main(int argc, char** argv){
	parseArgs(argc, argv);
	runThreads();
	exit(EXIT_SUCCESS);
}
Ejemplo n.º 6
0
TEST(LockedRobotState, set1mod3)
{
  runThreads(1, 1, 3);
}
Ejemplo n.º 7
0
TEST(LockedRobotState, set3mod3c3)
{
  runThreads(3, 3, 3);
}
Ejemplo n.º 8
0
TEST(LockedRobotState, set1mod2)
{
  runThreads(1, 1, 2);
}
Ejemplo n.º 9
0
TEST(LockedRobotState, set3mod1)
{
  runThreads(1, 3, 1);
}
Ejemplo n.º 10
0
TEST(LockedRobotState, set1mod1)
{
  runThreads(1, 1, 1);
}
Ejemplo n.º 11
0
TEST(LockedRobotState, set2mod1)
{
  runThreads(1, 2, 1);
}
Ejemplo n.º 12
0
TEST(LockedRobotState, mod3)
{
  runThreads(1, 0, 1);
}
Ejemplo n.º 13
0
TEST(LockedRobotState, set3)
{
  runThreads(1, 3, 0);
}
Ejemplo n.º 14
0
TEST(LockedRobotState, set2)
{
  runThreads(1, 2, 0);
}
Ejemplo n.º 15
0
TEST(LockedRobotState, set1)
{
  runThreads(1, 1, 0);
}
Ejemplo n.º 16
0
int main(int argc, char **argv)
{	
	clock_t tic = clock();
	FILE *fp; 
	int i, choice, err;
	long numBytes;
	long Inpt= 0;
	int rem = 0;
	pid_t pid[NUM_THR_PROC];
	struct primeArr *primeArray;
	int object_size = 1024 * 1024 * 600;
	sigset_t blockMask, origMask;
    struct sigaction saIgnore, saOrigQuit, saOrigInt, saDefault;
	
	printf("Please enter the max integer to search through for primes: ---->    ");
	scanf("%ld",&Inpt);
//	derp(Inpt);



//	Used this function to initially get my numbers into a BITMAP
//	primeArray = crinit_primeArr(Inpt);
//	IgnorePts(primeArray);
//	p_primeArr(primeArray);						//<<<-------------------------
//	mapPrimes(primeArray->num, Inpt);
//	freeArr(primeArray);

	
	//The number of bytes we want to pull in 
	
	numBytes = Inpt / 4; 							//4 numbers are kept per char.
//	printf("ERROR\n");
	if (Inpt % 4 > 0) { numBytes++;}
//	printf("ERROR\n");
	unsigned char *myPrimes = malloc(sizeof(unsigned char*) * numBytes);
	//char myPrimes[numBytes];						//So we get an array of that many chars(x4 numbers)
//	printf("ERRORhelp\n");
	
	//We open our bitmap(hashed in chars) and set it in the global list array
	fp = fopen("bitMap", "r");
	fread(List, sizeof(myPrimes[0]), numBytes, fp );
	//printf("ERROR\n");	
	Inpt = numBytes / NUM_THR_PROC;
	rem = numBytes % NUM_THR_PROC;

	printf("Would you like to run threads or system? 1 for threads, 2 for system, anything else to quit");
	scanf("%d",&choice); 
	
	//SIGNAL DEALING
	
	sigemptyset(&blockMask);            /* Block SIGCHLD */
    sigaddset(&blockMask, SIGCHLD);
    sigprocmask(SIG_BLOCK, &blockMask, &origMask);

    saIgnore.sa_handler = SIG_IGN;      /* Ignore SIGINT and SIGQUIT */
    saIgnore.sa_flags = 0;
    sigemptyset(&saIgnore.sa_mask);
    sigaction(SIGINT, &saIgnore, &saOrigInt);
    sigaction(SIGQUIT, &saIgnore, &saOrigQuit);
	if(choice == 1)
		runThreads(numBytes, Inpt, rem);
		
	if(choice == 2)
	{
		void *myAddr = mount_shmem("/shProc", object_size);
		myAddr = List;
		
		for(i = 0; i < NUM_THR_PROC; i++)
		{
			for(i=0; i<NUM_THR_PROC; ++i)
			{
				d[i].Depth = numBytes;
				int j = 0;
				int k = 0;
				d[i].offset = i;
				d[i].sliceSt = (Inpt * i);										
				d[i].sliceEnd = Inpt * (i + 1);
				
				//If it is our last fork or thread...
				if(i == NUM_THR_PROC - 1)
				{
					d[i].sliceEnd = d[i].sliceEnd + rem;
				}
			}
		}
		for(i = 0; i < NUM_THR_PROC; i++)
		{		
			switch(pid[i] = fork())
			{
				case -1:
					fprintf(stderr, "Fork failed");
				case 0: //child process
					saDefault.sa_handler = SIG_DFL;
					saDefault.sa_flags = 0;
					sigemptyset(&saDefault.sa_mask);

					if (saOrigInt.sa_handler != SIG_IGN)
						sigaction(SIGINT, &saDefault, NULL);
					if (saOrigQuit.sa_handler != SIG_IGN)
						sigaction(SIGQUIT, &saDefault, NULL);

					sigprocmask(SIG_SETMASK, &origMask, NULL);
					printf("%d start: \n", d[i].sliceSt);
					printf("%d end: \n", d->sliceEnd);
					runSystem(d[i].sliceSt, d[i].sliceEnd, d[i].offset);
					
					exit(EXIT_SUCCESS);
				default:
					break;
			}
		}
		
	}

	//Parse the char array and extract all happy primes with this FUNCtion.
	mapTurnin(numBytes);
	
	while(wait(NULL) != -1);
    shm_unlink("/shProc");
	

	clock_t toc = clock();

    printf("Elapsed: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
	return EXIT_SUCCESS;
}