how to broadCast string in mpi

This is a discussion on how to broadCast string in mpi within the C++ Programming forums, part of the General Programming Boards category; 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 ...

  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 02:53 PM. Reason: Try using correct tags

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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,185
    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
    682
    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.
    I never put signature, but I decided to make an exception.

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, 06: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, 04:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21