【问题标题】:MPI_Comm_rank always writes 0MPI_Comm_rank 总是写 0
【发布时间】:2012-11-14 14:36:18
【问题描述】:

我怎样才能得到预期的输出

rank 0
size 2
rank 1
size 2

或者这些行的一些排列?

ranktest.c

#include <mpi.h>
#include <stdio.h>
int main(int argc, char *argv[]){
    MPI_Init(NULL, NULL);
    int world_rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
    int world_size;
    MPI_Comm_size(MPI_COMM_WORLD, &world_size);
    printf("rank %d\n", world_rank);
    printf("size %d\n", world_size);
    MPI_Finalize();
    return 0;
}

编译运行

tsbertalan@hustlenbustle:~$ mpicc ranktest.c
tsbertalan@hustlenbustle:~$ mpirun -np 2 ./a.out 
rank 0
size 1
rank 0
size 1

在不同的主机上:

tsbertalan@stamp:~$ mpicc ranktest.c
tsbertalan@stamp:~$ mpirun -np 2 ./a.out 
rank 0
size 2
rank 1
size 2

我试过了

tsbertalan@hustlenbustle:~$ sudo aptitude reinstall openmpi-bin libopenmpi-dev

但没有任何改变。 /etc/openmpi/openmpi-default-hostfile 和 /etc/openmpi/openmpi-mca-params.conf 在两台主机上都只包含 cmets。这里可能有什么不同?

更改为MPI_Init(&amp;argc, &amp;argv)int main() 也无济于事。

真正的问题,感谢 user3469194:

