示例#1
0
void server_procedure(struct command_line_args *object)
{
	struct packet *p;
	My402ListElem *elem = NULL;
	struct timespec tim;
	double time;
	long time_diff_in_nsec;
	int i = 0;
	while( i < object->no_of_packets && !EndServerThread) 
	{
		pthread_mutex_lock(&token_bucket);
		while(My402ListEmpty(&Q2PacketList)&&!EndServerThread)
			pthread_cond_wait(&is_q2_empty,&token_bucket);

		if(EndServerThread == 1)
		{
			pthread_mutex_unlock(&token_bucket);
			break;
		}

		elem = My402ListFirst(&Q2PacketList);
		if(elem == NULL)
		{
			pthread_mutex_unlock(&token_bucket);
			break;
		}
		p = (struct packet *)elem->obj;
		My402ListUnlink(&Q2PacketList, elem);

		pthread_mutex_unlock(&token_bucket);
	
		gettimeofday(&(p->Q2leaves), NULL);
		time = (TIME_IN_USEC(p->Q2leaves) - TIME_IN_USEC(GlobalStartTime))/1000;
		p->time_in_Q2 = (TIME_IN_USEC(p->Q2leaves) - TIME_IN_USEC(p->Q2timestamp))/1000;

		LOG(stdout, "%012.3fms: p%d begin service at S, time in Q2 = %.3fms\n",time,p->packet_id,p->time_in_Q2);
 
		time_diff_in_nsec = (long)((((p->precise_packet_service_time)/1000) - (p->service_time/1000))*1000000000L);
		tim.tv_sec = (p->service_time)/1000;
		tim.tv_nsec = time_diff_in_nsec;
	
		nanosleep(&tim, NULL);
	
		gettimeofday(&(p->Leaves_server), NULL);
		time = (TIME_IN_USEC(p->Leaves_server) - TIME_IN_USEC(GlobalStartTime))/1000;
		p->time_in_system = (TIME_IN_USEC(p->Leaves_server) - TIME_IN_USEC(p->Arrival_timestamp))/1000;
		p->precise_packet_service_time = (TIME_IN_USEC(p->Leaves_server) - TIME_IN_USEC(p->Q2leaves))/1000;
		LOG(stdout, "%012.3fms: p%d departs from S, service time = %.3fms, time in system = %.3fms\n",time,p->packet_id,p->precise_packet_service_time,p->time_in_system);
		completed_packets ++;
		calculate_stats(p);
		if((packet_count == object->no_of_packets) &&(completed_packets == (packet_count-discarded_packets)) && My402ListEmpty(&Q2PacketList))
		{
			EndServerThread = 1;
			pthread_cond_signal(&is_q2_empty);
		}
		i++;
	}
	pthread_exit(NULL);
	
}
示例#2
0
stats calculate_stats(int category, std::string save_id)
{
	DBG_NG << "calculate_stats, category: " << category << " side: " << save_id << " master_stats.size: " << master_stats.size() << "\n";
	if(category == 0) {
		stats res;
		// We are going from last to first to include correct turn stats in result
		for(int i = int(master_stats.size()); i > 0 ; --i) {
			merge_stats(res,calculate_stats(i,save_id));
		}

		return res;
	} else {
		const size_t index = master_stats.size() - size_t(category);
		if(index < master_stats.size() && master_stats[index].team_stats.find(save_id) != master_stats[index].team_stats.end()) {
			return master_stats[index].team_stats[save_id];
		} else {
			return stats();
		}
	}
}
wxString htmlWidgetStocks::getHTMLText()
{
    wxString output = "";
    std::map<int, std::pair<double, double> > stockStats;
    calculate_stats(stockStats);
    if (!stockStats.empty())
    {
        output = "<table class ='sortable table'><col style='width: 50%'><col style='width: 25%'><col style='width: 25%'><thead><tr class='active'><th>\n";
        output += _("Stocks") + "</th><th class = 'text-right'>" + _("Gain/Loss");
        output += "</th>\n<th class='text-right'>" + _("Total") + "</th>\n";
        output += wxString::Format("<th nowrap class='text-right sorttable_nosort'><a id='%s_label' onclick='toggleTable(\"%s\");' href='#%s' oncontextmenu='return false;'>[-]</a></th>\n"
            , "INVEST", "INVEST", "INVEST");
        output += "</tr></thead><tbody id='INVEST'>\n";
        const auto &accounts = Model_Account::instance().all(Model_Account::COL_ACCOUNTNAME);
        wxString body = "";
        for (const auto& account : accounts)
        {
            if (Model_Account::type(account) != Model_Account::INVESTMENT) continue;
            if (Model_Account::status(account) != Model_Account::OPEN) continue;
            body += "<tr>";
            body += wxString::Format("<td sorttable_customkey='*%s*'><a href='stock:%i' oncontextmenu='return false;'>%s</a></td>\n"
                , account.ACCOUNTNAME, account.ACCOUNTID, account.ACCOUNTNAME);
            body += wxString::Format("<td class='money' sorttable_customkey='%f'>%s</td>\n"
                , stockStats[account.ACCOUNTID].first
                , Model_Account::toCurrency(stockStats[account.ACCOUNTID].first, &account));
            body += wxString::Format("<td colspan='2' class='money' sorttable_customkey='%f'>%s</td>"
                , stockStats[account.ACCOUNTID].second
                , Model_Account::toCurrency(stockStats[account.ACCOUNTID].second, &account));
            body += "</tr>";
        }

        output += body;
        output += "</tbody><tfoot><tr class = 'total'><td>" + _("Total:") + "</td>";
        output += wxString::Format("<td class='money'>%s</td>"
            , Model_Currency::toCurrency(grand_gain_lost_));
        output += wxString::Format("<td colspan='2' class='money'>%s</td></tr></tfoot></table>"
            , Model_Currency::toCurrency(grand_total_));
        if (body.empty()) output.clear();
    }
    return output;
}
示例#4
0
QVector<Genome> GenAlg::epoch(QVector<Genome> prev_generation)
{
    m_population = prev_generation;
    reset();
    std::sort(m_population.begin(), m_population.end());

    calculate_stats();

    QVector<Genome> new_pop;

    grab_N_best(Globs::NUM_ELITES, Globs::NUM_COPIES, new_pop);

    while(new_pop.size() < m_population_size)
    {
        Genome mom = select_roulette();
        Genome dad = select_roulette();
        Genome baby = cross_over(mom, dad);
        mutate(baby);
        new_pop.append(baby);
    }
    return std::move(new_pop);
}
示例#5
0
文件: blk_mt.c 项目: KaiZhang666/nvml
int
main(int argc, char *argv[])
{
	struct blk_arguments arguments;

	/* set the random seed value */
	srand(time(NULL));

	/* set default values */
	memset(&arguments, 0, sizeof (struct blk_arguments));
	arguments.block_size = 512;
	arguments.num_ops = 100;
	arguments.file_size = (PMEMBLK_MIN_POOL / 1024) / 1024;

	if (argp_parse(&argp, argc, argv, 0, 0, &arguments) != 0) {
		exit(1);
	}

	struct worker_info worker_params[arguments.thread_count];
	memset(worker_params, 0, sizeof (struct worker_info));

	/* set common values */
	worker_params[0].block_size = arguments.block_size;
	worker_params[0].num_ops = arguments.num_ops;
	worker_params[0].file_lanes = arguments.thread_count;

	/* file_size is provided in MB */
	unsigned long long file_size_bytes = arguments.file_size * 1024 * 1024;

	worker *thread_workers = NULL;

	/* prepare parameters specific for file/pmem */
	if (arguments.file_io) {
		/* prepare open flags */
		int flags = O_RDWR | O_CREAT | O_SYNC;
		/* create file on PMEM-aware file system */
		if ((worker_params[0].file_desc = open(arguments.file_path,
			flags, FILE_MODE)) < 0) {
			perror(arguments.file_path);
			exit(1);
		}

		/* pre-allocate file_size MB of persistent memory */
		if ((errno = posix_fallocate(worker_params[0].file_desc,
			(off_t)0, (off_t)file_size_bytes)) != 0) {
			warn("posix_fallocate");
			close(worker_params[0].file_desc);
			exit(1);
		}

		worker_params[0].num_blocks = file_size_bytes
				/ worker_params[0].block_size;
		thread_workers = file_workers;
	} else {
		worker_params[0].file_desc = -1;
		if (arguments.prep_blk_file) {
			if ((worker_params[0].handle = pmemblk_create(
				arguments.file_path,
				worker_params[0].block_size,
				(off_t)file_size_bytes, FILE_MODE)) == NULL) {
				err(1, "%s: pmemblk_open", argv[2]);
			}
		} else {
			if ((worker_params[0].handle = pmemblk_open(
					arguments.file_path,
					worker_params[0].block_size)) == NULL) {
				err(1, "%s: pmemblk_open", argv[2]);
			}

		}
		worker_params[0].num_blocks = pmemblk_nblock(
				worker_params[0].handle);
		thread_workers = pmem_workers;
	}

	/* propagate params to each info_t */
	for (int i = 1; i < arguments.thread_count; ++i) {
		memcpy(&worker_params[i], &worker_params[0],
				sizeof (struct worker_info));
		worker_params[i].thread_index = i;
		worker_params[i].seed = rand();
	}

	/* The blk mode file prep */
	if (arguments.prep_blk_file) {
		if (worker_params[0].file_desc >= 0)
			close(worker_params[0].file_desc);
		return run_threads(prep_worker, arguments.thread_count,
				worker_params);
	}

	struct measurements perf_meas;
	perf_meas.total_ops = arguments.thread_count
			* worker_params[0].num_ops;

	/* perform PMEMBLK warmup */
	if (!arguments.file_io) {
		if (run_threads(warmup_worker, arguments.thread_count,
				worker_params) != 0) {
			if (worker_params[0].file_desc >= 0)
				close(worker_params[0].file_desc);
			exit(1);
		}
	}

	for (int i = 0; i < WORKER_COUNT_MAX; ++i) {
		clock_gettime(CLOCK_MONOTONIC, &perf_meas.start_time);
		if (run_threads(thread_workers[i], arguments.thread_count,
				worker_params) != 0) {
			if (worker_params[0].file_desc >= 0)
				close(worker_params[0].file_desc);
			exit(1);
		}
		clock_gettime(CLOCK_MONOTONIC, &perf_meas.stop_time);

		calculate_stats(&perf_meas);
		printf("%f;%f;", perf_meas.total_run_time,
				perf_meas.ops_per_second);
	}

	printf("\n");

	if (worker_params[0].file_desc >= 0)
		close(worker_params[0].file_desc);

	/* cleanup and check pmem file */
	if (!arguments.file_io) {
		pmemblk_close(worker_params[0].handle);

		/* not really necessary, but check consistency */
		int result = pmemblk_check(arguments.file_path);
		if (result < 0) {
			warn("%s: pmemblk_check",
					arguments.file_path);
		} else if (result == 0) {
			warnx("%s: pmemblk_check: not consistent",
					arguments.file_path);
		}
	}

	exit(0);
}