资源简介
并行计算大作业,MPI矩阵转置,效果很好

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#define MAX 5001
using namespace std;
int pnummlnfirst[MAX][MAX]*tmp;
double t_start t_end;
int ans[MAX][MAX];
MPI_Status status;
int main(int argc char* argv[]){
int my_rankgroup_size;
int i jp1p2xyt;
n = atoi(argv[1]);
MPI_Init(&argc&argv);
MPI_Comm_size(MPI_COMM_WORLD&group_size);
MPI_Comm_rank(MPI_COMM_WORLD&my_rank);
pnum = group_size;
m = sqrt(pnum);
l = n/m;
tmp = (int *)malloc(sizeof(int)*l*l);
if(my_rank == 0){
FILE *fp = fopen(“Parallel_compumatrix.txt““r“);
if(!fp){
printf(“error“);
exit(1);
}
else
{
for(i = 0; i < n; i++){
for(j = 0; j < n; j++){
fscanf(fp“%d “&(first[i][j]));
//printf(“%2d “first[i][j]);
}
//printf(“\n“);
}
fclose(fp);
}
t_start = MPI_Wtime();
for(i = 0; i < m; i++){
for(j = 0; j < m; j++){
p1 = j*l p2 = i*l;
//printf(“%d is sending.\n“i*m+j);
for(x = 0; x < l; x++){
for(y = 0;y < l; y++){
tmp[x*l+y] = first[p1][p2];
p2++;
//printf(“%2d “tmp[x*l+y]);
}
//printf(“\n“);
p1++;
p2 = i*l;
}
if(i!=0 || j!=0)
MPI_Send(tmpl*lMPI_INTi*m+ji*m+jMPI_COMM_WORLD);
}
}
}
//所有进程给主进程发自己转置部分的数组
else{ //printf(“l = %d“l);
MPI_Recv(tmpl*lMPI_INT0my_rankMPI_COMM_WORLD&status);
int t;
for(i = 0; i < l; i++){
for(j = i+1; j < l; j++){
t = tmp[i*l+j];
tmp[i*l+j] = tmp[j*l+i];
tmp[j*l+i] = t;
}
}
MPI_Send(tmpl*lMPI_INT0my_rankMPI_COMM_WORLD);
}
if(my_rank==0){
for(i = 0; i < l; i++){
for(j = 0; j < l; j++){
ans[i][j] = first[j][i];
}
}
for(i = 0; i < m; i++){
for(j = 0; j < m; j++){
if(i!=0 || j!=0){
MPI_Recv(tmpl*lMPI_INTi*m+ji*m+jMPI_COMM_WORLD&status);
for(x = 0; x < l; x++){
for(y = 0; y < l; y++){
ans[i*l+x][j*l+y] = tmp[x*l+y];
}
}
}
}
}
}
t_end = MPI_Wtime();
if (my_rank==0)
{
printf(“Matrix order:%d Time cost:%lf\n“nt_end-t_start);
}
free(tmp);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-04-18 23:57 实验三\
文件 17324 2017-04-07 16:51 实验三\hw3
文件 3025 2017-04-18 23:57 实验三\hw3.cpp
文件 1130 2017-04-07 08:44 实验三\hw3.o46502
文件 1130 2017-04-07 08:45 实验三\hw3.o46506
文件 1130 2017-04-07 08:45 实验三\hw3.o46508
文件 1130 2017-04-07 09:36 实验三\hw3.o46535
文件 1835 2017-04-07 16:51 实验三\t3.pbs
文件 612165 2017-04-20 20:54 实验报告三.pdf
相关资源
- 触摸屏TPC7063E与S7 300 PLC之间MPI通信实
- Exact Conditions of Blow-up and Global Existen
- doneex xcell compiler 2.1.2.9绿色汉化版(
- 山东大学编译原理PL/0语言 compiler实验
- 三维可压缩流场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
- synopsys公司的Design Compiler license生成工
- 综合与Design Compiler
- Design Compiler student guide-学习手册
- OpenCV 1.0.0 patch for ffmpeg errors
- delphi反编译工具 Decompiler v1.1.0.194
- Advanced Compiler Design and Implementation (高
- Linux英文原版图书系列].OREILLY-High_Pe
- Design Compiler入门教程
- Design Compiler® User Guide Version O-2018.06
- mpich2-1.4.1p1-win-ia32.msi
- Compiler Construction: Principles and Practice
- mpich2-1.3.2p1-win-ia32.msi MPICH2 安装版 及
- mpich-3.1.tar.gz
- Intel_Visual_Fortran_Compiler10.1破解文件
- 编译原理 第二版 刘坚 课后习题答案
- Crafting a compiler120633
- Design compiler 经典入门教程
评论
共有 条评论