Thread: Communication using MPI

  1. #1
    PhysicistTurnedProgrammer Cell's Avatar
    Join Date
    Jan 2009
    Location
    New Jersey
    Posts
    72

    Communication using MPI

    Hey guys,

    I am trying to send a string from one processor to another using MPI.

    In one file, I have the send function specified by:

    Code:
    MPI_Send(str, 128, MPI_CHAR, 1, my_rank, MPI_COMM_WORLD);
    where my_rank is 0.

    And in another file, I have the receive function:

    Code:
    MPI_Recv(str, 128, MPI_CHAR, 0, my_rank, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    where my_rank is 1.

    The files compile. But when I try to run the program I get the following error:

    Code:
    An error occurred in MPI_Send
    on communicator MPI_COMM_WORLD
    MPI_ERR_TAG: invalid tag
    MPI_ERRORS_ARE_FATAL (goodbye)
    From the MPI documentation:

    MPI_ERR_TAG
    Invalid tag argument. Tags must be non-negative; tags in a receive (MPI_Recv, MPI_Irecv, MPI_Sendrecv, etc.) may also be MPI_ANY_TAG. The largest tag value is available through the the attribute MPI_TAG_UB.
    I've also tried using MPI_ANY_TAG and I've received the same error.

    I should also mention that the way I run the program is by using:

    Code:
    mpirun -np 1 send : -np 1 receive
    Does anyone have any ideas?
    Last edited by Cell; 02-25-2009 at 10:23 AM. Reason: Added more info.

  2. #2

  3. #3
    PhysicistTurnedProgrammer Cell's Avatar
    Join Date
    Jan 2009
    Location
    New Jersey
    Posts
    72
    Hmm, I don't see where I got the parameters wrong:

    From the link:

    Code:
    MPI_Send(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
    From my code:

    Code:
    MPI_Send(str, 128, MPI_CHAR, 1, my_rank, MPI_COMM_WORLD);
    And for receive:

    Code:
    MPI_Recv(void* buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status)
    From my code:

    Code:
    MPI_Recv(str, 128, MPI_CHAR, 0, my_rank, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    BTW, I'm using my_rank as the tag value.

    I tried using the parameters MPI_ANY_TAG and MPI_ANY_SOURCE and I believe I got the same error. However, I will try it again right now.

    Edit - Yup, I tried using MPI_ANY_TAG and MPI_ANY_SOURCE and I still got the same exact error.
    Last edited by Cell; 02-25-2009 at 06:32 PM. Reason: Just tested.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    The tag has to be the same on all ends. 'my_rank' is different on all ends.

    MPI_ANY_TAG and MPI_ANY_SOURCE are only for MPI_Recv(), if you use them.

    gg

  5. #5
    PhysicistTurnedProgrammer Cell's Avatar
    Join Date
    Jan 2009
    Location
    New Jersey
    Posts
    72
    Alright, so I fixed that issue and I am still getting the same error.

    I now have:

    Code:
    MPI_Send(str, 128, MPI_CHAR, 1, 99, MPI_COMM_WORLD);
    Code:
    MPI_Recv(str, 128, MPI_CHAR, 0, 99, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    I am starting to think the tag is not the issue. I am getting another line after the error I posted above that I forgot to post*. It says:

    mpirun noticed that job rank 1 with PID 1095 on node cc1 exited on signal 15 (Terminated).
    I did some research to find out what this error signifier ("signal 15") means and I came across this thread on the Open MPI archives:

    http://www.open-mpi.org/community/li...09/01/7704.php

    One interesting post stated:
    Signal 15 (i.e., SIGTERM) can also mean that a job scheduler killed
    you (e.g., if your job ran out of time).
    Do you think this could be the issue? I'm not sure why my job would run out of time since I am only sending a relatively small string.

    I'm going to do some more testing and research and I'll check back tomorrow to see if you have any ideas.

    Thanks!

    * Edit - I should mention that I was getting this error line right from the beginning. It is not new.
    Last edited by Cell; 02-25-2009 at 11:52 PM. Reason: More info.

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Well, I would compile a provided sample (like "hello world") and make sure your MPI installation runs it as it should.

    What MPI library are you using?

    gg

  7. #7
    PhysicistTurnedProgrammer Cell's Avatar
    Join Date
    Jan 2009
    Location
    New Jersey
    Posts
    72
    Hey Codeplug, thanks for sticking with this thread.

    The MPI library I am using is Open MPI. The MPI installation is running as it should because I can run other MPI applications (that I did not write) on the machine.

  8. #8
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Write a minimal "hello world" type of MPI app that replicates the issue. Post the source here, as well as how you built and ran it.

    gg

  9. #9
    PhysicistTurnedProgrammer Cell's Avatar
    Join Date
    Jan 2009
    Location
    New Jersey
    Posts
    72
    Hey Codeplug,

    After messing around a little bit more, I got it it working. Turns out I was making a really stupid error when I was compiling, and because I was so focused on the stupid error that I thought was in the code, I never thought to check my building script.

    Thanks for all of your help!

  10. #10
    Registered User
    Join Date
    Aug 2009
    Posts
    2

    Lightbulb problem in sending vector <string> using MPI

    Hello can somebody help me to sending it................
    Code:
    #include <iostream>
    #include <vector>
    #include <string>
    #include"mpi.h"
    using namespace std;
    
    main(int argc, char *argv[])
    {
    
            MPI::Status status;
            MPI::Init(argc,argv);
            int myrank = MPI::COMM_WORLD.Get_rank();
            int numprocs = MPI::COMM_WORLD.Get_size();
            MPI_Datatype strtype;
            //int blocklen=16;
            //MPI_Aint disp[3]={0,16,32};
            MPI_Type_contiguous(16,MPI::CHAR,&strtype);
            MPI_Type_commit(&strtype);
       vector<string> SS;
     if(myrank == 0){
       SS.push_back("The number is 10");
       SS.push_back("The number is 20");
       SS.push_back("The number is 30");
    
       cout << "At root Node: " << endl;
    
       int ii;
       for(ii=0; ii < SS.size(); ii++)
       {
          cout << SS[ii] << endl;
       }
            //MPI_Type_contiguous(16,MPI::CHAR,strtype);
            MPI::COMM_WORLD.Send(&SS[0],3,strtype, 1, 1);
     }
    else{
            SS.reserve(3);
            MPI::COMM_WORLD.Recv(&SS[0],3,strtype,0,1);
       int ii;
             cout << "At worker Node: " << endl;
       for(ii=0; ii < SS.size(); ii++)
       {
          cout << SS[ii] << endl;
       }
     }
            MPI::Finalize();
    }
    Now My O/P is:
    $ mpicxx vecDemo.cpp -o vDemo.out -DMPICH_IGNORE_CXX_SEEK
    $ mpirun -np 2 ./vDemo.out
    At root Node:
    The number is 10
    The number is 20
    The number is 30
    At worker Node:
    $

    BUT i want O/P like.......
    $ mpirun -np 2 ./vDemo.out
    At root Node:
    The number is 10
    The number is 20
    The number is 30
    At worker Node:
    The number is 10
    The number is 20
    The number is 30
    $

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unkown Hang
    By Bladactania in forum C Programming
    Replies: 31
    Last Post: 04-22-2009, 09:33 AM
  2. Sorting whit MPI
    By isato in forum C Programming
    Replies: 0
    Last Post: 03-03-2009, 10:38 AM
  3. Malloc and MPI
    By moddinati in forum C Programming
    Replies: 17
    Last Post: 03-07-2008, 07:55 PM
  4. Looking for communication lib
    By BrownB in forum C Programming
    Replies: 3
    Last Post: 04-27-2005, 10:01 AM
  5. Serial communication packets
    By Roaring_Tiger in forum C Programming
    Replies: 3
    Last Post: 04-26-2003, 08:33 AM