MPI_Bcast在if语句? [英] MPI_Bcast in an if statement?

查看:489
本文介绍了MPI_Bcast在if语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与MPI实验和我一直得到这个错误,当我在命令行中运行它通过的mpirun。

<$p$p><$c$c>----------------------------------------------------------------------------------------------
的mpirun注意到,工作中断,但没有信息,以流程
导致这种情况。
-------------------------------------------------- --------------------------------------------

我不知道为什么,但因为其他MPI程序运行完全正常。

下面是我的code。

 的#include&LT;&stdio.h中GT;
#包括LT&;&mpi.h GT;INT FUNC(INT NUM){
    INT排名;
    MPI_Comm_rank(MPI_COMM_WORLD,&安培;等级);
    如果(NUM == 0){
        NUM = 5;
        MPI_Bcast(试验#1,MPI_INT,职级,MPI_COMM_WORLD);
    }
    返回NUM;
}INT主(INT ARGC,字符** argv的){
    INT等级,尺寸;
    MPI_INIT(安培; ARGC,&安培; argv的);
    MPI_Comm_rank(MPI_COMM_WORLD,&安培;等级);
    MPI_Comm_size(MPI_COMM_WORLD,&安培;大小);
    的printf(在处理器%D,FUNC返回%d个\\ N,等级,FUNC(职级));
    MPI_Finalize();
    返回0;
}

程序还在给我同样的错误。是一个if语句只是没有有效的内MPI_Bcast?如果您尝试广播,当你不是根是否仍然有效?


解决方案

MPI_Bcast 我看到它的任何引用文件中的签名是 INT MPI_Bcast(无效*缓冲区,诠释计数,MPI_Datatype数据类型,INT根,MPI_Comm COMM)。但是,您只传递四个参数,看起来像你忘了无论是对第一个或第二个参数。

什么是 NUM 在你的情况,什么是您的缓冲区?这个问题的答案可能会解决你的问题,但我也不能确定为什么你的code编译连。如果 NUM 是要广播,尝试什么,如果 MPI_Bcast(试验#1,MPI_INT,职级,MPI_COMM_WORLD)你的作品。

还有一种,非常严重的独立问题。你有一些 INT排名; 在栈上,并通过这 MPI_Bcast 之前,你曾经初始化。是谁发出? 0 ,或 INT排名= 0正确初始化p>

排名待定值几乎肯定是对你的工作中止,因为实例将随机发送或接收的原因。

I am experimenting with MPI and I kept getting this error when I was running it through mpirun on the command line.

----------------------------------------------------------------------------------------------
mpirun noticed that the job aborted, but has no info as to the process
that caused that situation.
----------------------------------------------------------------------------------------------

I'm not sure why though, because other mpi programs run perfectly fine.

Here is my code.

#include <stdio.h>
#include <mpi.h>

int func(int num){
    int rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    if (num == 0){
        num = 5;
        MPI_Bcast(&num, 1, MPI_INT, rank, MPI_COMM_WORLD);
    }
    return num;
}

int main(int argc, char **argv){
    int rank, size;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    printf("On processor %d, func returns %d\n", rank, func(rank));
    MPI_Finalize();
    return 0;
}

the program is still giving me the same error. Is MPI_Bcast within an if statement just not valid? Does it still work if you try broadcasting when you're not the root?

解决方案

The signature of MPI_Bcast as I see it in any reference document is int MPI_Bcast(void* buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm). However, you are passing only four arguments, and looks like you forgot either about the first or second argument.

What is num in your case, and what is your buffer? The answer to this will likely resolve your question, but I am also not sure why your code even compiles. If num is what you want to broadcast, try if MPI_Bcast(& num, 1, MPI_INT, rank, MPI_COMM_WORLD) works for you.

There is another, very serious independent problem. You have some int rank; on your stack and pass this to MPI_Bcast before you ever initialize it. Who is sending? If root is, you could just as well pass 0, or initialize properly by int rank = 0;.

Undetermined values for rank are almost certainly the reason for your job to abort because instances will be randomly sending or receiving.

这篇关于MPI_Bcast在if语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