八仙数(并行计算)
2016-11-14 21:04
148 查看
// openMP.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <time.h> #include <windows.h> #include <omp.h> #define NUM_THREADS 2 int _tmain(int argc, _TCHAR* argv[]) { omp_set_num_threads(NUM_THREADS); //并行求八仙花数 clock_t t1=clock(); #pragma omp parallel for for(int i=10000000;i<100000000;i++) { int a,b,c,d,e,f,g,h,t; a=i%10; b=(i/10)%10; c=(i/100)%10; d=(i/1000)%10; e=(i/10000)%10; f=(i/100000)%10; g=(i/1000000)%10; h=i/10000000; t=(a*a*a*a*a*a*a*a)+(b*b*b*b*b*b*b*b)+(c*c*c*c*c*c*c*c)+(d*d*d*d*d*d*d*d)+(e*e*e*e*e*e*e*e)+(f*f*f*f*f*f*f*f)+(g*g*g*g*g*g*g*g)+(h*h*h*h*h*h*h*h); if(i==t) { printf("%d\n",i); } } clock_t t2=clock(); printf("parallel time=%d\n",(t2-t1));//并行时间 //串行求八仙花数 t1=clock(); for(int i=10000000;i<100000000;i++) { int a,b,c,d,e,f,g,h,t; a=i%10; b=(i/10)%10; c=(i/100)%10; d=(i/1000)%10; e=(i/10000)%10; f=(i/100000)%10; g=(i/1000000)%10; h=i/10000000; t=(a*a*a*a*a*a*a*a)+(b*b*b*b*b*b*b*b)+(c*c*c*c*c*c*c*c)+(d*d*d*d*d*d*d*d)+(e*e*e*e*e*e*e*e)+(f*f*f*f*f*f*f*f)+(g*g*g*g*g*g*g*g)+(h*h*h*h*h*h*h*h); if(i==t) { printf("%d\n",i); } } t2=clock(); printf("parallel time=%d\n",(t2-t1));//串行时间 system("pause"); return 0; }
运行结果:
相关文章推荐
- matlab并行计算
- Udacity并行计算课程笔记-The GPU Hardware and Parallel Communication Patterns
- .Net中并行计算的了解
- 【并行计算与CUDA开发】基于NVIDIA显卡的硬编解码的一点心得 (完结)
- 什么是并行计算?什么是分布式计算?并行计算和分布式计算之前的区别:
- 分布式计算 网格计算 并行计算 云计算
- Python 多核并行计算的示例代码
- MapReduce和HPC集群并行计算优劣对比
- .NET4.0并行计算技术基础(12)
- c++多线程编程:实现标准库accumulate函数的并行计算版本
- 并行计算之Memory barrier(内存
- 并行计算(Parallel Computing)初步认识
- 关于hadoop集群的简单性能测试——mapreduce性能,hive性能,并行计算分析(原创)
- 浅谈.NET下的多线程和并行计算(八)Winform中多线程编程基础上
- 课程资源 并行计算
- Visual C++2010编译器常用选项设置-新增支持并行计算
- 并行计算之OpenMPx
- 并行计算—OpenMP—统计完数个数
- 利用GPU进行高性能数据并行计算《程序员》2008年第4期
- 并发变成之:无锁并行计算