资源简介
这是用mpi与openmp并行计算实现蒙特卡洛算法求不规则图形面积,其中还需用opencv进行图像处理,拍照生成.jpg文件,注意图片尺寸。

代码片段和文件信息
#include
#include
#include
#include
#include
int main(){
int comm_sz;
int my_rank;
int numsum=0;
int countall_count;
int a[440][590];
double xy;
srand((unsigned)time(0));
FILE *fp=fopen(“1.txt““r“);
if(fp==NULL){
printf(“open error\n“);
return -1;
}
for(int i=0;i<434;i++){
for(int j=0;j<578;j++){
fscanf(fp“%d“&a[i][j]);
}
fscanf(fp“\n“);
}
MPI_Init(NULLNULL);
MPI_Comm_size(MPI_COMM_WORLD&comm_sz);
MPI_Comm_rank(MPI_COMM_WORLD&my_rank);
double startfinish;
if(my_rank!=0){
num=0;
start=MPI_Wtime();
MPI_Recv(&count1MPI_INT00MPI_COMM_WORLDMPI_STATUS_IGNORE);
srand(my_rank);
for(int i=0;i x=(double)(433.0*rand()/RAND_MAX); //产生0-433的随机数
y=(double)(577.0*rand()/RAND_MAX);
if(a[(int)x][(int)y]==1)
num++;
}
finish=MPI_Wtime();
printf(“proc %d > Elapse time =%e seconds\n“my_rankfinish-start);
MPI_Send(&num1MPI_INT00MPI_COMM_WORLD);
}
else{
printf(“please input the count of all point :“);
scanf(“%d“&all_count);
count=all_count/comm_sz;
start=MPI_Wtime();
for(int q=1;q MPI_Send(&count1MPI_INTq0MPI_COMM_WORLD);
}
srand(my_rank);
for(int i=0;i x=(double)(433.0*rand()/RAND_MAX); //产生0-433的随机数
y=(double)(577.0*rand()/RAND_MAX);
if(a[(int)x][(int)y]==1)
sum++;
}
for(int q=1;q MPI_Recv(&num1MPI_INTq0MPI_COMM_WORLDMPI_STATUS_IGNORE);
sum+=num;
}
printf(“the count of point in the graph:%d\n“sum);
printf(“the area is :%lf\n“((double)sum/all_count)*400);
finish=MPI_Wtime();
printf(“proc %d > Elapse time =%e seconds\n“my_rankfinish-start);
}
MPI_Finalize();
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-01-19 23:41 蒙特卡罗求面积\
目录 0 2019-01-19 23:41 蒙特卡罗求面积\mpi_openmp\
文件 502138 2019-01-09 10:48 蒙特卡罗求面积\mpi_openmp\1.txt
文件 16600 2019-01-19 23:07 蒙特卡罗求面积\mpi_openmp\mpi
文件 2105 2019-01-18 10:51 蒙特卡罗求面积\mpi_openmp\mpi.c
文件 16576 2019-01-19 23:09 蒙特卡罗求面积\mpi_openmp\omp
文件 1265 2019-01-15 13:21 蒙特卡罗求面积\mpi_openmp\omp.c
目录 0 2019-01-19 23:40 蒙特卡罗求面积\test\
文件 3432570 2019-01-07 14:59 蒙特卡罗求面积\test\1.jpg
文件 502138 2019-01-19 23:39 蒙特卡罗求面积\test\1.txt
文件 11727 2019-01-01 21:42 蒙特卡罗求面积\test\CMakeCache.txt
目录 0 2019-01-19 23:40 蒙特卡罗求面积\test\CMakeFiles\
目录 0 2019-01-19 23:40 蒙特卡罗求面积\test\CMakeFiles\3.5.1\
文件 2002 2019-01-01 21:42 蒙特卡罗求面积\test\CMakeFiles\3.5.1\CMakeCCompiler.cmake
文件 4556 2019-01-01 21:42 蒙特卡罗求面积\test\CMakeFiles\3.5.1\CMakeCXXCompiler.cmake
文件 8640 2019-01-01 21:42 蒙特卡罗求面积\test\CMakeFiles\3.5.1\CMakeDetermineCompilerABI_C.bin
文件 8656 2019-01-01 21:42 蒙特卡罗求面积\test\CMakeFiles\3.5.1\CMakeDetermineCompilerABI_CXX.bin
文件 402 2019-01-01 21:42 蒙特卡罗求面积\test\CMakeFiles\3.5.1\CMakeSystem.cmake
目录 0 2019-01-19 23:40 蒙特卡罗求面积\test\CMakeFiles\3.5.1\CompilerIdC\
文件 16423 2019-01-01 21:42 蒙特卡罗求面积\test\CMakeFiles\3.5.1\CompilerIdC\CMakeCCompilerId.c
文件 8800 2019-01-01 21:42 蒙特卡罗求面积\test\CMakeFiles\3.5.1\CompilerIdC\a.out
目录 0 2019-01-19 23:40 蒙特卡罗求面积\test\CMakeFiles\3.5.1\CompilerIdCXX\
文件 16406 2019-01-01 21:42 蒙特卡罗求面积\test\CMakeFiles\3.5.1\CompilerIdCXX\CMakeCXXCompilerId.cpp
文件 8808 2019-01-01 21:42 蒙特卡罗求面积\test\CMakeFiles\3.5.1\CompilerIdCXX\a.out
文件 609 2019-01-01 21:42 蒙特卡罗求面积\test\CMakeFiles\CMakeDirectoryInformation.cmake
文件 40301 2019-01-01 21:42 蒙特卡罗求面积\test\CMakeFiles\CMakeOutput.log
目录 0 2019-01-19 23:42 蒙特卡罗求面积\test\CMakeFiles\CMakeTmp\
文件 2093 2019-01-19 23:38 蒙特卡罗求面积\test\CMakeFiles\Makefile.cmake
文件 3200 2019-01-19 23:38 蒙特卡罗求面积\test\CMakeFiles\Makefile2
文件 139 2019-01-19 23:38 蒙特卡罗求面积\test\CMakeFiles\TargetDirectories.txt
文件 85 2019-01-19 23:38 蒙特卡罗求面积\test\CMakeFiles\cmake.check_cache
............此处省略20个文件信息
- 上一篇:二手市场答辩PPT
- 下一篇:基于BUCK电路电压模式的反馈环路设计
相关资源
- 马尔科夫 蒙特卡罗方法.rar 中文版
- BFSK/BPSK-BER 蒙特卡洛仿真程序
- Exact Conditions of Blow-up and Global Existen
- doneex xcell compiler 2.1.2.9绿色汉化版(
- 山东大学编译原理PL/0语言 compiler实验
- 基于蒙特卡洛生成电动汽车充电负荷
- 10负荷点配电网蒙特卡洛法可靠性计算
- 三维可压缩流场MPI+OpenMP混合并行算法
- Wind River Diab Compiler for PowerPC
- MPI和CUDA在多层快速多极子中的应用
- 论文研究 - 开放性试验研究Yokukansan
- 论文研究 - 通过共形图进行快速扩散
- FFT并行MPI实现
- Design_compiler经典教程
- θ=π时具有“拓扑”项的反
- 龙书《编译原理》(Compilers:Principle
- Writing A Compiler In Go.pdf
- DFT Compiler Scan User Guide Version E-2010.12
- OpenMP编译原理及实现技术
- 蒙特卡洛算法
- synopsys公司的Design Compiler license生成工
- 基于Leslie模型的中国人口预测及蒙特
- 量化策略开发流程蒙特卡洛方法等五
- 综合与Design Compiler
- 蒙特卡洛方法原理及编程
- 蒙特卡罗方法与MCNP程序入门.
- Design Compiler student guide-学习手册
- 配电网可靠性评估
- OpenCV 1.0.0 patch for ffmpeg errors
- delphi反编译工具 Decompiler v1.1.0.194
评论
共有 条评论