Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MPI with cout

277 views
Skip to first unread message

Stefan Kuhne

unread,
Dec 3, 2009, 7:03:50 AM12/3/09
to
Hello,

i'll port my C code to C++.
My hello.c has:
printf("Hier ist Job %2.0f von %2.d auf %s\n", (double) myrank, size,
cpu_name);

and hello.cpp:
cout << setw(2) << "Hier ist Job " << myrank << " von " << size << " auf
" << cpu_name << endl;

The C Output is correct put the C++ output is:
Hier ist Job Hier ist Job Hier ist Job Hier ist Job 3 von 4 auf 10 von 4
auf fb5


2 von 4 auf fb5-cluster-head

or somethink simular.

How can i get cout sync?

Regards,
Stefan Kuhne

Heiko Bauke

unread,
Dec 3, 2009, 7:40:40 AM12/3/09
to
Hi,

the MPI standard does not have any notion of C++ std::cout. Thus,
it's up to the MPI implementation how it deals with reading from and
writing from standard streams. A valid MPI implementation may
even suppress reading from and writing from standard streams completely.
Therefore, I would suggest to try another MPI implementation.


Heiko

--
-- Wurst ist eine Götterspeise. Denn nur Gott weiß, was drin ist.
-- (Jean Paul)
-- Cluster Computing @ http://www.clustercomputing.de
-- Heiko Bauke @ http://www.mpi-hd.mpg.de/personalhomes/bauke

Stefan Kuhne

unread,
Dec 3, 2009, 7:48:12 AM12/3/09
to
Heiko Bauke schrieb:

> the MPI standard does not have any notion of C++ std::cout. Thus,
> it's up to the MPI implementation how it deals with reading from and
> writing from standard streams. A valid MPI implementation may
> even suppress reading from and writing from standard streams completely.
> Therefore, I would suggest to try another MPI implementation.
>

But MPICH2 is the only one with MPE support.
So i have to use printf in this case.

Regards,
Stefan Kuhne

Heiko Bauke

unread,
Dec 3, 2009, 8:03:08 AM12/3/09
to
Hi,

On Thu, 03 Dec 2009 13:48:12 +0100
Stefan Kuhne <SK-P...@gmx.net> wrote:

> But MPICH2 is the only one with MPE support.

MPE is not included in MPI implementations except MPICH2. However, to my
knowledge, MPE should work with any MPI standard compliant MPI
implementation. Download the source of the latest version of MPICH2,
extract the folder mpich2-1.2.1/src/mpe2/ from the tar ball and read
the README file and the INSTALL file.


Heiko

--
--
-- Derjenige, der zum ersten Mal anstatt eines Speeres ein Schimpfwort
-- benutzte, war der Begründer der Zivilisation. (Jean Paul)

Stefan Kuhne

unread,
Dec 4, 2009, 3:47:57 AM12/4/09
to
Heiko Bauke schrieb:

Hello,

> On Thu, 03 Dec 2009 13:48:12 +0100
> Stefan Kuhne <SK-P...@gmx.net> wrote:
>
>> But MPICH2 is the only one with MPE support.
>
> MPE is not included in MPI implementations except MPICH2. However, to my
> knowledge, MPE should work with any MPI standard compliant MPI
> implementation. Download the source of the latest version of MPICH2,
> extract the folder mpich2-1.2.1/src/mpe2/ from the tar ball and read
> the README file and the INSTALL file.
>

openMPI runs with cout fine.

But when i try to build MPE2:

