MPI编程--求最大值
来源:互联网 发布:网络推广新闻发布 编辑:程序博客网 时间:2024/06/10 06:20
#include <stdio.h>#include <mpi.h>#include <malloc.h>int main (int argc ,char** argv){ int rank,size,i,max,MAX; int a; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD,&size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); a = 1000/size; int rbuf1[a]; int *sbuf = (int *) malloc(sizeof(int) * a * size); int *rbuf2 = (int*)malloc(sizeof(int) * size); if (rank == 0){ for(i=1;i<=a*size;i++){ sbuf[i-1] = i; }} MPI_Scatter(sbuf, a, MPI_INT, rbuf1, a, MPI_INT, 0, MPI_COMM_WORLD); max = rbuf1[0]; for(i=1;i<a;i++) if(rbuf1[i] > max) max = rbuf1[i]; printf("Process %d 's max = %d\n",rank,max); MPI_Gather(&max, 1, MPI_INT, rbuf2, 1, MPI_INT, 0, MPI_COMM_WORLD); if(rank == 0){ MAX = rbuf2[0]; for(i=1;i<size;i++){ if(rbuf2[i]>MAX) MAX = rbuf2[i]; } printf("The Maximum = %d\n",MAX); } MPI_Finalize(); return 0;}
阅读全文
0 0
- MPI编程--求最大值
- [编程题]求最大值
- [编程题]求最大值
- C++求最大值编程
- POJ 1502 MPI Maelstrom 【单源最短路中求最大值】
- ELisp编程十:求最大值
- 编程求最大值 用指针
- shell编程连载【5】- 求最大值
- 编程:求三个整数中的最大值
- MPI编程
- MPI编程
- MPI编程--求cos(x)的定积分
- 求最大值
- 求最大值
- 求最大值
- 求最大值
- 求最大值
- 求最大值
- rabbitmq 交换模式-Headers
- mysql通过Binlog恢复数据到sql文件实战
- 语音信号滤波去噪——使用FLATTOPWIN设计的FIR滤波器
- 抢救
- My.Life.Story.v1.0-TE\
- MPI编程--求最大值
- 关于Xcode"this class is not key value coding-compliant for the key" 的错误问题
- hitag 2 算法 (来源网络)
- linux总结08-25 个常用的 Linux iptables 规则
- Docker搭建自己的Gitlab CI Runner
- 初识spring boot和spring data jpa
- 磁疗是真的吗?磁场对生命体征的作用
- Java web ueditor编辑器
- AfxGetApp