At 15:20 04/05/2012, you wrote:
Ups, I edited the code to make it easier to understand but I forgot to change two p2, sorry ^^' .
I hope this one is completely right:

1: for(int p1=0; p1<np; ++p1) {
2: for(int p2=0; p2<np; ++p2) {
3: if(me==p1) {
4: if(sendSize(p2)) MPI_Ssend(sendBuffer[p2],sendSize(p2),MPI_FLOAT,p2,0,myw); //processor p1 sends data to processor p2 5: if(recvSize(p2)) MPI_Recv(recvBuffer[p2],recvSize(p2),MPI_FLOAT,p2,0,myw,&status); //processor p1 receives data to processor p2
6: } else if(me==p2) {
7: if(recvSize(p1)) MPI_Recv(recvBuffer[p1],recvSize(p1),MPI_FLOAT,p1,0,myw,&status); //processor p2 receives data to processor p1 8: if(sendSize(p1)) MPI_Ssend(sendBuffer[p1],sendSize(p1),MPI_FLOAT,p1,0,myw); //processor p2 sends data to processor p1
9: }
10: MPI_Barrier(myw);
11: }
12: }


Now p1 will send messages to p2 and receive messages from p2

Now p2 will send messages to p1 and receive messages from p1

The logic of send/recv looks ok. Now, in 5 and 7, recvSize(p2) and recvSize(p1) function what value returns? The size of the buffer received from the MPI_Recv done in previous for loop?

This is the real code:

for(int p1=0; p1<mpiS; ++p1) {
for(int p2=0; p2<mpiS; ++p2) {
if(mpiR==p1) {
sento=p2;
if(s.getMem(sento)){
if(ite>25) cout<<"p1("<<p1<<") enviar "<<sento<<" "<<s.getMem(sento)<<" FLOATS "<<endl;
ok=MPI_Ssend(s.extractBuffer(sento),s.getMem(sento),MPI_FLOAT,sento,0,myw);

Don't know what are you doing here, second parameter, s.getMem(sento) should be the size of the buffer.

MPI_Ssend is defined for c++ :

void Comm::Ssend(const void* buf, int count, const Datatype& datatype, int dest, int tag) const

and you are using the C call. Are you mixing c and c++ code? Be careful with that.

The rest of your code has the same problems, check them. Perhaps you need a tutorial, check http://www.mpitutorial.com/beginner-mpi-tutorial/ , it's for mpich but is mpi-flavourless, so it works with openmpi too.


Thanks Eduardo

HTH and happy coding

Reply via email to