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


C++ BS::AddChunkIncremental方法代码示例

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


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

示例1: BSthread

DWORD WINAPI BSthread(LPVOID p)
{

	int threadID = *(int*)p;
	BS *bs = new BS(NITEMS / NTHREADS);
	SetThreadAffinityMask(GetCurrentThread(), 1 << threadID);

	if (threadID == 0)
		printf(

			"Starting sort...\n");
	UINT64 insertedItems = 0, totalItems = 0;
	// method B: one single stream with a dispatcher
	clock_t startAll = clock();
	clock_t startCur = startAll;
	int iter = 0;
	while (true)
	{

		// running a critical section here seems to help with speed and getting threads to finish closer together,
		// but strictly speaking, no sync is necessary unless the dispatcher runs concurrently with sorting threads
		EnterCriticalSection(&cs[threadID]);

		while (jobQ[threadID].size() == 0)
		{

			LeaveCriticalSection(&cs[threadID]);

			if (quit == true) // queue is empty and quit is true --> terminate
			{

				bs->AddChunkFinalize();

				double elapsed = (double)(clock() - startAll) / CLOCKS_PER_SEC;
				double speed = (double)totalItems / elapsed / 1e6;
				printf(

					"thread %d: sorted %.2fM keys in %.2f sec @ %.2f M/sec\n", threadID, (double)totalItems / 1e6, elapsed, speed);
				return 0;
			}

			Sleep(10);

			EnterCriticalSection(&cs[threadID]);

		}

		Job jb = jobQ[threadID].front();
		jobQ[threadID].pop();

		LeaveCriticalSection(&cs[threadID]);

		// once we exceed a set threshold, sort all pending buckets @ level 1 and reset to beginning
		if (insertedItems + jb.size > NITEMS / NTHREADS)
		{

			bs->AddChunkFinalize();

			double elapsed = (double)(clock() - startCur) / CLOCKS_PER_SEC;
			if (threadID == 0)
			{

				printf(

					"%d) sorted %.2fM items @ %.2fM/sec\n", iter, insertedItems / 1e6, insertedItems / elapsed / 1e6);
				startCur = clock();

				iter++;

			}

			insertedItems = 0;

			//printf ("finalized\n");
		}

		bs->AddChunkIncremental(bufInput + jb.offset, jb.size);

		insertedItems += jb.size;

		totalItems += jb.size;

	}

	delete bs;
	return 0;
}
开发者ID:yaoyuan0553,项目名称:BucketSortWithStream,代码行数:87,代码来源:emailed.cpp


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