36 const unsigned& first_row,
37 const unsigned& local_nrow,
38 const unsigned& global_nrow)
45 int my_rank =
Comm_pt->my_rank();
61 MPI_Allgather(&my_nrow_local,
70 unsigned my_first_row =
First_row[my_rank];
71 MPI_Allgather(&my_first_row,
91 for (
int p = 0; p < nproc; p++)
118 for (
int p = 0; p < nproc; p++)
122 for (
int pp = p + 1; pp < nproc; pp++)
132 std::ostringstream error_message;
134 <<
"The distributed rows on processor " << p
135 <<
" and processor " << pp <<
" overlap.\n"
136 <<
"Processor " << p <<
" : first_row = " <<
First_row[p]
138 <<
"Processor " << pp <<
" : first_row = " <<
First_row[pp]
142 "LinearAlgebraDistribution::distribute(...)",
143 OOMPH_EXCEPTION_LOCATION);
152 for (
int p = 0; p < nproc; p++)
156 std::ostringstream error_message;
157 error_message <<
"Processor " << p <<
" contains rows " <<
First_row[p]
159 <<
" but there are only " <<
Nrow <<
" to be distributed."
162 "LinearAlgebraDistribution::distribute(...)",
163 OOMPH_EXCEPTION_LOCATION);
177 const unsigned& global_nrow,
178 const bool& distribute)
197 if (distribute ==
true)
207 for (
int p = 0; p < nproc; p++)
210 unsigned((
double(p) /
double(nproc)) *
double(global_nrow));
214 for (
int p = 0; p < nproc - 1; p++)
297 for (
int i = 0;
i < nproc && flag ==
true;
i++)
321 stream <<
"nrow()=" << dist.
nrow() <<
", first_row()=" << dist.
first_row()
323 <<
", distributed()=" << dist.
distributed() << std::endl;
330 namespace LinearAlgebraDistributionHelpers
372 unsigned ndistributions = in_distribution_pt.size();
378 for (
unsigned dist_i = 0; dist_i < ndistributions; dist_i++)
380 if (in_distribution_pt[dist_i] == 0)
382 std::ostringstream error_message;
383 error_message <<
"The pointer in_distribution_pt[" << dist_i
386 OOMPH_CURRENT_FUNCTION,
387 OOMPH_EXCEPTION_LOCATION);
394 for (
unsigned dist_i = 0; dist_i < ndistributions; dist_i++)
396 if (!in_distribution_pt[dist_i]->built())
398 std::ostringstream error_message;
399 error_message <<
"The in_distribution_pt[" << dist_i
400 <<
"] is not built.\n";
402 OOMPH_CURRENT_FUNCTION,
403 OOMPH_EXCEPTION_LOCATION);
412 *(in_distribution_pt[0]->communicator_pt());
414 for (
unsigned dist_i = 0; dist_i < ndistributions; dist_i++)
418 *(in_distribution_pt[dist_i]->communicator_pt());
420 if (!(first_comm == another_comm))
422 std::ostringstream error_message;
423 error_message <<
"The communicator in position " << dist_i <<
" is \n"
424 <<
"not the same as the first one.\n";
426 OOMPH_CURRENT_FUNCTION,
427 OOMPH_EXCEPTION_LOCATION);
437 bool first_distributed = in_distribution_pt[0]->distributed();
438 for (
unsigned dist_i = 0; dist_i < ndistributions; dist_i++)
441 bool another_distributed = in_distribution_pt[dist_i]->distributed();
442 if (first_distributed != another_distributed)
444 std::ostringstream error_message;
446 <<
"The distribution in position " << dist_i <<
" has a different\n"
447 <<
"different distributed boolean than the distribution.\n";
449 OOMPH_CURRENT_FUNCTION,
450 OOMPH_EXCEPTION_LOCATION);
457 if (out_distribution.
built())
459 std::ostringstream error_message;
460 error_message <<
"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();
488 unsigned out_first_row = 0;
493 bool distributed = in_distribution_pt[0]->distributed();
498 unsigned my_rank = comm_pt->my_rank();
500 unsigned* out_nrow_local_all =
new unsigned[nproc];
501 MPI_Allgather(&out_nrow_local,
507 comm_pt->mpi_comm());
508 for (
unsigned proc_i = 0; proc_i < my_rank; proc_i++)
510 out_first_row += out_nrow_local_all[proc_i];
512 delete[] out_nrow_local_all;
522 if (nproc == 1 || !distributed)
527 out_distribution.
build(comm_pt, out_nrow,
false);
531 out_distribution.
build(
532 comm_pt, out_first_row, out_nrow_local, out_nrow);
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
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 first_row() const
access function for the first row on this processor. If not distributed then this is just zero.
bool operator==(const LinearAlgebraDistribution &other_dist) const
== Operator
OomphCommunicator * communicator_pt() const
const access to the communicator pointer
Vector< unsigned > Nrow_local
the number of local rows on the processor
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
unsigned Nrow
the number of global rows
Vector< unsigned > First_row
the first row on this processor
Vector< unsigned > nrow_local_vector() const
return the nrow_local Vector
bool built() const
if the communicator_pt is null then the distribution is not setup then false is returned,...
bool Distributed
flag to indicate whether this distribution describes an object that is distributed over the processor...
unsigned nrow() const
access function to the number of global rows.
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 ...
An OomphLibError object which should be thrown when an run-time error is encountered....
An OomphLibWarning object which should be created as a temporary object to issue a warning....
A slight extension to the standard template vector class so that we can include "graceful" array rang...
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...
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
std::ostream & operator<<(std::ostream &out, const DoubleVector &v)
output operator