Esempio n. 1
0
int main(int argc, char **argv)
{
	int i;

	assert(argc == 2);
	int num_threads = atoi(argv[1]);
	assert(num_threads >= 1 && num_threads <= CUCKOO_MAX_THREADS);

	red_printf("main: Initializing shared cuckoo hash table\n");
	cuckoo_init(&keys, &ht_index);

	/**< Thread structures */
	pthread_t worker_threads[CUCKOO_MAX_THREADS];

	for(i = 0; i < num_threads; i ++) {
		int tid = i;
		pthread_create(&worker_threads[i], NULL, cuckoo_thread, &tid);

		/**< Ensure that threads don't use the same keys close in time */
		sleep(1);
	}

	for(i = 0; i < num_threads; i ++) {
		pthread_join(worker_threads[i], NULL);
	}

	/**< The work never ends */
	assert(0);

	return 0;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
	int i;

	/** < Variables for PAPI */
	float real_time, proc_time, ipc;
	long long ins;
	int retval;

	red_printf("main: Initializing cuckoo hash table\n");
	cuckoo_init(&keys, &ht_index);

	red_printf("main: Starting lookups\n");
	/** < Init PAPI_TOT_INS and PAPI_TOT_CYC counters */
	if((retval = PAPI_ipc(&real_time, &proc_time, &ins, &ipc)) < PAPI_OK) {    
		printf("PAPI error: retval: %d\n", retval);
		exit(1);
	}

	for(i = 0; i < NUM_KEYS; i += BATCH_SIZE) {
		process_batch(&keys[i]);
	}

	if((retval = PAPI_ipc(&real_time, &proc_time, &ins, &ipc)) < PAPI_OK) {    
		printf("PAPI error: retval: %d\n", retval);
		exit(1);
	}

	red_printf("Time = %.4f s, rate = %.2f\n"
		"Instructions = %lld, IPC = %f\n"		
		"sum = %d, succ_1 = %d, succ_2 = %d, fail = %d\n", 
		real_time, NUM_KEYS / real_time,
		ins, ipc,
		sum, succ_1, succ_2, fail);

	return 0;
}
Esempio n. 3
0
int main(int argc, char** argv) 
{

    int i;
    int num_writers = 1;
    int num_readers = 1;
    struct timeval tvs, tve; 
    double tvsd, tved, tdiff;

    char ch; 
    while ((ch = getopt(argc, argv, "r:w:h")) != -1) {
        switch (ch) {
        case 'w': num_writers = atoi(optarg); break;
        case 'r': num_readers = atof(optarg); break;
        case 'h': usage(argv[0]); exit(0); break;
        default:
            usage(argv[0]);
            exit(-1);
        }   
    }  


    task_init(total);

    printf("initializing hash table\n");
    table = cuckoo_init(power);
    cuckoo_report(table);

    pthread_t* readers = calloc(sizeof(pthread_t), num_readers);
    pthread_t* writers = calloc(sizeof(pthread_t), num_writers);

    thread_arg_t* reader_args = calloc(sizeof(thread_arg_t), num_readers);
    thread_arg_t* writer_args = calloc(sizeof(thread_arg_t), num_writers);
    // create threads as writers
    for (i = 0; i < num_writers; i ++) {
        writer_args[i].id = i;
        if (pthread_create(&writers[i], NULL, insert_thread, &writer_args[i]) != 0) {
            fprintf(stderr, "Can't create thread for writer%d\n", i);
            exit(-1);
        }
    }

    // create threads as readers
    for (i = 0; i < num_readers; i ++) {
        reader_args[i].id = i;
        if (pthread_create(&readers[i], NULL, lookup_thread, &reader_args[i]) != 0) {
            fprintf(stderr, "Can't create thread for reader%d\n", i);
            exit(-1);
        }
    }


    gettimeofday(&tvs, NULL); 
    tvsd = (double)tvs.tv_sec + (double)tvs.tv_usec/1000000;

    size_t* last_num_read = calloc(sizeof(size_t), num_readers);
    size_t* last_num_written = calloc(sizeof(size_t), num_writers);
    memset(last_num_read, 0, num_readers);
    memset(last_num_written, 0, num_writers);
    while (keep_reading && keep_writing) {
        sleep(1);
        gettimeofday(&tve, NULL); 
        tvsd = (double)tvs.tv_sec + (double)tvs.tv_usec/1000000;
        tved = (double)tve.tv_sec + (double)tve.tv_usec/1000000;
        tdiff = tved - tvsd;
        printf("[tput in MOPS] ");
        for (i = 0; i < num_readers; i ++) {
            printf("reader%d %4.2f ", i, (reader_args[i].num_read - last_num_read[i])/ tdiff/ million );
            last_num_read[i] = reader_args[i].num_read;
        }
        for (i = 0; i < num_writers; i ++) {
            printf("writer%d %4.2f ", i, (writer_args[i].num_written - last_num_written[i])/ tdiff/ million );
            last_num_written[i] = writer_args[i].num_written;
        }
        printf("\n");
        tvs = tve;
    }

    for (i = 0; i < num_readers; i ++) {
        pthread_join(readers[i], NULL);
        printf("[reader%d] %zu lookups, %zu failures\n", i, reader_args[i].ops, reader_args[i].failures);
        if (reader_args[i].failures > 0)
            passed = false;
    }

    for (i = 0; i < num_writers; i ++) {
        pthread_join(writers[i], NULL);
        printf("[writer%d] %zu inserts, %zu failures\n", i, writer_args[i].ops, writer_args[i].failures);
        if (writer_args[i].failures > 0)
            passed = false;
    }


    cuckoo_exit(table);

    printf("[%s]\n", passed ? "PASSED" : "FAILED");
}