43 const unsigned& first_row,
44 const unsigned& local_nrow,
45 const unsigned& global_nrow)
52 int my_rank =
Comm_pt->my_rank();
68 MPI_Allgather(&my_nrow_local,1,MPI_UNSIGNED,
73 unsigned my_first_row =
First_row[my_rank];
74 MPI_Allgather(&my_first_row,1,MPI_UNSIGNED,
90 for (
int p = 0; p < nproc; p++)
111 for (
int p = 0; p < nproc; p++)
115 for (
int pp = p+1; pp < nproc; pp++)
125 std::ostringstream error_message;
126 error_message <<
"The distributed rows on processor " << p
127 <<
" and processor " << pp <<
" overlap.\n" 128 <<
"Processor " << p <<
" : first_row = " 130 << Nrow_local[p] <<
".\n" 131 <<
"Processor " << pp <<
" : first_row = " 133 << Nrow_local[pp] <<
".\n";
135 "LinearAlgebraDistribution::distribute(...)",
136 OOMPH_EXCEPTION_LOCATION);
145 for (
int p = 0; p < nproc; p++)
149 std::ostringstream error_message;
150 error_message <<
"Processor " << p <<
" contains rows " 153 <<
" but there are only " <<
Nrow 154 <<
" to be distributed." << std::endl;
156 "LinearAlgebraDistribution::distribute(...)",
157 OOMPH_EXCEPTION_LOCATION);
172 const unsigned& global_nrow,
173 const bool& distribute)
192 if (distribute ==
true)
203 for (
int p=0;p<nproc;p++)
205 First_row[p] = unsigned((
double(p)/
double(nproc))*
double(global_nrow));
209 for (
int p=0; p<nproc-1; p++)
265 bool LinearAlgebraDistribution::operator==
270 if (!((*
Comm_pt) == (*other_dist.communicator_pt())))
284 if (other_dist.nrow() ==
Nrow)
294 for (
int i = 0;
i < nproc && flag ==
true;
i++)
304 if (other_dist.nrow() ==
Nrow)
318 stream <<
"nrow()=" << dist.
nrow()
329 namespace LinearAlgebraDistributionHelpers
371 unsigned ndistributions=in_distribution_pt.size();
377 for (
unsigned dist_i = 0; dist_i < ndistributions; dist_i++)
379 if(in_distribution_pt[dist_i]==0)
381 std::ostringstream error_message;
383 <<
"The pointer in_distribution_pt[" << dist_i <<
"] is null.\n";
385 OOMPH_CURRENT_FUNCTION,
386 OOMPH_EXCEPTION_LOCATION);
393 for (
unsigned dist_i = 0; dist_i < ndistributions; dist_i++)
395 if(!in_distribution_pt[dist_i]->
built())
397 std::ostringstream error_message;
399 <<
"The in_distribution_pt[" << dist_i <<
"] is not built.\n";
401 OOMPH_CURRENT_FUNCTION,
402 OOMPH_EXCEPTION_LOCATION);
411 = *(in_distribution_pt[0]->communicator_pt());
413 for (
unsigned dist_i = 0; dist_i < ndistributions; dist_i++)
417 = *(in_distribution_pt[dist_i]->communicator_pt());
419 if(!(first_comm == another_comm))
421 std::ostringstream error_message;
422 error_message <<
"The communicator in position "<<dist_i<<
" is \n" 423 <<
"not the same as the first one.\n";
425 OOMPH_CURRENT_FUNCTION,
426 OOMPH_EXCEPTION_LOCATION);
436 bool first_distributed = in_distribution_pt[0]->distributed();
437 for (
unsigned dist_i = 0; dist_i < ndistributions; dist_i++)
440 bool another_distributed = in_distribution_pt[dist_i]->distributed();
441 if(first_distributed != another_distributed)
443 std::ostringstream error_message;
445 <<
"The distribution in position "<<dist_i<<
" has a different\n" 446 <<
"different distributed boolean than the distribution.\n";
448 OOMPH_CURRENT_FUNCTION,
449 OOMPH_EXCEPTION_LOCATION);
456 if(out_distribution.
built())
458 std::ostringstream error_message;
460 <<
"The out distribution is built.\n" 461 <<
"Please clear it.\n";
463 OOMPH_CURRENT_FUNCTION,
464 OOMPH_EXCEPTION_LOCATION);
471 = in_distribution_pt[0]->communicator_pt();
474 unsigned nproc = comm_pt->nproc();
477 unsigned out_nrow_local = 0;
478 unsigned out_nrow = 0;
479 for (
unsigned in_dist_i = 0; in_dist_i < ndistributions; in_dist_i++)
481 out_nrow_local += in_distribution_pt[in_dist_i]->nrow_local();
482 out_nrow += in_distribution_pt[in_dist_i]->nrow();
487 unsigned out_first_row = 0;
492 bool distributed = in_distribution_pt[0]->distributed();
497 unsigned my_rank = comm_pt->my_rank();
499 unsigned *out_nrow_local_all =
new unsigned[nproc];
500 MPI_Allgather(&out_nrow_local,1,MPI_UNSIGNED,
501 out_nrow_local_all,1,MPI_UNSIGNED,
502 comm_pt->mpi_comm());
503 for (
unsigned proc_i = 0; proc_i < my_rank; proc_i++)
505 out_first_row += out_nrow_local_all[proc_i];
507 delete [] out_nrow_local_all;
517 if(nproc == 1 || !distributed)
522 out_distribution.
build(comm_pt,out_nrow,
false);
526 out_distribution.
build(comm_pt,out_first_row,out_nrow_local,out_nrow);
friend std::ostream & operator<<(std::ostream &stream, LinearAlgebraDistribution &dist)
<< operator
Vector< unsigned > First_row
the first row on this processor
void concatenate(const Vector< LinearAlgebraDistribution *> &in_distribution_pt, LinearAlgebraDistribution &out_distribution)
Takes a vector of LinearAlgebraDistribution objects and concatenates them such that the nrow_local of...
OomphCommunicator * communicator_pt() const
const access to the communicator pointer
void build(const OomphCommunicator *const comm_pt, const unsigned &first_row, const unsigned &nrow_local, const unsigned &nrow=0)
Sets the distribution. Takes first_row, nrow_local and nrow as arguments. If nrow is not provided or ...
OomphCommunicator * Comm_pt
the pointer to the MPI communicator object in this distribution
Vector< unsigned > Nrow_local
the number of local rows on the processor
unsigned nrow() const
access function to the number of global rows.
unsigned first_row() const
access function for the first row on this processor. If not distributed then this is just zero...
bool distributed() const
access function to the distributed - indicates whether the distribution is serial or distributed ...
Vector< unsigned > first_row_vector() const
return the first_row Vector
unsigned Nrow
the number of global rows
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
Vector< unsigned > nrow_local_vector() const
return the nrow_local Vector
unsigned nrow_local() const
access function for the num of local rows on this processor. If no MPI then Nrow is returned...
An oomph-lib wrapper to the MPI_Comm communicator object. Just contains an MPI_Comm object (which is ...