mpi all reduce with std::vector and back_inserter

Hello, I have a std::vector<std::string> vector at each CPU. I would like to "reduce" all vectors on all CPUs. For example: CPU 0: vec = [a, b, c, d] CPU 1: vec = [e, f, g, h] std::vector<std::string> myreduce; mpi::all_reduce( mpi com object, vec, myreduce, #); myreduce = [a, b, c, d, e, f, g, h] How can I do this? Should I replace my # with a back_inserter of the std::vector? Thx for help Phil

Hi Kraus, If i understood well, it's not the case for `all_reduce`, you need `all_gather` instead: http://www.boost.org/doc/libs/1_46_1/doc/html/boost/mpi/all_gather.html <http://www.boost.org/doc/libs/1_46_1/doc/html/boost/mpi/all_gather.html>The vectors has the same size? Regards, Júlio. 2011/5/5 Kraus Philipp <philipp.kraus@flashpixx.de>
Hello,
I have a std::vector<std::string> vector at each CPU. I would like to "reduce" all vectors on all CPUs. For example:
CPU 0: vec = [a, b, c, d] CPU 1: vec = [e, f, g, h]
std::vector<std::string> myreduce; mpi::all_reduce( mpi com object, vec, myreduce, #);
myreduce = [a, b, c, d, e, f, g, h]
How can I do this? Should I replace my # with a back_inserter of the std::vector?
Thx for help
Phil _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Am 06.05.2011 um 00:24 schrieb Júlio Hoffimann:
Hi Kraus,
If i understood well, it's not the case for `all_reduce`, you need `all_gather` instead:
http://www.boost.org/doc/libs/1_46_1/doc/html/boost/mpi/ all_gather.html
The vectors has the same size?
No, they have different sizes. I use all_gather, but I must iterate over each element in the result vector and put the elements into a new vector. I do this at the time: std::vector< std::vector<std::string> > result; mpi::all_gather( mpi object, vec, result); std::vector<std::string> myvec; foreach( result as res ) myvec.push_back( foreach in res ); I need the loop after all_gather and my question is: Can I do the loop call into the mpi command, so that I don't have a loop after the gather? Thx Phil

Your first post referred to other implementation. Anyway, if you have two vectors of strings: CPU 0: vec = [ a b c d e ] CPU 1: vec = [ f g h i j ] then all_gather will produce a vector of strings: result = [ a b c d e f g h i j ] If you have a vector<vector<string> >, then all_gather will produce vector<vector<string> > it's not possible to change this behavior. You begin with a bidimensional vector, then you end with a bidimensional vector. I don't know if it's possible to concatenate the matrix lines with other Boost library, but the collective operations in Boost.MPI are like in the MPI 1.1 standard, nothing else. Regards, Júlio. 2011/5/5 Kraus Philipp <philipp.kraus@flashpixx.de>
Am 06.05.2011 um 00:24 schrieb Júlio Hoffimann:
Hi Kraus,
If i understood well, it's not the case for `all_reduce`, you need `all_gather` instead:
http://www.boost.org/doc/libs/1_46_1/doc/html/boost/mpi/all_gather.html
<http://www.boost.org/doc/libs/1_46_1/doc/html/boost/mpi/all_gather.html>The vectors has the same size?
No, they have different sizes. I use all_gather, but I must iterate over each element in the result vector and put the elements into a new vector. I do this at the time:
std::vector< std::vector<std::string> > result; mpi::all_gather( mpi object, vec, result);
std::vector<std::string> myvec; foreach( result as res ) myvec.push_back( foreach in res );
I need the loop after all_gather and my question is: Can I do the loop call into the mpi command, so that I don't have a loop after the gather?
Thx
Phil
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Júlio Hoffimann
-
Kraus Philipp