Discussion:
mpirun and console output
(too old to reply)
Stefan Kuhne
2009-07-15 10:42:56 UTC
Permalink
Hi,

i have build a little mpi program which print a text to console and read
an number. But i don't get the text.

Code:
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);


if(myid == 0) {
printf("Enter the number of intervals: (0 quits) ");
scanf("%f", &n);
}

MPI_Bcast(&n, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);

Call:
***@Ubuntu-8-04:~/pi$ mpirun --mca btl ^openib --hostfile ../hostfile pi
20000
Enter the number of intervals: (0 quits) pi is approxomantely
3.1415926505377429, Error is 3.0520501682e-09
***@Ubuntu-8-04:~/pi$

Without mpirun:
***@Ubuntu-8-04:~/pi$ ./pi
libibverbs: Fatal: couldn't read uverbs ABI version.
--------------------------------------------------------------------------
[0,0,0]: OpenIB on host Ubuntu-8-04 was unable to find any HCAs.
Another transport will be used instead, although this may result in
lower performance.
--------------------------------------------------------------------------
Enter the number of intervals: (0 quits) 2000
pi is approxomantely 3.1415926487068111, Error is 4.8829820187e-09
***@Ubuntu-8-04:~/pi$

Regards,
Stefan Kuhne
Michael Hofmann
2009-07-16 08:50:47 UTC
Permalink
Post by Stefan Kuhne
Hi,
i have build a little mpi program which print a text to console and read
an number. But i don't get the text.
You "don't get the text"?
Post by Stefan Kuhne
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
if(myid == 0) {
printf("Enter the number of intervals: (0 quits) ");
scanf("%f", &n);
^^^^^^^^

"%lf" is required for double values ("%f" is for floats)!


Michael
Stefan Kuhne
2009-07-16 09:09:36 UTC
Permalink
Hi.
Post by Michael Hofmann
Post by Stefan Kuhne
i have build a little mpi program which print a text to console and read
an number. But i don't get the text.
You "don't get the text"?
Yes, the output of "printf".
Post by Michael Hofmann
Post by Stefan Kuhne
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
if(myid == 0) {
printf("Enter the number of intervals: (0 quits) ");
scanf("%f", &n);
^^^^^^^^
"%lf" is required for double values ("%f" is for floats)!
With "%lf" and "%d" by int i get the same result, no text :(.

Stefan Kuhne
Michael Hofmann
2009-07-16 10:50:14 UTC
Permalink
Post by Stefan Kuhne
Hi.
Post by Michael Hofmann
Post by Stefan Kuhne
i have build a little mpi program which print a text to console and read
an number. But i don't get the text.
You "don't get the text"?
Yes, the output of "printf".
20000
Enter the number of intervals: (0 quits) pi is approxomantely
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Post by Stefan Kuhne
3.1415926505377429, Error is 3.0520501682e-09
libibverbs: Fatal: couldn't read uverbs ABI version.
--------------------------------------------------------------------------
[0,0,0]: OpenIB on host Ubuntu-8-04 was unable to find any HCAs.
Another transport will be used instead, although this may result in
lower performance.
--------------------------------------------------------------------------
Enter the number of intervals: (0 quits) 2000
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Post by Stefan Kuhne
pi is approxomantely 3.1415926487068111, Error is 4.8829820187e-09
However, with (this) mpirun the ouput appears a little bit later.
Propably, because the stdout stream is buffered somewhere. Often, a
newline ("\n") forces the flushing of the output stream. Or you call
"fflush(stdout)" after the printf call.


Michael
Stefan Kuhne
2009-07-16 13:57:43 UTC
Permalink
Michael Hofmann schrieb:

Hello,
Post by Michael Hofmann
However, with (this) mpirun the ouput appears a little bit later.
Propably, because the stdout stream is buffered somewhere. Often, a
newline ("\n") forces the flushing of the output stream. Or you call
"fflush(stdout)" after the printf call.
thank you very much.
It is so easy ...

Stefan Kuhne

Loading...