当前位置: 首页>>代码示例>>C++>>正文


C++ Counter::begin方法代码示例

本文整理汇总了C++中Counter::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ Counter::begin方法的具体用法?C++ Counter::begin怎么用?C++ Counter::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Counter的用法示例。


在下文中一共展示了Counter::begin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[])
{
	int    oc;
	size_t ntask = sysconf(_SC_NPROCESSORS_ONLN);
	size_t nslot = sysconf(_SC_NPROCESSORS_ONLN);
	int    range = 0x10000;
	float  s     = 0.0;
	size_t size  = 10000000;
	bool   check = false;
	char  * file = NULL;

	nslot *= nslot;

	while ((oc = getopt(argc, argv, "t:k:n:r:s:w:zh")) != -1) {
		switch (oc) {
		case 't':
			ntask = std::min((size_t)strtoul(optarg, 0, 10), ntask);
			break;
		case 'k':
			nslot = strtoul(optarg, 0, 10);
			break;
		case 'n':
			size  = strtoul(optarg, 0, 10);
			break;
		case 'r':
			range = atoi(optarg);
			break;
		case 's':
			s     = atof(optarg);
			break;
		case 'w':
			file = optarg;
			break;
		case 'z':
			check = true;
			break;
		case 'h':
			printf(usage, argv[0]);
			exit(EXIT_SUCCESS);
		default:
			exit(EXIT_FAILURE);
		}
	}

	typedef wc_splitter Splitter;

	typedef multi_hash_runtime<
		wc_splitter, size_t, size_t, wc_mapper, mapcombine::simple_partition<size_t> > Runtime;

	typedef Runtime::storage_type Storage;

	// for verification
	typedef open_hash_map<Storage::key_type, Storage::value_type> Counter;

	// three elements of a computation
	Splitter splitter(size, range, s);
	Storage	 storage(nslot);
	Runtime	 runtime(splitter, storage);

	timespec timer;
	timer_start(&timer);
	runtime.run(ntask);
	float elapsed = timer_stop(&timer);

	printf("nslot=%lu, range=%d, s=%f, size=%lu, elapsed=%f\n",
	       (unsigned long)nslot, range, s, (unsigned long)size, elapsed);

	splitter.split(1);
	Splitter::chunk_type chunk = splitter.chunk(0);

	if (file) {
		FILE *fp = fopen(file, "wb");
		if (fp == NULL) {
			fprintf(stderr, "cannot open %s\n", file);
			exit(EXIT_FAILURE);
		}
		for (Splitter::chunk_type::const_iterator it = chunk.begin();
		     it != chunk.end(); ++it) {
			Splitter::chunk_type::value_type r = *it;
			fwrite(&r, sizeof(r), 1, fp);
		}
		fclose(fp);
	}

	if (check) {
		Counter counter;
		timer_start(&timer);
		for (Splitter::chunk_type::iterator it = chunk.begin();
		     it != chunk.end(); ++it)
			++counter[*it];
		elapsed = timer_stop(&timer);
		fprintf(stderr, "build counter successfully: %f sec\n", elapsed);
		for (Counter::const_iterator it = counter.begin(); it != counter.end(); ++it) {
			if (it.value() != storage[it.key()]) {
				fprintf(stderr, "expect %zu, actual %zu for key %zu\n",
					storage[it.key()], it.value(), it.key().key());
				exit(EXIT_FAILURE);
			}
		}
		fprintf(stderr, "backward check OK\n");
//.........这里部分代码省略.........
开发者ID:ZilongTan,项目名称:ParallelComputing,代码行数:101,代码来源:mc_rng_bench_mh.cpp


注:本文中的Counter::begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。