矩阵乘法
本实例实现C = AxB
设计模式
采用主从模式,即一个主进程负责收发数据,其余从进程负责计算并反馈结果。
代码
//
// Created by zhangx on 2022/9/15.
//
#include <ctime>
#include "iostream"
#include "mpi.h"
#include "stdio.h"
#include "math.h"
using namespace std;
// A(N,M) P(M,P)
const int N = 4;
const int M = 4;
const int P = 3;
//打印矩阵
void disp(double *x,int n,int m){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++)
printf("%10.2f",*(x+i*m+j));
puts(" ");
}
}
int main(){
int rank,numprocs;
double A[N][M],B[M][P],C[N