MPI系​​列的主要功能 [英] MPI serial main function

查看:129
本文介绍了MPI系​​列的主要功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个pretty基本MPI的问题,但我不能换我的头周围。我有一个调用使用MPI另一个函数main函数。我想主要功能以串行执行,以及其它功能来并行执行。我的code是这样的:

This is a pretty basic MPI question, but I can't wrap my head around it. I have a main function that calls another function that uses MPI. I want the main function to execute in serial, and the other function to execute in parallel. My code is like this:

int main (int argc, char *argv[])
{
    //some serial code goes here
    parallel_function(arg1, arg2);
    //some more serial code goes here
}

void parallel_function(int arg1, int arg2)
{
    //init MPI and do some stuff in parallel
    MPI_Init(NULL, NULL);
    MPI_Comm_size(MPI_COMM_WORLD, &p);
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
    //now do some parallel stuff
    //....
    //finalize to end MPI??
    MPI_Finalize();
}

我的code运行良好,并得到预期的输出,但问题是,主要的功能也正在单独的进程运行,所以串行code执行不止一次。我不知道它是如何运行多次,因为我还没有叫MPI_INIT,但(如果我主要的printf之前,我打电话parallel_function,我见多发的printf的)

My code runs fine and gets the expected output, but the issue is that the main function is also being run in separate processes and so the serial code executes more than once. I don't know how it's running multiple times, because I haven't even called MPI_Init yet (if I printf in main before I call parallel_function, I see multiple printf's)

如何才能停止我的程序并行运行我完成后?

How can I stop my program running in parallel after I'm done?

感谢您的任何答复!

推荐答案

看一看这个答案

短篇小说: MPI_INIT MPI_Finalize 不标记并行处理的开始和结束。 MPI进程的全部并行运行。

Short story: MPI_Init and MPI_Finalize do not mark the beginning and end of parallel processing. MPI processes run in parallel in their entirety.

这篇关于MPI系​​列的主要功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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