Hi, I can't seem to find a help forum dedicated to MPI, this was the closest I could find. Anyways, I am having problem with the following code:
Code:
#include <iostream>
#include <math.h>
#include <bitset>
#include <fstream>
#include <mpi.h>
using namespace std;
MPI_Request req;
MPI_Status stat;
MPI_Datatype type[2]={MPI_INT,MPI_DOUBLE};
MPI_Datatype MSG;
int blocklen[2]={1,1};
MPI_Aint disp[2]={0,sizeof(int)};
struct message{
int position;
double data; // *** HERE ***
};
message snd,rcv;
int main(int argc,char *argv[]){
MPI_Init(&argc,&argv);
MPI_Type_struct(2,blocklen,disp,type,&MSG);
MPI_Type_commit(&MSG);
double tt=0.0;
int myRank,nProcs;
MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
if(myRank==0){
tt=3.0;
snd.data=tt;
snd.position=1111;
rcv.position=snd.position;
for(int i=1;i<nProcs;i++){
MPI_Isend(&snd,1,MSG,i,0,MPI_COMM_WORLD,&req);
MPI_Wait(&req,&stat);
}
}
else{
MPI_Recv(&rcv,1,MSG,0,0,MPI_COMM_WORLD,&stat);
tt=rcv.data;
}
cout << "Server " << myRank << " has " << tt << " and " << rcv.position << endl;
}
Basically all the code does is have the root process send the double 3.0 to the other process. When I run this code all servers but server 0 receive the message as 0 not 3. However, if I just change the line marks //*** HERE ** in struct to "float data" and use data as a float instead it works. Does anybody have any idea why this might be happening? I've tried fiddling with the MPI_Aint disp[2]={0,sizeof(int)}; line but that doesn't seem to do anything. Any help would be greatly appreciated.
P.S. please don't suggest I use bcast or some such , I need the code to have a coupled Isend and Rcv