Hello,

I am new using MPI. I want to run a simple program (I enclose the program) in 2 
different computers. I have installed MPI in both computers. I have compiled 
the program using:

mpiCC -o PruebaSumaParalela.out PruebaSumaParalela.cpp

I have copied the executable PruebaSumaParalela.out  to my /home directoy in 
both computers. Then I run:

mpirun -np 2 --host 10.4.5.123,edu@10.4.5.126 --prefix /usr/local 
./PruebaSumaParalela.out 

The 10.4.5.123 computer prints:

Inicio
Inicio
totalnodes:2
mynode:0
Inicio Recv
totalnodes:2
mynode:1
Inicio Send
sum:375250

The edu@10.4.5.126 computer prints:

Inicio
Inicio
totalnodes:2
mynode:1
Inicio Send
sum:375250
totalnodes:2
mynode:0
Inicio Recv

But the program does not finish on any computer. It seems that the Send and 
Recv does not work. Master computer is waiting to receive something that the 
slave does not send.
Do you know what the problem could be ?

Thank you very much.

Sofia

No virus found in this outgoing message
Checked by PC Tools AntiVirus (4.0.0.26 - 10.100.007).
http://www.pctools.com/free-antivirus/
#include<iostream.h>
#include<mpi.h>
int main(int argc, char ** argv){
int mynode, totalnodes;
int sum,startval,endval,accum;
printf("Inicio\n");
MPI_Status status;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD, &totalnodes);
MPI_Comm_rank(MPI_COMM_WORLD, &mynode);
printf("totalnodes: %d\n",totalnodes);
printf("mynode: %d\n",mynode);
sum = 0;
startval = 1000*mynode/totalnodes+1;
endval = 1000*(mynode+1)/totalnodes;
for(int i=startval;i<=endval;i=i+1)
sum = sum + i;
if(mynode!=0){
printf("Inicio Send\n");
printf("sum: %d\n",sum);
MPI_Send(&sum,1,MPI_INT,0,1,MPI_COMM_WORLD);
printf("Send sum\n");
}
else
for(int j=1;j<totalnodes;j=j+1){
printf("Inicio Recv\n");
MPI_Recv(&accum,1,MPI_INT,j,1,MPI_COMM_WORLD, &status);
printf("RECV accum\n");
sum = sum + accum;
printf("Sum\n");
}
printf("Final\n");
if(mynode == 0)
cout << "The sum from 1 to 1000 is: " << sum << endl;
MPI_Finalize();
}

Reply via email to