Atomic cout call in MPI

I am wondering if there is a command or method in OpenMPI to have an atomic call to write to stdout (or, for that matter, any thread).

I noticed that when you run MPI programs, write to cout calls (or other threads) can get confused, since every proc can write every time it gets to a particular section of code. When presenting the results, a string can be written in several procedures, which confuses the problem. So 2 different procs can 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 could be:

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

- "" cout ( , , , ). , cout, , endl flush . , , (, , , ):

My results are: 20 21
My results are: 10 11
+5
1

- (stdout stdin C cout cin ++) - MPI (OpenMPI MPI). : http://www.csee.wvu.edu/~donm/classes/cs591x/notes/io1.ppt, Slide 10 . ( 8.1 " Mpi P. P. Pacheco" )

/ cout 0. , MPI 0.

+3

All Articles