得到的openmpi等待永远 [英] OpenMPI gets waiting for ever
问题描述
当我执行此$ C $词都没有反应,它就会永远的等待,进程1将数据发送到根进程,但根本过程中不接受它(或几乎这就是我认为)。
when i execute this code i have no response, it gets waiting for ever, process 1 is sending data to the root process but the root process doesn't receive it (or almost that is what i think).
#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"
void my_parallel_function(int v[], int size, int rank)
{
MPI_Status status;
int i;
if(rank==0)
{
MPI_Send(&v[0], 10, MPI_INT, 1, 1, MPI_COMM_WORLD);
}
else
{
MPI_Recv(&v[0], 10, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD,&status);
for(i=0;i<10;i++)
{
//change the value
v[i] = i;
//printf("hola soy nodo: %d\n", i);
}
MPI_Send(&v[0], 10, MPI_INT, 0, 2, MPI_COMM_WORLD);
}
if(rank==0)
{
MPI_Recv(&v[0], 10, MPI_INT, MPI_ANY_SOURCE, 2, MPI_COMM_WORLD,&status);
for(i=1;i<size;i++)
{
printf("\nvalue of item %d: %d\n", i, v[i]);
}
}
}
void simpleFunction()
{
printf("Hi i am a simple function\n");
}
int main(int argc, char *argv[])
{
int rank, size;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Status status;
int vect[10];
int op=1;
while(op != 0)
{
//system("clear");
printf("Welcome to example program!\n\n");
printf("\t1.- Call Parallel Function\n");
printf("\t2.- Call another Function\n");
printf("\t0.- Exit\n\t");
printf("\n\n\tEnter option:");
scanf("%d", &op);
switch(op)
{
case 1:
my_parallel_function(vect, size, rank);
printf("Parallel function called successfully\n\n");
break;
case 2:
simpleFunction();
printf("Function called successfully\n\n");
break;
}
}
MPI_Finalize();
return 0;
}
我与-np 2执行
I am executing with -np 2
我觉得这是不沃金,因为它应该:
MPI_RECV(安培; v [0],10,MPI_INT,MPI_ANY_SOURCE,2,MPI_COMM_WORLD,&安培;状态);
I think this is not woking as it should:
MPI_Recv(&v[0], 10, MPI_INT, MPI_ANY_SOURCE, 2, MPI_COMM_WORLD,&status);
你知道吗?非常感谢你。
Any idea? thank you very much.
编辑:但是,当我删除,如果(排名== 0)我得到的所有的I / O从属进程,这意味着吨次菜单打印。我是新手的openmpi,如何解决这个问题?
非常感谢你!
推荐答案
要实现MPI程序菜单的正确方法是:
The proper way to implement a menu in an MPI program is:
while (op != 0)
{
if (rank == 0)
{
printf("Welcome to example program!\n\n");
printf("\t1.- Call Parallel Function\n");
printf("\t2.- Call another Function\n");
printf("\t0.- Exit\n\t");
printf("\n\n\tEnter option:");
scanf("%d", &op);
}
// Broadcast the user's choice to all other ranks
MPI_Bcast(&op, MPI_INT, 1, 0, MPI_COMM_WORLD);
switch(op)
{
case 1:
my_parallel_function(vect, size, rank);
MPI_Barrier(MPI_COMM_WORLD);
if (rank == 0)
printf("Parallel function called successfully\n\n");
break;
case 2:
simpleFunction();
MPI_Barrier(MPI_COMM_WORLD);
if (rank == 0)
printf("Function called successfully\n\n");
break;
}
}
这两个障碍不是绝对必要的 - 他们只是确保该电话中的所有队伍已经返回
The two barriers are not absolutely necessary - they just make sure that the calls have returned in all ranks.
请注意,允许等级0从标准输入读的是不会由MPI标准保证和计划,做这样那样的I / O不可移植。这就是说,大多数现有的MPI实现确实重定向标准输入和等级0的输出 mpiexec的
/ 的mpirun $的标准输入和输出C $ C>。
Note that allowing rank 0 to read from the standard input is not guaranteed by the MPI standard and programs that do such kind of I/O are not portable. That said, most existing MPI implementations does indeed redirect the standard input and output of rank 0 to the standard input and output of mpiexec
/mpirun
.
这篇关于得到的openmpi等待永远的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!