Boost logo

Boost Users :

Subject: Re: [Boost-users] MPI::get_content with string member
From: Matthias Troyer (troyer_at_[hidden])
Date: 2010-07-14 00:44:12


On 12 Jul 2010, at 13:25, alev mutlu wrote:

> Hi all,
>
> I am trying to separate structure from content and send a vector of strings.
> Without the separation it works fine, I do receive the data on workers.
> When I try to separate structure and data it fails to compile. My simple code and the error message are below.
>
> Any idea, what am I doing wrong?
>
> Compilation
> mpicxx test.cpp -o test -I /boost/include/boost-1_37/ /boost/lib/libboost_mpi-gcc41-mt-1_37.a /boost/lib/libboost_serialization-gcc41-mt-1_37.a /boost/lib/libboost_date_time-gcc41-mt-1_37.a
>
> Code
>
> 1 #include "mpi_ver_headers.h"
> 2
> 3 using namespace std;
> 4 namespace mpi = boost::mpi;
> 5 mpi::communicator world;
> 6
> 7
> 8 int main(int argc, char* argv[]){
> 9 vector<std::string> a;
> 10 int sz;
> 11 mpi::environment env(argc, argv);
> 12 if (world.rank() == 0){
> 13 broadcast(world, mpi::skeleton(a), 0);
> 14 mpi::content c = mpi::get_content(a);
> 15 for(int i =1; i < world.size(); i++){
> 16 for(int l = 1; l < 3; l++)
> 17 a.push_back("A");
> 18 sz = a.size();
> 19 world.send(i, 3, sz);
> 20 world.send(i, 1, &a[0], sz);
> 21 world.recv(i, 2);
> 22 }
> 23 }
> 24 if(world.rank() > 0){
> 25 broadcast(world, mpi::skeleton(a), 0);
> 26 mpi::content c = mpi::get_content(a);
> 27 world.recv(0, 3 , sz);
> 28 a.resize(sz);
> 29 world.recv(0, 1, &a[0], sz);
> 30 for(int l=0; l < sz; l++)
> 31 cout << a[l] << "\t";
> 32 cout << endl;
> 33 world.send(0, 2);
> 34 }
> 35 }

Hi,

the origin of this problem is the fact that Boost.Serialization treats std::string as a primitive type, but one cannot create an MPI datatype for it. This should not be a problem though since in your example you actually cannot separate structure from content. Look at this code fragment:

> 13 broadcast(world, mpi::skeleton(a), 0);
> 14 mpi::content c = mpi::get_content(a);
> 15 for(int i =1; i < world.size(); i++){
> 16 for(int l = 1; l < 3; l++)
> 17 a.push_back("A");

You change the size of the string and thus the structure after broadcasting the structure. This would crash at runtime. Are your strings of variable length or fixed length? If they are of fixed length but varying content you could try to use std::vector<char> instead of std::string.

We could implement a workaround in Boost.MPI if you really have fixed size srings and want to separate structure from contents for them.

Matthias


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net