Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MPI Bcast

  1. Jul 16, 2012 #1
    Hey gang,

    I'm trying to use MPIBcast to distribute a user entered value across all nodes, but it seems like only the root node is working (i.e. no broadcast).

    I'm using OpenMPI 1.5.4 with the following code:

    Code (Text):
      A=0;
      std::clock_t start;
      double duration;
      start = std::clock();
      MPI::Status status;
      MPI::Init(argc, argv);
      N=0;
      numnodes = MPI::COMM_WORLD.Get_size();
      mynode = MPI::COMM_WORLD.Get_rank();
     
      if(mynode==0){
        cout<<"Enter number of sections: "<<endl;
        cin>>N;
        MPI::COMM_WORLD.Bcast(&N, 1, MPI::INT, 0);
      }
      MPI::COMM_WORLD.Barrier();
     
      if(mynode!=0) {
       
        while(N==0) {
         
         //Loop until Bcast received
     
        }
       
      }
     
     if(mynode==0) {
      cout<<"root node: "<<N<<endl;
     } else {
       cout<<"other nodes: "<<N<<endl;
       
    }
    Unfortunately the other node never gets a non-zero value of N and just keeps looping :\ I have a feeling my Bcast syntax or usage is wrong but I don't know why/how. Any help would be great! (I know I could use the wait function instead of a loop but this was quicker :) )

    Cheers,
    -FD
     
  2. jcsd
  3. Jul 16, 2012 #2

    chiro

    User Avatar
    Science Advisor

    Hey FunkyDwarf.

    I noticed that your Bcast procedure is in the if statement and only gets executed if mynodes is 0. Is it meant to be outside the if block just below it?
     
  4. Jul 16, 2012 #3
    colective communication routines must be called by all nodes on your commutator. Also theese routines sync up all nodes so you dont need any kind of "Loop until Bcast received".
     
  5. Jul 16, 2012 #4
    What if I only want to input the value for N once? If it is outside the if statement the cin will be called by all nodes. Am i forced to do some send/receive stuff?

    (thanks for replys btw)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: MPI Bcast
  1. FFTW and MPI (Replies: 4)

  2. MPI in Fortran (Replies: 2)

  3. MPI Fortran on Mac OSX (Replies: 1)

Loading...