gpt4 book ai didi

c - MPI_Comm_rank 总是写 0

转载 作者:太空宇宙 更新时间:2023-11-04 02:59:49 24 4
gpt4 key购买 nike

如何获得预期的输出

rank 0
size 2
rank 1
size 2

或者这些行的一些排列?

排名测试.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 只包含两台主机上的注释。这里可能有什么不同?

更改为 MPI_Init(&argc, &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 日提交。)

Try moving the definitions of world_rank and world_size before MPI_Init(), does it change anything?

当然,这不是很好:

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

This is almost always an issue of running a program compiled with one MPI with another's mpirun. Does the first machine (hustlenbustle) also have mpich2 installed? Where do things appear on the path? In particular, what is the result of which mpicc and which 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,这里是对 hnb 的一些 aptitude 搜索的输出和 perrin .如果我应该搜索其他内容,请告诉我。

Under Open MPI the following command should print out the version: mpirun -V. If it doesn't print mpiexec (OpenRTE) 1.x.x. then you might have a mismatch of the run-times.

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 可能有帮助?

最佳答案

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

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

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

关于c - MPI_Comm_rank 总是写 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13380869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com