m***@gmail.com
2008-06-05 11:44:00 UTC
Hi,
I've a strange bug in one of my MPI programs and reduced it to this
snippet:
--- snip ---
#include <time.h>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
#undef SEEK_CUR
#undef SEEK_SET
#undef SEEK_END
#include <mpi.h>
using namespace MPI;
void io(int rank, char *s) {
FILE *f;
char buf[64];
time_t t;
sprintf(buf, "%02d.log", rank);
f = fopen(buf, "a");
t = time(0);
fprintf(f, "%s: %s\n\n\n", ctime(&t), s);
fclose(f);
}
int main(void) {
int value;
int rank;
Request r;
Init();
rank = COMM_WORLD.Get_rank();
if (rank == 0) {
io(rank, "Sending");
value = 42;
r = COMM_WORLD.Isend(&value, 1, INT, 1, 0);
io(rank, "Computing something");
unsigned int tick = 0;
while (++tick < 200000) {
printf("%g\r", sqrt(tick));
}
io(rank, "Finished.");
r.Wait();
} else {
io(rank, "Started");
io(rank, "Waiting for input");
// Waiting for input (blocking)
int tick = 0;
while (true) {
if (COMM_WORLD.Iprobe(ANY_SOURCE, ANY_TAG)) {
COMM_WORLD.Recv(&value, 1, INT, ANY_SOURCE, ANY_TAG);
break;
}
if (++tick % 1000000 == 0)
io(rank, "tick");
}
io(rank, "Received");
}
Finalize();
return EXIT_SUCCESS;
}
--- snap ---
If I understood non-blocking messages correct, process 1 should
receive the message *before* the computation in process 0 starts. But,
as my logs show
----------
(for process 0)
Thu Jun 5 13:31:30 2008
: Sending
Thu Jun 5 13:31:30 2008
: Computing something
Thu Jun 5 13:31:33 2008
: Finished.
---------
(for process 1)
Thu Jun 5 13:31:30 2008
: Started
Thu Jun 5 13:31:30 2008
: Waiting for input
Thu Jun 5 13:31:31 2008
: tick
Thu Jun 5 13:31:31 2008
: tick
Thu Jun 5 13:31:32 2008
: tick
Thu Jun 5 13:31:33 2008
: Received
-----
it (process 1) receives the message of process 0 *after* it has
finished it's calculation. I'm a bit clueless about where I could find
the error, because it looks right ;-)
Any help (hints for documentation, a more correct code, etc...) are
really appreciated,
Regards,
Michael Lesniak
I've a strange bug in one of my MPI programs and reduced it to this
snippet:
--- snip ---
#include <time.h>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
#undef SEEK_CUR
#undef SEEK_SET
#undef SEEK_END
#include <mpi.h>
using namespace MPI;
void io(int rank, char *s) {
FILE *f;
char buf[64];
time_t t;
sprintf(buf, "%02d.log", rank);
f = fopen(buf, "a");
t = time(0);
fprintf(f, "%s: %s\n\n\n", ctime(&t), s);
fclose(f);
}
int main(void) {
int value;
int rank;
Request r;
Init();
rank = COMM_WORLD.Get_rank();
if (rank == 0) {
io(rank, "Sending");
value = 42;
r = COMM_WORLD.Isend(&value, 1, INT, 1, 0);
io(rank, "Computing something");
unsigned int tick = 0;
while (++tick < 200000) {
printf("%g\r", sqrt(tick));
}
io(rank, "Finished.");
r.Wait();
} else {
io(rank, "Started");
io(rank, "Waiting for input");
// Waiting for input (blocking)
int tick = 0;
while (true) {
if (COMM_WORLD.Iprobe(ANY_SOURCE, ANY_TAG)) {
COMM_WORLD.Recv(&value, 1, INT, ANY_SOURCE, ANY_TAG);
break;
}
if (++tick % 1000000 == 0)
io(rank, "tick");
}
io(rank, "Received");
}
Finalize();
return EXIT_SUCCESS;
}
--- snap ---
If I understood non-blocking messages correct, process 1 should
receive the message *before* the computation in process 0 starts. But,
as my logs show
----------
(for process 0)
Thu Jun 5 13:31:30 2008
: Sending
Thu Jun 5 13:31:30 2008
: Computing something
Thu Jun 5 13:31:33 2008
: Finished.
---------
(for process 1)
Thu Jun 5 13:31:30 2008
: Started
Thu Jun 5 13:31:30 2008
: Waiting for input
Thu Jun 5 13:31:31 2008
: tick
Thu Jun 5 13:31:31 2008
: tick
Thu Jun 5 13:31:32 2008
: tick
Thu Jun 5 13:31:33 2008
: Received
-----
it (process 1) receives the message of process 0 *after* it has
finished it's calculation. I'm a bit clueless about where I could find
the error, because it looks right ;-)
Any help (hints for documentation, a more correct code, etc...) are
really appreciated,
Regards,
Michael Lesniak