Commit e7ea8034 authored by COULAUD Olivier's avatar COULAUD Olivier
Browse files

Compute particle distribution prepare the comms

parent 19276784
......@@ -309,22 +309,15 @@ namespace scalfmm::tree
std::vector<int> tosendL(nb_proc, 0), tosendR(nb_proc, 0);
std::vector<int> toreceiv(nb_proc, 0);
manager.comm.barrier();
for(int i = 0; i < nb_proc - 1; ++i)
for(int i = 0; i < nb_proc; ++i)
{
tomove[i] = part_distrib[i][2] - block;
}
print("rank(" + std::to_string(rank) + ") tomove: ", tomove);
print("rank(" + std::to_string(rank) + ") initial tomove: ", tomove);
// if(rank == 0)
{
for(int i = 0; i < nb_proc - 1; ++i)
{
// std::cout << i << " \n";
// print(" (" + std::to_string(i) + ")
// tomove: ", tomove); print(" (" +
// std::to_string(i) + ") tosendR: ",
// tosendR); print(" (" +
// std::to_string(i) + ") tosendRL: ",
// tosendL);
if(tomove[i] < 0)
{
tosendL[i + 1] = -tomove[i];
......@@ -350,24 +343,91 @@ namespace scalfmm::tree
print("rank(" + std::to_string(rank) + ") tosendR: ", tosendR);
print("rank(" + std::to_string(rank) + ") tosendRL: ", tosendL);
///
std::cout << "rank(" + std::to_string(rank) + ") tosendL: " << tosendL[rank] << std::endl;
std::cout << "rank(" + std::to_string(rank) + ") tosendR: " << tosendR[rank] << std::endl;
std::cout << "tosendL(" + std::to_string(rank) + "): " << tosendL[rank] << std::endl;
std::cout << "tosendR(" + std::to_string(rank) + "): " << tosendR[rank] << std::endl;
if(rank > 0)
std::cout << "toReceivL(" + std::to_string(rank) + "): " << tosendR[rank - 1] << std::endl;
if(rank < nb_proc - 1)
std::cout << "toReceivR(" + std::to_string(rank) + "): " << tosendL[rank + 1] << std::endl;
int toReceivL, toReceivR;
toReceivL = tosendR[rank - 1] > 0 ? 1 : 0;
toReceivR = tosendL[rank + 1] > 0 ? 1 : 0;
/// proceed the communications
/// first send the number particles inside leaves to send
///
int nb_leaf_to_left{0}, nb_leaf_to_right{0}, nb_part_to_left{0}, nb_part_to_right{0};
if(tosendL[rank] > 0)
{
int pos = 0;
while(weight[pos][1] != tosendL[rank])
int leaf_idx = 0;
nb_part_to_left = weight[leaf_idx][1];
std::cout << " tosendL leaf_idx " << leaf_idx << " " << nb_part_to_left << std::endl;
while(nb_part_to_left <= tosendL[rank])
{
// std::cout << " new pos " << pos <<
// std::endl;
pos++;
leaf_idx++;
nb_part_to_left += weight[leaf_idx][1];
std::cout << " tosendL new pos " << leaf_idx << " " << nb_part_to_left << std::endl;
}
nb_leaf_to_left = leaf_idx + 1;
std::cout << rank << "send " << nb_leaf_to_left << " leaf to left - nb part " << nb_part_to_left
<< std::endl;
}
if(tosendR[rank] > 0)
{
//
int leaf_idx = 0;
nb_part_to_right = weight[leaf_idx][1];
std::cout << "tosendR leaf_idx " << leaf_idx << " " << nb_part_to_right << std::endl;
while(nb_part_to_right <= tosendL[rank])
{
leaf_idx++;
nb_part_to_right += weight[leaf_idx][1];
std::cout << " - tosendR new pos " << leaf_idx << " " << nb_part_to_right << std::endl;
}
nb_leaf_to_right = leaf_idx + 1;
std::cout << rank << " send " << nb_leaf_to_right << " leaf to right - nb part "
<< nb_part_to_right << std::endl;
}
/// Send the number
/// send to left and right
int nb_elt_from_left{0}, nb_elt_from_right{0};
/// receive from left right
{
// compute the buffer size
inria::mpi::request tab_mpi_status[2];
auto mpi_type = inria::mpi::get_datatype<int>();
// if i'm not the last proc
const int to_right = (rank + 1 == nb_proc) ? MPI_PROC_NULL : rank + 1;
const int to_left = (rank == 0) ? MPI_PROC_NULL : rank - 1;
if(tosendL[rank] > 0)
{
manager.comm.isend(&nb_part_to_left, 1, mpi_type, to_left, 1);
}
if(tosendR[rank] > 0)
manager.comm.isend(&nb_part_to_right, 1, mpi_type, to_right, 1);
int idx = 0;
if(toReceivL > 0)
{
tab_mpi_status[idx] = manager.comm.irecv(&nb_elt_from_left, 1, mpi_type, to_left, 1);
idx++;
}
if(toReceivR > 0)
tab_mpi_status[idx] = manager.comm.irecv(&nb_elt_from_right, 1, mpi_type, to_right, 1);
// Waiting for the result of the request, if my rank is 0
// I don't need to wait
if(toReceivL + toReceivR > 0)
{
inria::mpi::request::waitall(toReceivL + toReceivR, tab_mpi_status);
}
std::cout << rank << " nb Part left: " << nb_elt_from_left
<< " nb Part right: " << nb_elt_from_right << std::endl;
}
/// Second send the particles
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment