|
Boost Users : |
Subject: Re: [Boost-users] [mpi] - how to split communicator correctly?
From: Matthias Troyer (troyer_at_[hidden])
Date: 2009-11-13 04:03:30
On Nov 12, 2009, at 2:12 PM, Jeremiah Willcock wrote:
> On Thu, 12 Nov 2009, tomasz jankowski wrote:
>
>> ello group,
>>
>> i think I know how to split communicators & how it works in pure c mpi.
>> but I have problems with boost::mpi.
>>
>> assume that we want divide world communicator into 3 groups.
>> please look here:
>>
>> mpi::environment env(argc, argv);
>> mpi::communicator world;
>> mpi::communicator elloa;
>> mpi::communicator elloc;
>> mpi::communicator ellob;
>>
>> if(world.rank() == 0){ elloa = world.split(0); }
>> if(world.rank() == 1){ elloa = world.split(0); }
>> if(world.rank() == 2){ elloa = world.split(0); }
>> if(world.rank() == 3){ ellob = world.split(1); }
>> if(world.rank() == 4){ ellob = world.split(1); }
>> if(world.rank() == 5){ ellob = world.split(1); }
>> if(world.rank() == 6){ elloc = world.split(2); }
>> if(world.rank() == 7){ elloc = world.split(2); }
>>
>> if(world.rank() == 0){
>> std::cout<<"elloa " << elloa.size()<<std::endl;
>> std::cout<<"ellob " << ellob.size()<<std::endl;
>> std::cout<<"elloc " << elloc.size()<<std::endl;
>> }
>>
>> the code above gives me such results:
>>
>> elloa 3
>> ellob 8
>> elloc 8
>>
>> my question is why ellob and alloc communicators counts 8 members not 3
>> and 2 respetively?
>>
>> what I'm doing incorrect?
>
> Does similar code work in C? MPI_Comm_split must be called on all ranks in the input communicator, not just those that will be in some particular output communicator. See the top of http://www.mpi-forum.org/docs/mpi22-report/node134.htm for this restriction; the documentation for MPI_Comm_split is later on that page.
This is actually the correct expected behavior.
You do call split on every rank. However, as you can see only elloa gets assigned into on rank 0, and the correct size 3 is printed from rank 0. The others (ellab, elloc) still are in their default constructed state on rank 0, which means their size is 8.
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