“原子”在MPI中调用cout [英] An "atomic" call to cout in MPI

查看:308
本文介绍了“原子”在MPI中调用cout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感兴趣的是,在OpenMPI中是否有一个命令或技术,有一个原子调用来写入stdout(或者,就此而言,任何流)。



我注意到的是,在执行MPI程序期间,对cout(或其他流)的写入调用可能会变得混乱,因为每个proc可能会写入到某段代码。当报告结果时,可以通过多个过程写入一行,使问题混乱。所以2个不同的proc可能会做这样的事情:

  // Proc 10  - 结果计算在上面
// result1 = 10
// result2 = 11
cout<< 我的结果是:< result1<< < resul2<< endl;

和:

  // Proc 20  - 计算结果的结果
// result1 = 20
// result2 = 21
cout< 我的结果是:< result1<< < resul2<< endl;

但结果可能是:

 我的结果是:20我的结果是:10 11 21 

我正在寻找的东西像一个阻塞或原子cout(以及可能写入其他流,如文件流)。所以一旦我开始写一个cout,它阻塞直到语句结束,或直到endl或刷新流发出。如果是这种情况,我将保证这两行将是分开的(但是,我仍然不知道哪一行会先到):

 我的结果是:20 21 
我的结果是:10 11


<使用标准的i / o流(使用C语言的stdout和stdin或C ++中的cout和cin)不是MPI的最好的部分(OpenMPI实现MPI )。有一些幻灯片: http://www.csee .wvu.edu /〜donm / classes / cs591x / notes / io1.ppt 和Slide 10有一个解决方案。
(或第8.1章使用cop的所有I / O在排名为0的过程中执行。

从其他进程输出一些数据,只是发送具有这个数据的MPI消息为秩0.


I am interested in whether there is a command or a technique within OpenMPI to have an atomic call to write to stdout (or, for that matter, any stream).

What I have noticed is that during the execution of MPI programs, calls to write to cout (or other streams) can become confusing, as each proc may write whenever it gets to a certain section of code. When reporting results, a line can be written to by several procs, confusing the issue. So 2 different procs might do something like this:

//Proc 10 - results calculated somewhere above
//  result1 = 10
//  result2 = 11
cout << "My results are: " << result1 << " " << resul2 << endl;

and:

//Proc 20 - results calculated somewhere above
//  result1 = 20
//  result2 = 21
cout << "My results are: " << result1 << " " << resul2 << endl;

But the result might be:

My results are: 20 My results are: 10 11 21

What I'm looking for is something like a "blocking" or atomic cout (as well as possibly writing to other streams, such as file streams). So once I start writing a to cout, it blocks until the end of the statement, or until endl or a flush to the stream is issued. If this were the case, I'd be guaranteed that the 2 lines would be separate (but, of course, I still wouldn't know which line would come first):

My results are: 20 21
My results are: 10 11

解决方案

Working with standard i/o streams (stdout and stdin in terms of C language or cout and cin in C++) is not the best part of MPI (OpenMPI implements MPI). There are some slides about this: http://www.csee.wvu.edu/~donm/classes/cs591x/notes/io1.ppt and Slide 10 has a solution. (or chapter 8.1 of the book "Parallel Programming With Mpi By P. S. Pacheco")

Do all your I/O with cout in the process with rank 0. If you want to output some data from other processes, just send MPI message with this data to rank 0.

这篇关于“原子”在MPI中调用cout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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