Biggod586 2022-11-12 20:24 采纳率: 55.6%
浏览 37
已结题

MPI运行时进程报错?

写MPI-openMP的时候报错,显示进程执行出问题。如下图:

img

请问各位大lao是啥子原因哦

#include<stdio.h>
#include<math.h>
#include<mpi.h>
#include<stdlib.h>
#include<omp.h>
//int M,N;
//int myid;
int main(int argc,char* argv[])
{
    int M = 1000,N = 1000;
    int i,j,ii;//用来控制循环
    int tem;//暂时存储
    int myid;//存放MPI进程等级
    int local_result[M*N];//存放每一个线程的矩阵
    int local_Matrix_one[M*N];
    int result_Matrix[M][N];
    int Matrix_one[M*N];
    int Matrix_two[M*N];
    int local_M;
    //nem an matrix
    for(i = 0;i<M;i++)
        for(j = 0;j<N;j++)
            Matrix_one[i*N+j] = rand()%10;
    for (j = 0;j<N;j++)
        for(i = 0;i<M;i++)
            Matrix_two[i*N+j] = rand()%10;
    //    
    //MPI_Init(&argc,&argv);
    //MPI_Comm_rank(MPI_COMM_WORLD,&myid);
    
    //散播操作,将进程0的mtrix——one分割给
    MPI_Scatter(Matrix_one,local_M*N,MPI_INT,local_Matrix_one,local_M*N,MPI_INT,0,MPI_COMM_WORLD);
    //广播原语
    MPI_Bcast(Matrix_two,M*N,MPI_INT,0,MPI_COMM_WORLD);
    
    
    //OpenMP的计算部分
    
    #pragma omp parallel
    {
        int kk;
        #pragma omp for
        for(ii = 0;ii<local_M;ii++)
        {
            for(int jj = 0;jj<M;jj++)
            {
                tem = 0;
                //int kk;
                for(kk = 0;kk<N;kk++)
                    tem += local_Matrix_one[ii*M+kk]*Matrix_two[jj*M+kk];
                local_result[ii*M+kk] = tem;
            }
        }
    }
    
    
    //MPI聚集结果
    MPI_Gather(local_result,local_M*N,MPI_INT,result_Matrix,local_M*N,MPI_INT,0,MPI_COMM_WORLD);
    if(myid == 0)
    {
        printf("Process 0 gather from other Process:\n");
        for(i = 0;i<M;i++)
        {
            for(j = 0;j<N;j++)
                printf("%d\t",result_Matrix[i][j]);
            
            printf("\n");
        }
    }
    
    MPI_Finalize();
    return 0;
    
    
}

  • 写回答

2条回答 默认 最新

  • 地球屋里老师 2022-11-13 17:19
    关注

    你这串行都跑不了吧。local_M 没有值

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 11月22日
  • 已采纳回答 11月14日
  • 创建了问题 11月12日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效