《《并行程序设计》实验报告.docx》由会员分享,可在线阅读,更多相关《《并行程序设计》实验报告.docx(5页珍藏版)》请在第一文库网上搜索。
1、并行程序设计实验报告2018/07/04华南理工大学本科实验报告课程名称并行程序设计成绩评定实验项目名称MPI+OpenMP实现PSRS排序实验。数据量大小1G个整型数。1、实验目标(1)利用visual studio配置MPI环境和mpi混合编译环境;(2) MPI+OpenMP实现PSRS排序实验。数据量大小1G个整型数。2、串行程序代码(串行程序已经放在网络教学平台,请把主要代码部分摘抄在下面)void Odd_even_sort(int a /* in/out */,int n /* in */) int phase, i, temp;for (phase = 0; phase n;
2、phase+)if (phase % 2 = 0) /* Even phase */for (i = 1; i ai) temp = ai;ai = ai-l;ai-l = temp;) else /* Odd phase */for (i = 1; i ai+l) temp = ai;ai = ai+l;ai+l = temp;) /* Odd_even_sort */3、并行程序关键代码4、性能分析表1采用1进程时,使用不同线程数在1G数据集上的测试结果线程数248运行方式串行并行并行并行运行时间(s)19.1744.3325.4015.51加速比0.430.761.24效率0.220.1
3、90.15截图编号图1图3图4图5表2采用2进程时,使用不同线程数在1G数据集上的测试结果线程数1248运行方式串行并行并行并行并行运行时间(s)19.1745.1690.8043.3741.97加速比0.420.210.440.46效率0.210.050.060.03截图编号图1图2图3图4图5表3采用4进程时,使用不同线程数在1G数据集上的测试结果线程数1248运行方式串行并行并行并行并行运行时间(s)19.1726.3466.7629.2436.14加速比0.730.660.660.53效率0.180.080.040.02截图编号图1图2图3图4图5图1串行:C:UsersAdminis
4、tratorDesktopparal 1 elmix2x64Releaserr?iexec -n 1 mix2. exeread end.1G, process: 1, 1 threads in per process time: 19.172960salg. success!图2 1G数据1、2、4进程+1线程:C:UsersAdministratorDesktopparallelmix2x64Releaseinpiexec -n 1 mix2. exeread end.1G, process: 1, 1 threads in per process time: 19. 172960salg
5、. success!C:UsersAdministratorDesktopparallelinix2x64Releaseir?iexec -n 2 mix2. exeread end.1G, process: 2, 1 threads in per process time: 45. 155738salg. success!C:UsersAdministratorDesktopparallelmix2x64Releaseirf)iexec -n 4 mix2. exeread end.1G, process: 4, 1 threads in per process time: 26. 3886
6、46salg. success!图3 1G数据1、2、4进程+2线程:C:UsersAdininistratorDesktopparallelinix2x64Releaseirtiexec -n 2 mix2. exeread end.,1G, process: 2, 2 threads in per process time: 90. 798443salg. success!C:UsersAdministratorDesktopparallelmix2x64Releaseirf)iexec -n 1 mix2. exeread end.1G, process: 1, 2 threads in
7、 per process time: 44. 332905salg. success!C:UsersAdministratorDesktopparallelmix2x64Releaseirfiexec -n 4 mix2. exeread end.1G, process: 4, 2 threads in per process time: 66.762108salg. success!图4 1G数据1、2、4进程+4线程:3:UsersAdministratorDesktopparallelmix2x64Releaseirpiexec -n 1 mix2.exeread end.1G, pro
8、cess: 1, 4 threads in per process time: 25. 403736salg. success!UsersAdininistratorDesktopparallelinix2x64Releaseinpiexec -n 2 mix2. exeread end.1G, process: 2, 4 threads in per process time: 43. 371446salg. success!3:UsersAdministratorDesktopparallelmix2x64Releaseinpiexec -n 4 mix2.exeread end.1G,
9、process: 4, 4 threads in per process time: 29. 242632salg. success!图5 1G数据1、2、4进程+8线程:?:UsersAdministratorDesktopparallelmix2x64Releaseir)iexec -n 1 mix2. exeread end.1G, process: 1, 8 threads in per process time: 15. 513640salg. success!3:UsersAdministratorDesktopparallelmix2x64Releaseinpiexec -n 2
10、 mix2.exeread end.1G, process: 2, 8 threads in per process time: 41. 969458salg. success!?:UsersAdministratorDesktopparal 1 elmix2x64Releaseiripiexec -n 4 mix2. exeread end.1G, process: 4, 8 threads in per process time: 36.137507salg. success!图6:不同进程分别在不同线程下排序所需要的时间5、总结本次实验的机器是4核CPU,每个核有8个逻辑处理器,因此分别进行了 1、2、4进程搭配1、2、4、8线程的实验,从实验结果来看,只有在单进程的时候,将线程数增加到8才取得了更好的效果,而进程数的增加反而更慢了。特别的是在4进程的时候,算法的性能相比于2进程有很大的提升,但是仍然不如串行的性能好。6、附件Mpi_omp_int_vs. cpp