首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Openmpi程序挂起

Openmpi程序挂起
EN

Stack Overflow用户
提问于 2018-03-23 07:38:50
回答 1查看 128关注 0票数 0

在运行我的openmpi程序时,我在gdb中得到了这个。程序只是挂在recv上,我真的不明白为什么。我到处都找过了,但似乎找不到任何相似的东西。

代码语言:javascript
复制
Attaching to process 29704
[New LWP 29709]
where[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007f107c333827 in sched_yield () at ../sysdeps/unix/syscall-template.S:84
84  ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) where
#0  0x00007f107c333827 in sched_yield ()
    at ../sysdeps/unix/syscall-template.S:84
#1  0x00007f106f07d955 in mca_pml_ob1_recv ()
   from /usr/lib/openmpi/lib/openmpi/mca_pml_ob1.so
#2  0x00007f107cc1061c in PMPI_Recv () from /usr/lib/libmpi.so.12
#3  0x0000000000408740 in solve_it (k=4, n=5) at MPI_pythagorean.cc:24
#4  0x000000000040893b in main (argc=2, argv=0x7ffec018c088)
    at MPI_pythagorean.cc:61

我使用mpic++ -g MPI_pythagorean.cc编译它,并使用mpiexec -np 5运行它。/a.out500

以下是代码

代码语言:javascript
复制
#include <iostream>
#include <cstdlib>
#include <mpi.h>
#include <stdio.h>
using namespace std;

int solve_it(int k, int n) {
  int m;

  MPI_Recv(&m,1,MPI_INT,0,0,MPI_COMM_WORLD,NULL);
  int count=0;
  for (int x=1+k;x<=m;x+=n) {
    for (int y=x+1;y<=m;y++) {
      for (int z=y+1;z<=m;z++) {

    long long x1 = x;
    long long y1 = y;
    long long z1 = z;
    if (x1*x1 + y1*y1 == z1*z1) {
      count++;
    }
      }
    }
  }
  MPI_Send(&count,1,MPI_INT,0,0,MPI_COMM_WORLD);
  return 0;
}


int main(int argc, char *argv[]) {
  int m;
  int k;
  int n;
  if (argc !=2) {
    cout << "Needs at least one argument " << endl;
    exit(-1);
  } else {
    m =atoi(argv[1]);
    cout << m << endl;
  }
  cout << argc << endl;
  cout << "Hello1" << endl; 
  MPI_Init(&argc,&argv);
  cout << "Hello" << endl;
  MPI_Comm_size(MPI_COMM_WORLD,&n);
  MPI_Comm_rank(MPI_COMM_WORLD,&k);
  int res = solve_it(k,n);
  if (k==0) {
    // Send m to everyone
    for (int i=0;i<n;i++) {
      MPI_Send(&m,1,MPI_INT,i,0,MPI_COMM_WORLD);
    }
    int sum=0;
    int res=0;
    // Get the answer from everyone
    for (int i=0;i<n;i++) {
      MPI_Recv(&res,1,MPI_INT,i,0,MPI_COMM_WORLD,NULL);
      sum+=res;
    }
    cout << sum << endl;
  }
  MPI_Finalize();
}

任何帮助都会被提及

EN

回答 1

Stack Overflow用户

发布于 2018-03-23 10:59:56

等级0挂起,因为solve_it() MPI_Recv()MPI_Send()尚未被main函数调用。

也就是说,MPI的方式是:

  • MPI_Bcast(&m, ...)
  • solve_it(...)
  • MPI_Reduce(&count, ...)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49440194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档