user@head:mpe2$ ./configure
--with-mpiinc=/opt/mpi/gcc/openmpi-1.3.3/include/
--with-mpilibs=/opt/mpi/gcc/openmpi-1.3.3/lib64/ --with-mpicc=
/opt/mpi/gcc/openmpi-1.3.3/bin/
configure: WARNING: you should use --build, --host, --target
configure: WARNING: invalid host type: /opt/mpi/gcc/openmpi-1.3.3/bin/
Configuring MPE Profiling System with
'--with-mpiinc=/opt/mpi/gcc/openmpi-1.3.3/include/'
'--with-mpilibs=/opt/mpi/gcc/openmpi-1.3.3/lib64/' '--with-mpicc='
'/opt/mpi/gcc/openmpi-1.3.3/bin/'
'build_alias=/opt/mpi/gcc/openmpi-1.3.3/bin/'
'host_alias=/opt/mpi/gcc/openmpi-1.3.3/bin/'
'target_alias=/opt/mpi/gcc/openmpi-1.3.3/bin/'
'CPPFLAGS=-I/usr/lib/jvm/java-6-sun-1.6.0.16/include/
-I/usr/lib/jvm/java-6-sun-1.6.0.16/include/linux/ -I/opt/include/
-I/opt/mpi/gcc/openmpi-1.3.3/include'
checking for current directory name... /home/sk/Cluster/lib/mpe2
checking gnumake... yes using --no-print-directory
checking BSD 4.4 make... no - whew
checking OSF V3 make... no
checking for virtual path format... VPATH
User supplied MPI implmentation (Good Luck!)
checking for leftover Makefiles in subpackages ... none
checking for /opt/mpi/gcc/openmpi-1.3.3/bin/-gcc... cc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking whether MPI_CC has been set ... cc
checking for /opt/mpi/gcc/openmpi-1.3.3/bin/-g77... f77
checking whether we are using the GNU Fortran 77 compiler... no
checking whether f77 accepts -g... no
checking whether MPI_F77 has been set ... f77
checking for the linkage of the supplied MPI C definitions ... no
configure: error: Cannot link with basic MPI C program!
Check your MPI include paths, MPI libraries and MPI CC compiler
user@head:mpe2$

But i can build and run mpi code with mpicc and mpirun.

Regards,
Stefan Kuhne

Stefan Kuhne

unread,
Dec 4, 2009, 4:02:23 AM12/4/09
to
Stefan Kuhne schrieb:

> But when i try to build MPE2:
>

> checking for the linkage of the supplied MPI C definitions ... no
> configure: error: Cannot link with basic MPI C program!
> Check your MPI include paths, MPI libraries and MPI CC compiler
> user@head:mpe2$
>

RTMF ...

With configure option from INSTALL configure runs.

Stefan Kuhne

Familie Bisseling

unread,
Dec 5, 2009, 10:16:35 AM12/5/09
to

You should not rely on any proper interleaving of lines printed by
different
MPI processes since this behavior is not guaranteed in any standard.

The only difference between cout and stdout that I am aware of might be an
additional buffering. You may try to adjust that buffering or force a
buffer
flush by calling ostream.flush() on cout after each line.

It may help to use stderr/cerr since that should be buffered line wise. But
if this works than you are still not on solid ground regarding the MPI
behavior.

Good luck!

--
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/

blm...@myrealbox.com

unread,
Dec 14, 2009, 3:02:40 AM12/14/09
to
In article <7npnonF...@mid.dfncis.de>,

Others have pointed out that the MPI standard makes no guarantees
about how -- or even whether(?) -- output to stdout will work.
Still, a workaround that might be worth trying is to assemble your
message in a string and then send the whole thing to stdout at once.
So your example would become:

ostringstream msgStream;
msgStream << setw(2) << "Hier ist Job " << myrank << " von "
<< size << " auf " << cpu_name << endl;
string msg = msgStream.str();
cout << msg;

No guarantees, but might help.

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.

Keith Thompson

unread,
Dec 28, 2009, 10:01:55 PM12/28/09
to

That's likely to work.

The C printf call is likely to assemble the output in memory, and then
print it in a single call to a lower-level routine. In the C++
"cout << foo << bar", on the other hand, each "<<" is a distinct
function call; the implementation is unlikely to assemble the chained
output calls into a single chunk of data.

But even so, there are no guarantees; printf *could* invoke multiple
output operations. If synchronization is important, you'll have to
find some way to do it explicitly.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Colin Paul Gloster

unread,
Feb 18, 2010, 7:21:59 AM2/18/10
to
On Sat, 5 Dec 2009, Bisseling sent:

|----------------------------------------------------------------------------|

|----------------------------------------------------------------------------|

In order to not rely on undefined behavior, it might be portable for
each process to write to a different file instead of to stdout (with
printf()) or stderr (with fprintf()).

You can look at a file while it is being written with
less filename
then press both Ctrl and C and then press F.

0 new messages