<font>
</font><style type="text/css">
<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm; direction: ltr; color: #000000; line-height: 100%; widows: 2; orphans: 2 }
P.western { font-size: 12pt; so-language: en-GB }
P.cjk { font-size: 12pt }
P.ctl { font-size: 12pt }
-->
</style><p class="western" style="margin-bottom:0cm" lang="en-GB"><font>I am
completely new to MPI so I hope I’m not asking anything too silly.
I have two com<font>puters</font>, 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.</font></p><font>
</font><p class="western" style="margin-bottom:0cm" lang="en-GB"><font>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).</font>
</p><font></font><p class="western" style="margin-bottom:0cm" lang="en-GB"><font>If I run
the code with two processes on the same computer I get the correct
output:</font>
</p><font></font><p class="western" style="margin-bottom:0cm" lang="en-GB"><font>dan@siriusa:~/mpich2/tutorial2$
mpiexec -n 2 ./result2
</font>
</p><font>Process 0
sending number 4</font><font><br>Process 1
received number 4 from process 0
</font><font>
</font><p class="western" style="margin-bottom:0cm" lang="en-GB"><font>However,
if I try to run the code using both computers, I get:</font>
</p><font></font><p class="western" style="margin-bottom:0cm" lang="en-GB"><font>dan@siriusa:~/mpich2/tutorial2$
mpiexec -n 2 -f hosts ./result2
</font>
</p><font>Process 0
sending number 4</font><font><br>Process 1
received number -1078477356 from process 0
</font><font>
</font><p class="western" style="margin-bottom:0cm" lang="en-GB"><font>My host
file:</font>
</p><font></font><p class="western" style="margin-bottom:0cm" lang="en-GB"><font>dan@siriusa:~/mpich2/tutorial2$
cat hosts
</font>
</p><font>192.168.88.1</font><font><br>192.168.88.2</font><font><br><br>So there is some sort of problem<font> with using the send/recieve functions o<font>ver the network. </font></font>As I said
I am a beginner at this, so any help will be greatly appreciated. Thanks in advance.</font>
<p class="western" style="margin-bottom:0cm" lang="en-GB"><font>Code:</font>
</p><font></font><p class="western" style="margin-bottom:0cm" lang="en-GB"><font>#include
<mpi.h>
</font>
</p><font>#include
<stdio.h></font><font><br>#include
<stdlib.h>
</font><font>
</font><p class="western" style="margin-bottom:0cm" lang="en-GB">
</p><font>
</font><p class="western" style="margin-bottom:0cm" lang="en-GB"><font>int
main(int argc, char** argv) {
</font></p><font></font><font> //
Initialize the MPI environment</font><font><br> MPI_Init(NULL, NULL);</font><font><br> // Find
out rank, size</font><font><br> int
world_rank;</font><font><br> MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);</font><font><br> int
world_size;</font><font><br> MPI_Comm_size(MPI_COMM_WORLD, &world_size);</font><font><br> // Get
the name of the processor</font><font><br><font> </font>char
processor_name[MPI_MAX_PROCESSOR_NAME];</font><font><font> <br><font> </font></font>int
name_len;</font><font><br><font> </font>MPI_Get_processor_name(processor_name, &name_len);</font><font><br><br><font> </font>// We
are assuming at least 2 processes for this task</font><font><br><font> </font>if
(world_size < 2) {</font><font><br><font> </font>fprintf(stderr, "World size must be greater than 1 for %s\n",
argv[0]);</font><font><br><font> </font>MPI_Abort(MPI_COMM_WORLD, 1);</font><font><br><font> </font>}
</font><font>
</font><p class="western" style="margin-bottom:0cm" lang="en-GB">
</p><font></font><font><font> </font>int
number;</font><font><br><font> </font>if
(world_rank == 0) {</font><font><br><font> </font>// If
we are rank 0, set the number to -1 and send it to process 1</font><font><br><font> </font>number
= 4;</font><font><br><font> </font>printf("Process 0 sending number %d\n",number);</font><font><br><font> </font>MPI_Send(&number, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);</font><font><br><font> <br>
</font> } else
if (world_rank == 1) {</font><font><br><font> </font>MPI_Recv(&number, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
MPI_STATUS_IGNORE);</font><font><br><font> </font>printf("Process 1 received number %d from process 0\n",
number);</font><font><br><font> </font>}</font><font><br><font> <br></font> MPI_Finalize();</font><font><br>}</font><font>
</font>