linuxmint@linuxmint ~ $ sudo aptitude remove libopenmpi-dev mpich2
linuxmint@linuxmint ~ $ sudo aptitude install libmpich2-dev openmpi-bin
linuxmint@linuxmint ~ $ mpicc ranktest.c
linuxmint@linuxmint ~ $ mpirun -np 2 ./a.out
rank 0
size 1
rank 0
size 1
linuxmint@linuxmint ~ $ sudo aptitude remove libmpich2-dev openmpi-bin
linuxmint@linuxmint ~ $ sudo aptitude install libopenmpi-dev mpich2
linuxmint@linuxmint ~ $ mpicc ranktest.c
linuxmint@linuxmint ~ $ mpirun -np 2 ./a.out
[linuxmint:16539] [[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file ../../../../../../orte/mca/ess/singleton/ess_singleton_module.c at line 357

(还有更多)

对一些建议的回应: (参见this github repo,2012 年 12 月 1 日提交。)

尝试在 MPI_Init() 之前移动 world_rank 和 world_size 的定义,它会改变什么吗?

当然,这不太好用:

tsbertalan@perrin:~/svn/524hw4$ git checkout 7b5e229 ranktest.c
(reverse-i-search)`clean': tsbertalan@hustlenbustle:~/Documents/School/12fall2012/524apc524/hw/hw4$ make ^Cean && make ranktest && mpirun -np 2 ranktest
tsbertalan@perrin:~/svn/524hw4$ make clean && make ranktest && mpirun -np 2 ranktest
rm -f heat_serial heat_omp heat_mpi heat_serial_O* ranktest
mpicc ranktest.c -o ranktest
*** An error occurred in MPI_Comm_rank
*** before MPI was initialized
*** MPI_ERRORS_ARE_FATAL (your MPI job will now abort)
[perrin:15206] Abort before MPI_INIT completed successfully; not able to guarantee that all other processes were killed!
*** An error occurred in MPI_Comm_rank
*** before MPI was initialized
*** MPI_ERRORS_ARE_FATAL (your MPI job will now abort)
[perrin:15207] Abort before MPI_INIT completed successfully; not able to guarantee that all other processes were killed!
tsbertalan@perrin:~/svn/524hw4$ git checkout HEAD ranktest.c

或者,在我的家用电脑上:

tsbertalan@hustlenbustle:~/Documents/School/12fall2012/524apc524/hw/hw4$ git checkout 7b5e229 ranktest.c
tsbertalan@hustlenbustle:~/Documents/School/12fall2012/524apc524/hw/hw4$ vim ranktest.c 
tsbertalan@hustlenbustle:~/Documents/School/12fall2012/524apc524/hw/hw4$ make clean && make ranktest && mpirun -np 2 ranktest
rm -f heat_serial heat_omp heat_mpi heat_serial_O* ranktest
mpicc ranktest.c -o ranktest
Attempting to use an MPI routine before initializing MPICH
Attempting to use an MPI routine before initializing MPICH
tsbertalan@hustlenbustle:~/Documents/School/12fall2012/524apc524/hw/hw4$ git checkout HEAD ranktest.c

这几乎总是一个使用另一个 MPI 的 MPI 编译的程序运行的问题。第一台机器(hustlenbustle)是否也安装了 mpich2?事物出现在路径的什么位置?特别是which mpiccwhich mpirun的结果是什么?

每次尝试之前,我都会在每台计算机上重新编译。为此,我继续使用made a make target。但是,根据要求:

tsbertalan@hustlenbustle:~$ which mpicc
/usr/bin/mpicc
tsbertalan@hustlenbustle:~$ which mpirun
/usr/bin/mpirun

tsbertalan@perrin:~/svn/524hw4$ which mpicc
/usr/bin/mpicc
tsbertalan@perrin:~/svn/524hw4$ which mpirun
/usr/bin/mpirun

而且,对于 shiggles,这里是一些 aptitude 搜索的输出 hnbperrin。让我知道我是否应该搜索其他内容。

在 Open MPI 下,以下命令应打印出版本:mpirun -V。如果它没有打印出mpiexec (OpenRTE) 1.x.x.,那么您的运行时间可能不匹配。

tsbertalan@hustlenbustle:~$ mpirun -V
mpirun (Open MPI) 1.4.3

tsbertalan@perrin:~/svn/524hw4$ mpirun -V
mpirun (Open MPI) 1.4.1

但是,我正在为每个测试重新编译。

也许sudo aptitude reinstall SOMETHING 可能有帮助?

【问题讨论】:

  • 尝试将world_rankworld_size的定义移到MPI_Init()之前,有什么改变吗?
  • 这几乎总是一个运行使用一个 MPI 编译的程序和另一个 MPIrun 的问题。第一台机器(hustlenbustle)是否也安装了 mpich2?事物出现在路径的什么位置?特别是哪个mpicc和哪个mpirun的结果是什么?
  • 在 Open MPI 下,以下命令应打印出版本:mpirun -V。如果它不打印mpiexec (OpenRTE) 1.x.x.,那么您可能有运行时间不匹配。
  • 我回应了上面的这些建议。人力资源管理系统。即将尝试在hnb上重新安装一些东西。 ...重新安装 mpich2 没有帮助。

标签: c openmpi mpich


【解决方案1】:

在我计算机上的 mpic.c 版本中找到了此代码(当我安装了一个带有 mpi 的新软件包时,这给我带来了麻烦)。你的电脑上好像有这样的东西,而另一台主机的版本是正确的。

int MPI_Comm_rank( MPI_Comm comm, int *rank)
{
  *rank=0;
  return 0;
}

如您所见,rank 始终设置为 0(类似的 size 函数可能将变量设置为 1)。

【讨论】:

    【解决方案2】:

    我也有这个问题。问题是 mpicc 是 OpenMPI(要看到这个,只需运行 mpicc -v),而 mpirun 是 MPICH2(mpirun -V)。我只是通过卸载 MPICH2 解决了它。

    【讨论】:

    • 这没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方发表评论 - 您可以随时评论自己的帖子,一旦您有足够的reputation,您就可以comment on any post
    • @matthias 实际上,老实说,没有真正的问题。我的错;我会相应地编辑它。这似乎实际上是我要问的真正答案,并且在使用 Linux Mint 16 的 virtualbox 中进行的测试确认 libmich2-dev/openmpi-bin 组合是问题所在;不是 libopenmpi-dev/mpich2,它只是失败了。如果 user34 可以确认它是第一个组合而不是第二个组合,我可以将其标记为接受的答案。
    猜你喜欢
    • 2014-07-15
    • 2012-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多