Thread: how to broadCast string in mpi

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    11

    how to broadCast string in mpi

    Code:
    string  Image_name;	
    cout<<"enter image name"<<endl;
    		cin>>Image_name;
    
    MPI_Bcast(&image_name2, 100*sizeof(char), MPI_CHAR, MasterID, MPI_COMM_WORLD);
    it doesn't broadCast string properly , can any one correct my error
    Last edited by Salem; 06-01-2011 at 01:53 PM. Reason: Try using correct tags

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Is there supposed to be a relationship between Image_name and image_name2? Any reason for 100?

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    11
    image_name2="D:\\ImgDB\\" +Image_name;
    100*sizeof(char) -------> I think it is the message size

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Why do you think that 100*sizeof(char) is the message size? Wouldn't it depend on the length of image_name?

    Also if image_name2 is defined as a string, you are going to have to convert it to a char array in order to broadcast it.

  5. #5
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Code:
    MPI_Bcast(image_name2.c_str(), image_name2.size(), MPI_CHAR, MasterID, MPI_COMM_WORLD);
    or
    Code:
    MPI_Bcast(image_name2.c_str(), image_name2.size() + 1, MPI_CHAR, MasterID, MPI_COMM_WORLD);
    if the string is supposed to be null terminated.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. broadcast audio
    By taurus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 07-28-2010, 05:57 AM
  2. Broadcast on the right interface in C#
    By mdoland in forum C# Programming
    Replies: 1
    Last Post: 02-08-2008, 07:04 PM
  3. how to broadcast a music?
    By simonleo27 in forum C Programming
    Replies: 1
    Last Post: 01-14-2007, 02:34 AM
  4. Howto Broadcast?
    By Aidman in forum Windows Programming
    Replies: 6
    Last Post: 04-30-2003, 03:15 PM