⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xshortestmain.cpp

📁 最短路径的并行算法 采用TBB 需要intel编译器 速度很快
💻 CPP
字号:
/*/////////////////////////////////////////
// 版权所有(C)  2000-2008 邓辉           //
// Email:      denghui0815@hotmail.com  //
// 说明:       Intel线程优化大赛参赛作品//
/////////////////////////////////////////*/

#include "XDijkstra.h"
#include "XFloyed.h"

// 使用说明
void Usage(void)
{
	printf("Usage: XShortest.exe <file name> [ap|as|dp|ds|fp|fs|test] [NodeNum] [Density]\n");
	printf("Usage: ap = Auto Select Parallel\n");
	printf("Usage: as = Auto Select Serial\n");
	printf("Usage: dp = Dijkstra Parallel\n");
	printf("Usage: ds = Dijkstra Serial\n");
	printf("Usage: fp = Floyed Parallel\n");
	printf("Usage: fs = Floyed Serial\n");
	printf("Usage: test = Create Test Data\n");
}
 
int main(int argc, char* argv[])
{
	// 创建任务scheduler
	task_scheduler_init init;
	tick_count nBeg,nEnd;
	tick_count nBegAll,nEndAll;
	char szInput[MAX_PATH]  =  "data.in";
	char szOutput[MAX_PATH] =  "path.out";
	
	// 运行模式
	uint32 nRunMode = XRUN_AUTO_PARALLEL;
	// 解析命令行参数
	switch(argc)
	{
	case 3:
		if(strcmp(argv[2], "as") == 0) { nRunMode = XRUN_AUTO_SERIAL; }
		else if(strcmp(argv[2], "dp") == 0) { nRunMode = XRUN_DIJKSTRA_PARALLEL; }
		else if(strcmp(argv[2], "ds") == 0) { nRunMode = XRUN_DIJKSTRA_SERIAL; }
		else if(strcmp(argv[2], "fp") == 0) { nRunMode = XRUN_FLOYED_PARALLEL; }
		else if(strcmp(argv[2], "fs") == 0) { nRunMode = XRUN_FLOYED_SERIAL; }
		else { nRunMode = XRUN_AUTO_PARALLEL; }
	case 2:
		strcpy(szInput, argv[1]);
		break;
	case 5:
		if(strcmp(argv[2], "test") == 0)
		{
			strcpy(szInput, argv[1]);
			XCreateTestData(szInput, atoi(argv[3]), atof(argv[4]));
		}
		break;
	case 1:
	default: 
		Usage();
		exit(0);
		break;
	}

	if(nRunMode == XRUN_FORPGO)
	{
		XCreateTestData(szInput, 500, 200);
	}
	
	do
	{
		uint32 nMask = nRunMode & -nRunMode;

		nRunMode -= nMask;
		// 加载Graph
		nBeg = nBegAll = tick_count::now(); 

		XGraph<uint32>*	pGraph = XDataFileRead(szInput, nMask);

		nEnd = tick_count::now(); 
	 
		printf("Load Data Time: %f seconds\n", (nEnd - nBeg).seconds());

		// 调用最短路径算法
		nBeg = tick_count::now(); 

		switch(nMask)
		{
		case XRUN_DIJKSTRA_PARALLEL:
			printf("Dijkstra Parallel:\n");
			XDijkstraParallel<uint32>(pGraph);
			break;
		case XRUN_DIJKSTRA_SERIAL:
			printf("Dijkstra Serial:\n");
			XDijkstraSerial<uint32>(pGraph);
			break;
		case XRUN_FLOYED_PARALLEL:
			printf("Floyed Parallel:\n"); 
			XFloyedParallel<uint32>(pGraph);
			break;
		case XRUN_FLOYED_SERIAL:
			printf("Floyed Serial:\n");
			XFloyedSerial<uint32>(pGraph);
			break;
		default:
			Usage();
			break;
		}

		nEnd = tick_count::now();  
	  
		printf("Shortest Time: %f seconds\n", (nEnd - nBeg).seconds());

		// 输出排序结果
		nBeg = tick_count::now(); 

		XDataFileSave(szOutput, pGraph);

		nEnd = nEndAll = tick_count::now(); 

		printf("Save Data Time: %f seconds\n", (nEnd - nBeg).seconds());

		printf("Total Time: %f seconds\n\n", (nEndAll - nBegAll).seconds());

		// 销毁Graph
		XGraphDestroy(&pGraph);

	} while( nRunMode );

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -