[mpich-discuss] send and recieve not working over ethernet
D Griffiths
pha08dg at sheffield.ac.uk
Sat Dec 1 08:34:50 CST 2012
I am completely new to MPI so I hope I’m not asking anything too silly. I
have two computers, one running Ubuntu and the other running Scientific
Linux. They recognise each other as hosts, I can ssh from each without a
password and have disabled any firewalls.
Although I can run a simple Hello World application, the trouble starts
when I try to use MPI_SEND and MPI_RECV. I am trying a simple program to
send an int variable from one node to the other (see source code below).
If I run the code with two processes on the same computer I get the correct
output:
dan at siriusa:~/mpich2/tutorial2$ mpiexec -n 2 ./result2
Process 0 sending number 4
Process 1 received number 4 from process 0
However, if I try to run the code using both computers, I get:
dan at siriusa:~/mpich2/tutorial2$ mpiexec -n 2 -f hosts ./result2
Process 0 sending number 4
Process 1 received number -1078477356 from process 0
My host file:
dan at siriusa:~/mpich2/tutorial2$ cat hosts
192.168.88.1
192.168.88.2
So there is some sort of problem with using the send/recieve functions over
the network. As I said I am a beginner at this, so any help will be greatly
appreciated. Thanks in advance.
Code:
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Find out rank, size
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get the name of the processor
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
// We are assuming at least 2 processes for this task
if (world_size < 2) {
fprintf(stderr, "World size must be greater than 1 for %s\n",
argv[0]);
MPI_Abort(MPI_COMM_WORLD, 1);
}
int number;
if (world_rank == 0) {
// If we are rank 0, set the number to -1 and send it to process 1
number = 4;
printf("Process 0 sending number %d\n",number);
MPI_Send(&number, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
} else if (world_rank == 1) {
MPI_Recv(&number, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
MPI_STATUS_IGNORE);
printf("Process 1 received number %d from process 0\n", number);
}
MPI_Finalize();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mpich.org/pipermail/discuss/attachments/20121201/48756b15/attachment.html>
More information about the discuss
mailing list