Thread: :( Sorry, Another MPI Problem

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    13

    :( Sorry, Another MPI Problem

    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
    Last edited by maverick_starst; 07-18-2009 at 10:16 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well most (if not all) of the MPI functions return a status result.
    How about some RTM and adding some error checking.

    Perhaps it will tell you why it isn't working, rather than you just "*shrug* it doesn't work"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM